【问题标题】:TypeError: ('Keyword argument not understood:', 'module') when loading keras saved model加载keras保存的模型时TypeError:('关键字参数不理解:','模块')
【发布时间】:2019-05-11 12:29:38
【问题描述】:

我正在加载 keras 保存的模型并收到错误消息。

new_model=load_model("my_model.h5")
new_model.summary()

错误

Traceback (most recent call last):
  File "C:\Users\admin\Desktop\phd python projects\tensorflow_img_class\src\tensorflow ui.py", line 43, in <module>
    new_model=load_model("my_model.h5")#, custom_objects = custom_objects)
  File "C:\Python37\lib\site-packages\keras\engine\saving.py", line 419, in load_model
    model = _deserialize_model(f, custom_objects, compile)
  File "C:\Python37\lib\site-packages\keras\engine\saving.py", line 225, in _deserialize_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "C:\Python37\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "C:\Python37\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "C:\Python37\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "C:\Python37\lib\site-packages\keras\engine\sequential.py", line 300, in from_config
    custom_objects=custom_objects)
  File "C:\Python37\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "C:\Python37\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "C:\Python37\lib\site-packages\keras\layers\core.py", line 764, in from_config
    return cls(**config)
  File "C:\Python37\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Python37\lib\site-packages\keras\layers\core.py", line 626, in __init__
    super(Lambda, self).__init__(**kwargs)
  File "C:\Python37\lib\site-packages\keras\engine\base_layer.py", line 128, in __init__
    raise TypeError('Keyword argument not understood:', kwarg)
TypeError: ('Keyword argument not understood:', 'module')

我已经检查了我用来保存模型的 Keras 版本和我当前在计算机上的 Keras。两者相同,都是 Keras 2.2.4

当我尝试加载模型时

model= tf.keras.models.load_model(
"saved_models/",
custom_objects=None,
compile=True)

我收到以下权限被拒绝错误:

OSError: Unable to open file (unable to open file: name = 'saved_models/', errno = 13, error message = 'Permission denied', flags = 0, o_flags = 0)

我无法解决此问题,希望得到一些帮助

【问题讨论】:

  • 不要用文件夹调用load_model,必须调用tf.keras.models.load_model('saved_models/my_model.h5')
  • 已尝试但未收到此错误 NameError: name 'feature_extractor_url' is not defined
  • 即错误与问题无关,我们只能回答问题中的内容。如果您有更多问题,您应该打开一个新问题,但在此之前请确保它不是像变量名中的拼写错误这样的小代码问题。

标签: python python-3.x tensorflow keras


【解决方案1】:

您没有使用 Keras 2.2.4 构建模型,您使用 tf.keras 构建它,现在您使用 keras 加载它。这两个模块实际上并不兼容,这就是您收到错误的原因。

简单的解决方案是永远不要将kerastf.keras 混合使用。

【讨论】:

  • 请检查更新。现在出现权限被拒绝错误
  • @user3050590 您将文件夹而不是文件名放入 load_model 您忘记了路径中的 my_model.h5。
  • 检查了这个解决方案github.com/Microsoft/AutonomousDrivingCookbook/issues/45,但不知道我需要编辑哪个文件..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 2020-08-07
  • 1970-01-01
  • 2020-12-09
  • 1970-01-01
  • 2019-04-12
相关资源
最近更新 更多