Part-II : Converting(Saving) Keras Model as a single HDF5 (.h5) file
4 Part blog series : Documenting the learnings of my experimentation on Object Detection using Keras, Tensorflow
If you have read the part-I blog ,you can re-collect that we had used wpod-net pre-trained model with separate model weight (*.h5) and model structure (*.json) files. Both these files were loaded into the python program in-order to detect number plates.
In this blog post we will learn how to convert (save) keras model weight and model structure files into a single Keras *.h5 file
A Keras model consists of multiple components:
- The architecture or configuration, which specifies what layers the model contain, and how they’re connected, typically in
- A set of weights values (the “state of the model”), in
- An optimiser (defined by compiling the model).
The Keras API makes it possible to save all of these pieces to disk at once. Saving everything into a single archive in the TensorFlow SavedModel format (or in the older Keras H5 format).
If you like to follow along, refer to
2_convert_keras_model_to_single_file.ipynb jupyter notebook from my repository. Here are the implementation steps, the following program loads up keras model weight and model configuration files and saves them into a single model file by using
- Once keras model is saved as a single file, list the
modelsdirectory. Here you will find the file
- Finally, let’s use this newly created keras model file and try to detect license plate.
- You should get results like below
- In this blog we have learned how to save keras model file
*.h5and the configuration file
*.jsonas one file
*.h5keras model file
- We have also verified that, this new all-in-one model file is able to detect number plate from the image, as we wanted
- In the next blog , we will convert this keras model all-in-one file into tensorflow
(*.pb)frozengraph model file and its text representation