gpt4 book ai didi

python - 无法从 h5 文件重新加载经过训练的 resnet50 模型

转载 作者:行者123 更新时间:2023-11-28 18:06:47 48 4
gpt4 key购买 nike

我是神经网络的新手,我正在尝试使用 Keras 构建鱼类分类器。我得到了一个使用 Keras 和 tensorflow-backend 创建 RESNET-50 模型的 python 代码,该代码使用 model.save() 输出一个 h5 文件。

我编写了另一个 python 文件以从 h5 文件重新加载 RESNET-50 模型。我使用 keras.models.load_model() 加载 h5 文件。但是 python 给我如下错误信息,我不知道为什么。请帮帮我,谢谢。

Traceback (most recent call last):
File "keras-cnn-predict.py", line 75, in <module>
model=keras.models.load_model(model_config_filename)
File "C:\Python\Python36\lib\site-packages\keras\engine\saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "C:\Python\Python36\lib\site-packages\keras\engine\saving.py", line 225, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "C:\Python\Python36\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "C:\Python\Python36\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
printable_module_name='layer')
File "C:\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "C:\Python\Python36\lib\site-packages\keras\engine\network.py", line 1022, in from_config
process_layer(layer_data)
File "C:\Python\Python36\lib\site-packages\keras\engine\network.py", line 1008, in process_layer
custom_objects=custom_objects)
File "C:\Python\Python36\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
printable_module_name='layer')
File "C:\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object
return cls.from_config(config['config'])
File "C:\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 1109, in from_config
return cls(**config)
File "C:\Python\Python36\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Python\Python36\lib\site-packages\keras\layers\convolutional.py", line 490, in __init__
**kwargs)
File "C:\Python\Python36\lib\site-packages\keras\layers\convolutional.py", line 117, in __init__
self.kernel_initializer = initializers.get(kernel_initializer)
File "C:\Python\Python36\lib\site-packages\keras\initializers.py", line 508, in get
return deserialize(identifier)
File "C:\Python\Python36\lib\site-packages\keras\initializers.py", line 503, in deserialize
printable_module_name='initializer')
File "C:\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object
return cls.from_config(config['config'])
File "C:\Python\Python36\lib\site-packages\keras\initializers.py", line 30, in from_config
return cls(**config)
File "C:\Python\Python36\lib\site-packages\keras\initializers.py", line 195, in __init__
'but got', distribution)
ValueError: ('Invalid `distribution` argument: expected one of {"normal", "uniform"} but got', 'truncated_normal')

最佳答案

D:\Anaconda3\lib\site-packages\keras\initializers.py in __init__(self, scale, mode, distribution, seed)
193 raise ValueError('Invalid `distribution` argument: '
194 'expected one of {"normal", "uniform"} '
--> 195 'but got', distribution)
196 self.scale = scale
197 self.mode = mode

ValueError: ('Invalid `distribution` argument: expected one of {"normal", "uniform"} but got', 'truncated_normal')

import tensorflow.python.keras 中替换 keras。那么就成功了。

关于python - 无法从 h5 文件重新加载经过训练的 resnet50 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53064834/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com