如何使用保存在 HDF5 文件中的 Keras 训练模型进行预测?
How can I use a Keras trained model saved in a HDF5 file to make predictions?
我最近开始接触神经网络。我使用扩展的 MNIST 数据集、sklearn、Keras、numpy 和 pandas 构建了一个手写字符预测模型。主要目的是拍and/or上传手写的图片text/characters模型应该能猜到
训练阶段结束后,模型保存在文件my_model.h5
中。此时,我如何在接收输入图像并生成预测的 Python 程序中使用这个经过训练的模型(具体来说,my_model.h5
)?
从 Keras 和 TensorFlow 中的文件加载(训练的)模型有不同的方法。
Keras documentation 提供了一个展示如何加载模型的片段。
from keras.models import load_model
# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')
加载模型后,您可以使用model.predict
。
您可以根据需要将此代码集成到您的应用程序中。
我最近开始接触神经网络。我使用扩展的 MNIST 数据集、sklearn、Keras、numpy 和 pandas 构建了一个手写字符预测模型。主要目的是拍and/or上传手写的图片text/characters模型应该能猜到
训练阶段结束后,模型保存在文件my_model.h5
中。此时,我如何在接收输入图像并生成预测的 Python 程序中使用这个经过训练的模型(具体来说,my_model.h5
)?
从 Keras 和 TensorFlow 中的文件加载(训练的)模型有不同的方法。
Keras documentation 提供了一个展示如何加载模型的片段。
from keras.models import load_model
# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')
加载模型后,您可以使用model.predict
。
您可以根据需要将此代码集成到您的应用程序中。