Keras: Unable to load model from .h5 file

Created on 11 Jun 2017  路  11Comments  路  Source: keras-team/keras

# 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.

Most helpful comment

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.

All 11 comments

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.

Thank You,
I was saving 'weights' but trying to call a 'model'.

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.

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

pretr_model=load_model('/home/ajay_sg/Desktop/arnekt_pdf/alaj_RPN_2230/models/vgg16_weights.h5')
it is throwing an error
ValueError: No model found in config file.

use 'model.save()' will work

model = load_model('F:/Yagnesh_Project/deep_learning_flask_integration/mode_files/three_clas.h5')
Traceback (most recent call last):

File "", line 1, in
model = load_model('F:/Yagnesh_Project/deep_learning_flask_integration/mode_files/three_clas.h5')

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\saving\save.py", line 184, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py", line 178, in load_model_from_hdf5
custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\saving\model_config.py", line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\serialization.py", line 109, in deserialize
printable_module_name='layer')

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 373, in deserialize_keras_object
list(custom_objects.items())))

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\sequential.py", line 398, in from_config
custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\serialization.py", line 109, in deserialize
printable_module_name='layer')

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 375, in deserialize_keras_object
return cls.from_config(cls_config)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 655, in from_config
return cls(**config)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\convolutional.py", line 599, in __init__
**kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\convolutional.py", line 125, in __init__
**kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py", line 456, in _method_wrapper
result = method(self, args, *kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 294, in __init__
generic_utils.validate_kwargs(kwargs, allowed_kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 792, in validate_kwargs
raise TypeError(error_message, kwarg)

TypeError: ('Keyword argument not understood:', 'groups')

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.

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 have the same issue.
Did you find the solution?

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 have the same issue.

Did you find the solution?

Even I have the same issue if you get the answer can you please let me also know

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 have the same issue.
Did you find the solution?

Even I have the same issue if you get the answer can you please let me also know

The only solution I found was saving the model in google drive directly and using from there itself in Collab
Even for that I'm not 100 percent sure if it works in all cases.

Was this page helpful?
0 / 5 - 0 ratings