Reputation: 43
I've searched about this a lot. In keras documentation it says that model.save() saves all the relevant info, i.e. model architecture, weights, optimizer state,...
Some other posts here on stackoverflow, mentioned saving the weights and loading them in the future to resume training, but the answers said that it's wrong, because it's not saving the optimizer state. I use callbacks to save best model base om validation accuracy, and it only save weights.
If weights aren't enough to resume training, why does call backs only save weights? Just for evaluating on the test set?
How can I properly save the best model then? Why doesn't call backs use model.save() to store all the info? How can i achieve this?
Upvotes: 1
Views: 861
Reputation: 904
Definitely model.save()
for all the reasons you've already mentioned. In a ModelCheckPoint
callback, save_weights_only=false
would do it. Set save_best_only=True
if you wanna save some space or avoid clutters. This is equivalent to model.save()
.
If weights aren't enough to resume training, why does call backs only save weights? Just for evaluating on the test set?
Yes.
Upvotes: 2
Reputation: 546
According to Keras ModelCheckPointCallback
documentation it saves either the whole model or only the weights according to save_weights_only
flag which is False
by default.
https://keras.io/callbacks/#modelcheckpoint
Upvotes: 2