How to convert a trained Keras1 model to Keras2

I trained the model using Keras1. When I use an attempt to download it using Keras2

model = load_model('my_model.h5')

I get this error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/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/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/layers/__init__.py", line 46, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 140, in deserialize_keras_object
    list(custom_objects.items())))
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2374, in from_config
    process_layer(layer_data)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2343, in process_layer
    custom_objects=custom_objects)
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/__init__.py", line 46, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python2.7/dist-packages/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/engine/topology.py", line 1206, in from_config
    return cls(**config)
TypeError: __init__() got an unexpected keyword argument 'input_dtype'

This model works on my machine with Keras1 installed. Is there a way to convert a model to Keras2? Or should I re-train him for my Keras2 machine?

+4
source share

Source: https://habr.com/ru/post/1673807/


All Articles