Keras 网站上有关于将 Keras 模型导出到核心 Tensorflow 的 this article。然而这一步
new_model = model_from_config(config)
抛出一个错误:
Traceback (most recent call last):
File "/home/hal9000/tf_serving_experiments/sndbx.py", line 38, in <module>
new_model = model_from_config(config)
File "/home/hal9000/keras2env/local/lib/python2.7/site-packages/keras/models.py", line 304, in model_from_config
return layer_module.deserialize(config, custom_objects=custom_objects)
File "/home/hal9000/keras2env/local/lib/python2.7/site-packages/keras/layers/__init__.py", line 54, in deserialize
printable_module_name='layer')
File "/home/hal9000/keras2env/local/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 122, in deserialize_keras_object
raise ValueError('Improper config format: ' + str(config))
ValueError: Improper config format: {'layers': [{'class_name': 'InputLayer', 'config': {...
人们提出,自从 v2 发布以来,对 Keras v1 模型使用 model_from_config() 方法存在问题。但是,我已经尝试使用不同版本的一系列模型进行此操作,包括内置的 Keras ResNet50 和在该脚本中定义的简单单层 MLP。都抛出相同的错误。
看起来 keras.utils.generic_utils.deserialize_keras_object() 方法想要找到一个键 "class_name" 或 "config" 在 config 字典 ( see source ) 中。检查 get_config() 创建的 config 字典,没有这样的条目;取而代之的是键:
“输入层”“图层”“名字”“output_layers”
我还打开了一个问题 https://github.com/fchollet/keras/issues/7232 并创建了一个 Gist,您可以自己运行它并查看错误。 https://gist.github.com/9thDimension/e1cdb2cd11f11309bfaf297b276f7456
- 凯拉斯 2.0.6
- tensorflow 1.1.0
请您参考如下方法:
无论出于何种原因,keras.models.Model.get_config() 返回的字典对象与 keras.models.model_from_config() 方法不兼容以重新水化模型.
我将它们替换为对 keras.models.Model.model_to_json() 和 keras.models.model_from_json() 的等效调用,并且能够成功进行。
