I have just started using Streamlit and it’s amazing that I wanted to deploy my model by creating the project in Github. I have followed the documentation on the requirements for creating a Streamlit web application. Now, that my TensorFlow Keras model (after training) is ready as my_model.pb file (unable to save the model as pickle file because its a weak reference object). I placed this model at the same level as the .py file used for running the app. Please note that I am able to run the application using my browser which means it is working perfectly fine on my local machine. But when I upload the code to Github, it is unable to load the model due to some path issues and I could not resolve it. It would be really helpful if you can look into this and let me know if there is something that I am missing or what needs to be done to deploy the app.
I am sharing the link to my public repo for your reference. Kindly have a look and let me know.
Hi @madhumilan, welcome to the Streamlit community!
Thank you for sharing your repo. As you’ve noted, you have placed your saved model saved_model.pb in the same directory as your Streamlit app. As such, you can pass an empty string in line 17.
Replace line 17 with:
loaded_model = tf.keras.models.load_model("")
TensorFlow should be able to find your saved_model.pb file. However, you may have uploaded incorrect files to your variables/ directory.
According to the documentation, when you create your SavedModel with model.save('my_model'), it should contain the model architecture and configuration in saved_model.pb, and weights saved in the variables/ directory. However, the variables/ directory in your repo contains saved_model.pb instead of the weights. So you will run into another error even after passing the right path in line 17. Just something to keep in mind.
Hi @snehankekre, thank you so much for your support. I get the point that I have to load the model as you suggested and also in a proper format. I have done that. I have got directory structure as shown below:
’assets’
'variables’
variables.data-00000-of-00001
variables.index
keras_metadata.pb
saved_model.pb
However, I see that variables directory has too much of data (nearly 145 MB) which makes it nearly difficult to save in my Github repo. Github allows only files of size 25 MB if I am not wrong. So, how can I use this model to deploy using Streamlit app. Kindly help me out.
However, I see that variables directory has too much of data (nearly 145 MB) which makes it nearly difficult to save in my Github repo. Github allows only files of size 25 MB if I am not wrong.
Hi @snehankekre, that was a good set of options. I had the idea of using Git LFS, thanks for confirming it. Now I have uploaded my weights file as well into my repo. But I see a new error as
Whoops — something went wrong! An error has been logged.
I do not understand why this error is occurring now. I believe the model is now as expected by the method load_model() to load it, and I have updated the path too. Please let me know if I am missing anything else.
hi @madhumilan. it did not work for me. i just did what you said and i saved the model and load it. it was working good in localhost but when i upload the files to github and try to load the model. it did not worked. i do not know what the problem is. can you help!
When you try loading the model, you will run into the following error:
TypeError: ('Keyword argument not understood:', 'keepdims')
To fix the error, update the TensorFlow version in your requirements file to tensorflow==2.6.0 The keepdims argument is supported for TensorFlow versions >=2.6.0.
Once you make the above changes, your app will deploy successfully and your Word Embeddings classifier will work
Thank you a lot for your help. I have another question about logistic regression model. I can not use save this model like other models although i used the same instruction. can you help me in this point.
With this topic, I tried to resolve it but it doesn’t works.
In Github, my file “checkpoint_vgg16_3.data-00000-of-00001” is too big so I’ve upload it on GoogleDrive.
(link to the fil on GoogleDrive : https://drive.google.com/file/d/1UdztjLziquc_IUvrANAJo-ukoNC_uMtt/view?usp=share_link
But I don’t understand how to modify my “load_vgg16_cnn_model”.
My streamlit app works when I run it in the local way.
Anyone have an idea how to fix that and succed to deploy my first app ?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.