简体   繁体   English

无法从h5文件重新加载训练有素的resnet50模型

[英]Can't reload a trained resnet50 model from a h5 file

I am very new on neural network, and I am trying to use Keras to build a fish classifier. 我是神经网络的新手,我正在尝试使用Keras来构建鱼类分类器。 I got a python code that uses Keras with tensorflow-backend to create a RESNET-50 model, the code use model.save() to output a h5 file. 我得到了一个使用Keras和tensorflow-backend创建RESNET-50模型的python代码,代码使用model.save()来输出h5文件。

I write another python file to reload the RESNET-50 model from the h5 file. 我写了另一个python文件来从h5文件重新加载RESNET-50模型。 I use keras.models.load_model() to load h5 file. 我使用keras.models.load_model()来加载h5文件。 But python give me the error message like below, and I don't knwo why. 但python给我的错误信息如下,我不知道为什么。 Please give me a hand, thanks. 请帮帮我,谢谢。

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')

In import tensorflow.python.keras replace keras . import tensorflow.python.keras替换keras Then it's successful. 然后它成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM