加载保存的优化器时出错.keras python覆盆子

Mqu*_*iro 5 python raspberry-pi keras tensorflow

我已经在linux 64机器上训练了一个keras顺序模型并保存到.h5文件中.

这台PC我可以加载模型并毫无问题地进行预测.

现在我在Raspberry Pi 3中实现了已经安装了keras,tensorflow,h5py和python3的预测.

当我加载模型

from keras.models import load_model
model = load_model('model-0.6358.h5')
Run Code Online (Sandbox Code Playgroud)

, 我越来越:

usr/lib/python3.4/importlib/_bootstrap.py:321: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
return f(*args, **kwds)

/usr/local/lib/python3.4/dist-packages/keras/models.py:291: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
warnings.warn('Error in loading the saved optimizer '
Run Code Online (Sandbox Code Playgroud)

但是......它看起来似乎是正确的.

我该如何避免该警告信息?

Kir*_*iru 11

load_model 首先使用保存的权重构建已保存的模型体系结构,然后尝试使用其保存的权重构建已保存的优化程序.

但是,您会收到一条错误消息,因为根据加载模型的体系结构,保存的优化程序权重的形状与优化程序所期望的权重形状之间不匹配.

当我尝试保存并重新加载具有设置为内部子模型的模型时,我使用Keras 2.1.4遇到了这个问题trainable=False.保存模型时似乎不保留此信息,因此在重新设置内部子模型后trainable=True,优化器将期望比实际保存的权重更多.如果这可能是您的问题,我在此错误报告中描述了一种解决方法:

  1. 明确设置所有内部模型层的可训练性
  2. 在保存之前,所有层的可训练性标志必须设置为它们在模型编译时所具有的状态

如果您想要消除警告并且在保存之后不需要优化器,您也可以在没有优化器的情况下保存模型:使用 model.save(filename, include_optimizer=False)