該Keras網站有this article關於出口凱拉斯模型核心Tensorflow。然而步驟Keras-to-Tensorflow導出示例中爲什麼keras.models.model_from_config()拋出ValueError?
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': {...
人建議有使用model_from_config()
法Keras V1車型,因爲V2的釋放問題。不過,我已經嘗試過使用來自不同版本的一系列模型,包括內置的Keras ResNet50
以及在該腳本中定義的簡單單層MLP。所有拋出相同的錯誤。
這樣看來,該keras.utils.generic_utils.deserialize_keras_object()
方法希望找到在config
詞典(see source)的關鍵"class_name"
或"config"
。在檢查get_config()
創建的config
字典後,沒有這樣的條目;而不是有鑰匙:
"input_layers"
"layers"
"name"
"output_layers"
我也開了一個問題https://github.com/fchollet/keras/issues/7232並創建了可以運行自己,看看該錯誤的要點。 https://gist.github.com/9thDimension/e1cdb2cd11f11309bfaf297b276f7456
- Keras 2.0.6
- Tensorflow 1.1.0