I trained a CNN model in a local machine, saved the model using model.save('./models/my_model')
and I am able to load the model (new_model = tensorflow.keras.models.load_model('./models/my_model'))
and classify an image that I pass through a browser by using the web framework Flask.
Now, I want to run my code hosted in pythonanywhere.com. However, when loading the model I got this error:
ValueError: Error converting shape to a TensorShape: invalid literal for int() with base 10: 'class_name'.
I don't know if has to do with versions. First I trained with python 3.8 and the latest tensorflow version, but since Flask does not allow all the required libraries in 3.8, I used 3.7 in flask with tensorflow 2.0.0. So I retrained the model in my computer with 3.7 and tf 2.0.0 and uploaded the newer model files. However, the same error persists.
--update-- I put here the log error
Error running WSGI application ValueError: Error converting shape to a TensorShape: invalid literal for int() with base 10: 'class_name'.
File "/var/www/user_pythonanywhere_com_wsgi.py", line 16, in from main import app as application # noqa
File "/home/user/mysite/main.py", line 11, in model = tensorflow.keras.models.load_model('/home/user/mysite/models/modelo')
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 150, in load_model return saved_model_load.load(filepath, compile)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/saved_model/load.py", line 86, in load model = tf_load.load_internal(path, loader_cls=KerasObjectLoader)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/saved_model/load.py", line 541, in load_internal export_dir)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/saved_model/load.py", line 103, in init self._finalize()
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/saved_model/load.py", line 127, in _finalize node.add(layer)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper result = method(self, *args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 174, in add batch_shape=batch_shape, dtype=dtype, name=layer.name + '_input')
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/input_layer.py", line 263, in Input input_tensor=tensor)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/input_layer.py", line 125, in init ragged=ragged)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py", line 1057, in placeholder x = array_ops.placeholder(dtype, shape=shape, name=name)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/ops/array_ops.py", line 2630, in placeholder return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 6669, in placeholder shape = _execute.make_shape(shape, "shape")
File "/usr/lib/python3.7/site-packages/tensorflow_core/python/eager/execute.py", line 211, in make_shape e))
The error comes from a tensorflow file, and I am just passing the path where is the saved model