How can I use a Keras trained model saved in a HDF5 file to make predictions?

Thorvald Olavsen :

I recently got started with neural networks. I built a handwritten character prediction model using the extended MNIST dataset, sklearn, Keras, numpy and pandas. The main goal is to take and/or upload pictures of handwritten text/characters and the model should be able to guess.

After finishing the training phase, the model was saved in the file my_model.h5. At this point, how could I use this trained model (specifically, the my_model.h5) in a Python program that receives as input images and should produce a prediction?

nbro :

There are different ways to load a (trained) model from a file in Keras and TensorFlow.

The Keras documentation provides a snippet that shows how to load a model.

from keras.models import load_model

# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')

After having loaded the model, you can use model.predict.

You integrate this code into your application as you wish.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=34441&siteId=1