我正在加载保存的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)
我无法解决此问题,希望能获得一些帮助
答案 0 :(得分:1)
您不是使用Keras 2.2.4构建模型,而是使用tf.keras
构建模型,现在使用keras
加载模型。这两个模块实际上并不兼容,这就是为什么您会出错的原因。
简单的解决方案是永远不要将keras
与tf.keras
混合使用。