加载keras模型h5时出错,需要将模型从tf.keras转换为keras

时间:2020-10-19 15:21:43

标签: tensorflow keras tensorflow2.0 tf.keras

使用tensorflow.keras.model存储/保存Keras模型h5,这在将模型加载到keras 2.2.4中时会产生问题(没有使用其他后端框架的tensorflow后端)。请您建议我将tf.keras h5转换为Keras可加载版本的方法。

    model = load_model("/home/Documents/explorePrj/Segmentation/models/model.h5", compile=False)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 419, in load_model
    model = _deserialize_model(f, custom_objects, compile)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 225, in _deserialize_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 458, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/usr/local/lib/python3.6/dist-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python3.6/dist-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/network.py", line 1022, in from_config
    process_layer(layer_data)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/network.py", line 1008, in process_layer
    custom_objects=custom_objects)
  File "/usr/local/lib/python3.6/dist-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/usr/local/lib/python3.6/dist-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
    return cls.from_config(config['config'])
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 1109, in from_config
    return cls(**config)
  File "/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'ragged'

0 个答案:

没有答案