This is the error message i get-
Traceback:
File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/script_runner.py", line 354, in _run_script
exec(code, module.__dict__)
File "/app/app.py", line 131, in <module>
label, perc = classifier(image, model_file)
File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/legacy_caching/caching.py", line 574, in wrapped_func
return get_or_create_cached_value()
File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/legacy_caching/caching.py", line 558, in get_or_create_cached_value
return_value = func(*args, **kwargs)
File "/app/app.py", line 52, in classifier
model = tf.saved_model.load("my_model")
File "/app/.heroku/python/lib/python3.9/site-packages/tensorflow/python/saved_model/load.py", line 900, in load
result = load_internal(export_dir, tags, options)["root"]
File "/app/.heroku/python/lib/python3.9/site-packages/tensorflow/python/saved_model/load.py", line 913, in load_internal
loader_impl.parse_saved_model_with_debug_info(export_dir))
File "/app/.heroku/python/lib/python3.9/site-packages/tensorflow/python/saved_model/loader_impl.py", line 60, in parse_saved_model_with_debug_info
saved_model = _parse_saved_model(export_dir)
File "/app/.heroku/python/lib/python3.9/site-packages/tensorflow/python/saved_model/loader_impl.py", line 108, in parse_saved_model
raise IOError(f"Cannot parse file {path_to_pb}: {str(e)}.")
I am trying to run a saved model (pb format) on Heroku. I am calling for loading a saved model using the snippet below-
model = tf.keras.models.load_model("./my_model")
# Create the array of the right shape to feed into the keras model
data = np.ndarray(shape=(1, 200, 200, 3), dtype=np.float32)
image = img
# image sizing
size = (200, 200)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# turn the image into a numpy array
image_array = np.asarray(image)
# Normalize the image
normalized_image_array = image_array.astype(np.float32) / 255
# Load the image into the array
data[0] = normalized_image_array
# run the inference
predict_dataset = tf.convert_to_tensor(np.array(normalized_image_array))
# training=False is needed only if there are layers with different
# behavior during training versus inference (e.g. Dropout).
predictions = model(predict_dataset, training=False)
prediction_percentage = predictions.numpy()[0][0]
prediction = prediction_percentage.round()
Please note that the model is a tensorflow model saved in pb format and contains multiple files such as variables.data 00000 out of 00001 and saved_model.pb
Edit- I would like to point out that the model was saved on tensorflow version 2.7.0 using the save method
@staticmethod
def model_saver(model_obj):
try:
model_obj.save("./FreshPrice/Output/my_model")
except:
print("Model not saved successfully!")
I am trying to run the model on heroku where I am using tensorflow-cpu (2.7.0) to run the loaded model. I used tf-cpu since it has lower size than tf.
Please advise on the error! any help is appreciated