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

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

本文介绍了无法从H5文件重新加载经过训练的resnet50模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

推荐答案

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.然后成功了.

In import tensorflow.python.keras replace keras. Then it's successful.

这篇关于无法从H5文件重新加载经过训练的resnet50模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:10