Reputation: 2787
If yes, then, how did they do that? I mean, say that I have a custom-built model via subclassing. My optimizer is a separated object. How is it that one command save weights of two different objects? In particular, how does it know that those two objects are related? Is it due to magic done by model.compile?
EDIT: I just realized that a model has an attribute model.optimizer, is that how Keras do it? make the optimizer an attribute of a model and will be saved with it?
Upvotes: 2
Views: 1070
Reputation: 10400
No, model.save_weights()
only saves the model's parameters. The state of the stuffs that the model was compiled with (optimizers, callbacks, losses, metrics) will not be saved.
You should use model.save()
to save the model's optimizer and other training configurations. Please refer to this documentation (the most straigtforward way to save the optimizer together with the model).
If you for some reason want to use exactly model.save_weights()
, please refer to this stackoverflow question on how to save model's optimizer (might be a bit tricky).
Upvotes: 3