Keras MobileNet无法保存先前保存的型号h5文件

时间:2018-05-09 22:24:50

标签: python tensorflow keras

我刚刚使用keras训练了一个MobileNet模型(使用tensorflow作为后端)。 培训结束后,我用

保存了模型
# serialize weights to HDF5
model_with_weights = os.path.join(model_dir, "model.h5")
model.save(model_with_weights)
print("Saved model to disk")

现在我想重新加载相同的模型...... 所以我试过这个(模型在正确的目录中)

model = load_model('model.h5', custom_objects={
                       'relu6': keras.applications.mobilenet.relu6,
                       'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D})

但我收到了这个错误,而且我不知道如何加载以前的训练模型。

File "load_model.py", line 79, in <module>
    'relu6': keras.applications.mobilenet.relu6})
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/saving.py", line 241, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/saving.py", line 318, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/layers/serialization.py", line 64, in deserialize
    printable_module_name='layer')
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/utils/generic_utils.py", line 173, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/network.py", line 1098, in from_config
    process_node(layer, node_data)
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/tensorflow/python/keras/_impl/keras/engine/network.py", line 1056, in process_node
    layer(input_tensors[0], **kwargs)
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/keras/engine/topology.py", line 606, in __call__
    previous_mask = _collect_previous_mask(inputs)
  File "/home/seba/Projects/venv3.5/lib/python3.5/site-packages/keras/engine/topology.py", line 2834, in _collect_previous_mask
    mask = node.output_masks[tensor_index]
AttributeError: 'Node' object has no attribute 'output_masks'

有人能指出我正确的方向吗?

0 个答案:

没有答案