What is save_weights_only parameter in tf.keras.callbacks.ModelCheckpoint?

Issue

In tensorflow’s documentation, the description of save_weights_only parameter of ModelCheckpoint is as follows:

if True, then only the model’s weights will be saved (model.save_weights(filepath)), else the full model is saved (model.save(filepath)).

What does it mean by "the full model is saved"? I know that we use model.load_weights('path/to/model') when save_weights_only=True. But what’s different when it’s False? I.e. what additional information is saved besides the weights? And how can we load this "full model"? Do we still need to define its layers and compile it before loading the saved model?

Solution

If you check the source code for ModelCheckpoint you can see that when save_weights_only=True you are actually calling model.save_weights() where model is an instance of tf.keras.Model. Checking the docs for the difference between model.save_weights and model.save, we are pointed to keras’ serialization and saving guide. Here it explains that whole model saving and loading entails:

  • The model’s architecture/config.
  • The model’s weight values.
  • The model’s compilation information.
  • The optimizer and its state, if any.

Answered By – o-90

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published