Auto saving your best model during training - meet SaveModelCallback

I only found the SaveModelCallback due to it being in mentioned deep into a thread here, but after using it have found it indispensable for training.
Thus, after finishing a project I wrote up a quick article for anyone who’s not familiar with it in case it’s helpful:

I’ve also done some customizations to it such as min_threshold to even bother saving and adding the metric amount to the saved filename to keep track of what model scored what over time. If those customizations are of interest, can post those out as well.

Anyway, this is an immensely useful callback and one that I haven’t seen mentioned in the coursework but I think it deserves more publicity :slight_smile:

8 Likes

after the model is saved, how to load it, to use load_learner or load? And when, before lr_find or after? Can we save to different file names so that we can compare them later?

Hi @jerron -
to load, just use:
learn.load(‘filename’) to load it.
You should see the model summary print out

First load, then do lr_find…you want to lr_find using the saved model otherwise you are testing random weights.

Yes, you can save to different file names but you have to change the name in the callback each time as by default it just keeps overwriting.
You may want to just go into the file system and rename the latest one wiht a more descriptive name, then continue training and that way you effectively save different models without having to pop and re-add the callback function.

Hope that helps!

1 Like

It definitely helped a lot. Thanks. Happy new year!

1 Like

Hi!

When using the SaveModelCallback, does it mean I don’t have to do learn.save() at the end of the training?

Thank you and keep safe!

Hey @d-slr yes you do not have to do a learn.save() at the end of training, the model autosaves in a models directory.

2 Likes