为什么在Keras-to-Tensorflow导出示例中keras.models.model_from_config()引发ValueError? [英] Why is ValueError thrown by keras.models.model_from_config() in the Keras-to-Tensorflow exporting example?

查看:237
本文介绍了为什么在Keras-to-Tensorflow导出示例中keras.models.model_from_config()引发ValueError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Keras网站具有本文有关将Keras模型导出到核心Tensorflow的文章.但是,步骤

The Keras website has this article about exporting Keras models to core Tensorflow. However the step

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.都抛出相同的错误.

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.

看来keras.utils.generic_utils.deserialize_keras_object()方法想在config词典中找到键"class_name""config"(

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"
  • "input_layers"
  • "layers"
  • "name"
  • "output_layers"

我还打开了一个问题 https://github.com/fchollet/keras/issues/7232 ,并创建了一个Gist,您可以自己运行并查看错误. https://gist.github.com/9thDimension/e1cdb2cd11f11309bfaf297b276f7456

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

推荐答案

keras.models.Model.get_config()的反函数似乎是keras.models.Model.from_config(),而不是keras.models.model_from_config()

The inverse of keras.models.Model.get_config() seems to be keras.models.Model.from_config(), not keras.models.model_from_config() https://keras.io/models/about-keras-models/. Try that instead?

这篇关于为什么在Keras-to-Tensorflow导出示例中keras.models.model_from_config()引发ValueError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆