I have done training and when loading load_model there is an error like that. please give enlightenment.
problem :
I don't know a solution but you can try it once that you had import load_model so can use directly in code like: model = load_model('/....')
Resolved on my CNN.
Are you trying to load a model from a checkpoint? Because that's exactly how it went with me.
When you use model_checkpoint it saves the model in a .h5 file. So, you have to load it using model.load_weights('NAMEOFFILE.h5').
But, if you use model.save function, you will have to use model.load.
Hope this works for you also. Good luck!
This error happens on keras 2.3.4 (last of this time) with tensorflow 2.2.0 built for python 3.7 on Raspberry pi 4 b
I tested on python 3.6.10 on amd64 and it worked fine there.
Had the same error, try to use the nightly TensorFlow version instead.
A version change has done the trick for me.
tensorflow==2.3.0
numpy==1.18.0 (tensorflow 2.3.0 requires numpy<1.19.0,>=1.16.0)
Python 3.8
I faced the same issue when I tried to load a trained model generated on Google Colab (TensorFlow 2.3.0) to my local machine (TensorFlow 2.0.0)
@libinruan Did you manage to solve it?
@libinruan Did you manage to solve it?
I think it's a version issue when a model is saved in Tensorflow 2.3 and when trying to load the model in previous versions of TensorFlow. just maintaining the same version for saving and loading would probably solve the issue.
from tensorflow.keras.models import load_model
then
Thank you, the last thing works fine!
Yeah I too tried hard but did not get any solution, at last i looked all the parameters in load_model function and tried compile = False and it worked!! :)
@MPS-MASTER your solution worked like a charm. Thanks.
- just change
- from keras.models import load_model
- to
- from tensorflow.keras.models import load_model
- then
- model = load_model('model.h5', compile = False)
Awesome
- just change
- from keras.models import load_model
- to
- from tensorflow.keras.models import load_model
- then
- model = load_model('model.h5', compile = False)
Thanks! Anybody could explain why this is working though?
- just change
- from keras.models import load_model
- to
- from tensorflow.keras.models import load_model
- then
- model = load_model('model.h5', compile = False)
Thanks! Anybody could explain why this is working though?
>
- just change
- from keras.models import load_model
- to
- from tensorflow.keras.models import load_model
- then
- model = load_model('model.h5', compile = False)
Thanks! Anybody could explain why this is working though?
- Fundamentally this is the problem of environment. So you save a model in an environment and you load it to different environment (Ubantu to windows something like that).
2.other thing is Keras is an interface over Tensorflow so better to use Tensorflow instead of Keras(because dependencies are different in different environment related to keras).- Every time we load a model by default it compiles(That's a problem because of different environment). If we do compile == False then we are forcing it not to compile.
Then, would I have problems when using the model?
For me is exactly as u said it. Im training and saving my model locally then uploading to stagging server. Would I better do any tests if I set compile to False?
No it should works fine. I have used it. Did not get any problem.
No it should works fine. I have used it. Did not get any problem.
Okay thank you! :+1:
- solo cambia
- desde keras.models import load_model
- a
- desde tensorflow.keras.models import load_model
- luego
- model = load_model ('model.h5', compile = False)
ME SIRVIO PERFECTAMENTE, tenia el problema de cargar el modelo creado en gogle colab en formato h5,
Quisiera consultarte cuando guardo el mismo modelo pero con extensi贸n "tf", utilizando la forma que recomienda keras: model.save("model") o model.save("model", save_format='tf') ambas sin extensiones ".h5" EN GOOGLE COLAB en ves de guardar el archivo como se hace con la extensi贸n ".h5" SE CREA UNA CARPETA y no tengo idea porque sucede esto (UTILIZARIA LA FORMA ".h5" pero creo mis modelos con la funci贸n while y el archivo guardado con la extensi贸n ".h5" pesa demasiado (en algunos casos ya que el while demora mucho en encontrar mi modelo deseado) pesa mas de 1gb).
Quisiera su apoyo, muchas gracias!!!
Most helpful comment
from tensorflow.keras.models import load_model
then