加载.hdf5模型时出现问题(ValueError:未知层:FixedBatchNormalization)

时间:2019-11-13 15:45:16

标签: keras keras-layer

我正在尝试将.hdf5模型转换为.pb模型。我一直在加载模型。

这是我的代码:

import keras
keras.models.load_model('./model_frcnn.hdf5')

这是我的错误:

Traceback (most recent call last):
  File "/home/qendrim/solaborate/repos/solaborate/Solaborate.ML/scripts/solaborate_scripts/practice.py", line 2, in <module>
    keras.models.load_model('./model_frcnn.hdf5')
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/engine/saving.py", line 419, in load_model
    model = _deserialize_model(f, custom_objects, compile)
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/engine/saving.py", line 225, in _deserialize_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/engine/saving.py", line 458, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/engine/network.py", line 1022, in from_config
    process_layer(layer_data)
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/engine/network.py", line 1008, in process_layer
    custom_objects=custom_objects)
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/home/qendrim/anaconda3/envs/hello-ai/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 138, in deserialize_keras_object
    ': ' + class_name)
ValueError: Unknown layer: FixedBatchNormalization

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

好吧……Keras没有FixedBatchNormalization层。因此它无法加载此层。

如果您知道该层的代码,请将其传递给custom_objects={'FixedBatchNormalization' : FixedBatchNormalization}中的load_model参数。