Can't reload a trained resnet50 model from a h5 file

末鹿安然 提交于 2019-12-14 03:52:13

问题


I am very new on neural network, and I am trying to use Keras to build a fish classifier. 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.

I write another python file to reload the RESNET-50 model from the h5 file. I use keras.models.load_model() to load h5 file. But python give me the error message like below, and I don't knwo why. 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')

回答1:


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. Then it's successful.



来源:https://stackoverflow.com/questions/53064834/cant-reload-a-trained-resnet50-model-from-a-h5-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!