Part I of this series, we have learned different approaches to save architecture only or save weights only or entire Keras model. However, we had covered only small part of saving entire model. In this article we will focus only on saving entire model when we have a custom metric/loss or a custom layer.
Outline of this article is as follows
As mentioned in Part I of this series, entire Keras model consist(the following is from TensorFlow website)
An architecture, or configuration, which specifies what layers the model contain, and how they’re connected
A set of weights values (the “state of the model”)
An optimizer****state_ (defined by compiling the model)_
A set of losses and metrics (defined by compiling the model)
Entire Keras model can be saved to a disk in two formats (i) TensorFlow SavedModel ( tf
) format, and (ii) H5 format.
Entire Keras model can be saved either during training or before/after training the model. We will see see more details and examples in the following sections.
How to save entire model?
Entire Keras model can be saved using Saved model API by model.save(‘MyModel’,save_format='tf')
or model.save('MyModel_h5',save_format='h5')
. The tf
format is default which means if you don’t provide save_format
argument, then the model is saved in TensorFlow SavedModel tf
format.
Why do we need to save entire model?
#keras #machine-learning #tensorflow #deep-learning