keras: Unable to load model from .h5 file
# Unable to load model
Using TensorFlow backend.
Traceback (most recent call last):
File "ocv.py", line 7, in <module>
model = load_model('bottleneck_fc_model.h5')
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 230, in load_model
raise ValueError('No model found in config file.')
ValueError: No model found in config file.
I did not find a clear answer in other issues.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (1 by maintainers)
Did you saved with model.save or model.save_weights? Also, try to provide a working example so that we can see if it’s a bug.
I am using a pre-trained model such as Alexnet, In this case also, ending up with the same error.
I was downloaded the alexnet_weights from here–>https://github.com/heuritech/convnets-keras then I tried like this
from keras.models import load_model base_model=load_model(‘alexnet_weights.h5’)
I ended up with
ValueError: No model found in config file.
please help me to get rid out of it.
use ‘model.save()’ will work
It seems like your only using only the weights of the model. In that case you cant use load_model method. You have to set and define the architecture of your model and then use model.load_weights(‘alexnet_weights.h5’). Take a look at this for example https://stackoverflow.com/questions/35074549/how-to-load-a-model-from-an-hdf5-file-in-keras
I have this issue (ValueError: No model found in config file.) with TF 2.4.1,
tf.keras.callbacks.Callback.ModelCheckpoint
and a custom network.The reason of the issue is that the model was saved with
model.save_weights
despite having passedsave_weights_only = False
. I inspected tensorflow code andsave_weights_only
is forced toTrue
inModelCheckpoint
in some specific case (which happens for me) even if the user passedsave_weights_only = False
to construct theModelCheckpoint
object.Here is the code which causes the issue in the class
ModelCheckpoint
(tensorflow\python\keras\callbacks.py) :We should show a warning to inform the user that save_weights_only is forced to True (with the reasons). It will save people hours of debugging as I did.
This is related to https://github.com/tensorflow/tensorflow/issues/37620 and https://github.com/tensorflow/tensorflow/issues/42741
Can anyone guide me regarding above issue while loading the .h5 model.
I have used google colab to save this model. On google colab, I am able to load this model. But, it I download that model and trying to load that, it gives above erroe.
I am also facing the same issue
Any hopes?