Streamlit Deployment: tensorflow.python.framework.errors_impl.OpError

I am trying to deploy a streamlit app that uses a tensorflow model. The webapp is working properly on my local host but when I try to deploy it on Streamlit cloud I get the following errror: tensorflow.python.framework.errors_impl.OpError: not an sstable (bad magic number)

Please see github repo link: https://github.com/pinzhi000/resp_db

The files associated with my tensorflow model are in the “saved_model” folder in the above repo.

Below is the error I see on my app:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/scriptrunner/script_runner.py", line 443, in _run_script
    exec(code, module.__dict__)
  File "/app/resp_db/rsd_app.py", line 159, in <module>
    model = tensorflow.keras.models.load_model('./saved_model')
  File "/home/appuser/venv/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/appuser/venv/lib/python3.8/site-packages/tensorflow/python/training/py_checkpoint_reader.py", line 45, in error_translator
    raise errors_impl.OpError(None, None, error_message, errors_impl.UNKNOWN)
tensorflow.python.framework.errors_impl.OpError: not an sstable (bad magic number)

Here is a screen shot of my error:

I’m at a loss for what to do. Please help! Thx

Hi @pinhead000 :wave:

The error stems from line 159 of rsd_app.py:

model = tensorflow.keras.models.load_model(path+'/saved_model')

Replace the above with the correct path:

model = tensorflow.keras.models.load_model('/saved_model') 

Best, :balloon:
Snehan

Thank you for suggestion. I implemented it (see github repo) but did not work. I got the following error:

OSError: No file or directory found at /saved_model

Please advise …

Update: I figured it out! I saved the model as a .h5 file directly instead of using SavedModel; this allowed the cloud deployment to work!

Link 1:https://www.tensorflow.org/guide/keras/save_and_serialize#:~:text=The%20recommended%20format%20is%20SavedModel,‘h5’%20to%20save()%20.

Link 2: https://discuss.streamlit.io/t/oserror-savedmodel-file-does-not-exist-at/12985

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.