我最近开始接触神经网络。我使用扩展的 MNIST 数据集、sklearn、Keras、numpy 和 pandas 构建了一个手写字符预测模型。主要目标是拍摄和/或上传手写文本/字符的图片,并且模型应该能够猜测。
完成训练阶段后,模型保存在文件 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
。
您可以根据需要将此代码集成到您的应用程序中。
关于python - 如何使用保存在 HDF5 文件中的 Keras 训练模型进行预测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60572631/