The Keras website has this article about exporting Keras models to core Tensorflow. However the step
new_model = model_from_config(config)
throws an error:
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': {...
People have suggested that there's a problem using the model_from_config()
method with Keras v1 models since the release of v2. However I have tried this with a range of models from different versions, including the built-in Keras ResNet50
and a simple single-layer MLP defined in that very script. All throw the same error.
It would appear that the keras.utils.generic_utils.deserialize_keras_object()
method wants to find a key "class_name"
or "config"
in the config
dictionary (see source). Upon inspection of the config
dict that get_config()
creates, there is no such entry; instead there are keys:
"input_layers"
"layers"
"name"
"output_layers"
I also opened an issue https://github.com/fchollet/keras/issues/7232 and created a Gist that you can run for yourself and see the error. https://gist.github.com/9thDimension/e1cdb2cd11f11309bfaf297b276f7456
- Keras 2.0.6
- Tensorflow 1.1.0