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?
CodePudding user response:
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.