keras: "load_model()" Error When Updating Keras 2.0

Dear all, we are excited to see Keras has been updated to version 2.0. However, error occurred when I want to load a model that previously trained by keras.models.load_model().

 File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/models.py", line 232, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/models.py", line 293, in model_from_config
    return layer_module.deserialize(config, custom_objects=custom_objects)
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/layers/__init__.py", line 46, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/utils/generic_utils.py", line 140, in deserialize_keras_object
    list(custom_objects.items())))
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/engine/topology.py", line 2361, in from_config
    process_layer(layer_data)
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/engine/topology.py", line 2330, in process_layer
    custom_objects=custom_objects)
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/layers/__init__.py", line 46, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/utils/generic_utils.py", line 141, in deserialize_keras_object
    return cls.from_config(config['config'])
  File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.0-py2.7.egg/keras/engine/topology.py", line 1193, in from_config
    return cls(**config)
TypeError: __init__() got an unexpected keyword argument 'input_dtype'

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 15 (2 by maintainers)

Most upvoted comments

It turns out that in the current 2.0 version, we can load a .h5 model trained by keras 2.0. However, we could not load the model trained by keras 1.x beforehand.

+1 … we are facing the same issue here

Isn’t this a huge breaking change if 2.0 can’t load pre 2.0 models?

I had an issue: I tried to run test_layer = CustomerLayer() load_model(model_path, custom_objects={'layers': test_layer}) or load_model(model_path, custom_objects={'layers': CustomerLayer}) It always prompt error below: TypeError: load_model() got an unexpected keyword argument ‘custom_objects’

My settings are: Ubuntu 16; python 2 with latest keras 2.0.6

I have fixed the issue by using json to initialize the model architecture.

As for now, I rolled back to the version 1.2 …