简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM