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
Introduction
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
json
orYAML
format. - A set of weights values (the “state of the model”), in
.h5
format - 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).
Implementation
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 model.save("models/wpod-net_all_io_one.h5")
line.
- Once keras model is saved as a single file, list the
models
directory. Here you will find the filewpod_net_all_in_one.h5
- Finally, let’s use this newly created keras model file and try to detect license plate.
- You should get results like below
Summary
- In this blog we have learned how to save keras model file
*.h5
and the configuration file*.json
as one file*.h5
keras 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