加载keras保存的模型时发生TypeError:('Keyword参数不被理解:','module') [英] TypeError: ('Keyword argument not understood:', 'module') when loading keras saved model

查看:569
本文介绍了加载keras保存的模型时发生TypeError:('Keyword参数不被理解:','module')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在加载保存的keras模型并出现错误.

I am loading the keras saved model and getting the error.

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

I have already checked the Keras version that I have used to save the model and my current Keras on computer. Both are same and are Keras 2.2.4

当我尝试加载模型时

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

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

I am getting permission denied error as following:

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

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

I am not able to resolve this issue and would appreciate some help

推荐答案

您没有使用Keras 2.2.4构建模型,而是使用tf.keras构建了模型,现在您正在使用keras加载模型.这两个模块实际上都不兼容,这就是为什么您会出错的原因.

You didn't build the model using Keras 2.2.4, you built it using tf.keras, and now you are loading it with keras. Both modules are not actually compatible and this i why you get an error.

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

The simple solution is to never mix keras with tf.keras.

这篇关于加载keras保存的模型时发生TypeError:('Keyword参数不被理解:','module')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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