Goto

Collaborating Authors

 savemodelcallback


Identify, version control, and document the best performing model during training

#artificialintelligence

Model training can be seen as the generation of subsequent versions of a model -- after each batch, the model weights are adjusted, and as a result, a new version of the model is created. Each new version will have varying levels of performance (as evaluated against a validation set). If everything goes well, training and validation loss will decrease with the number of training epochs. However, the best performing version of a model (here abbreviated as best model) is rarely the one obtained at the end of the training process. Take a typical overfitting case -- at first, both training and validation losses decrease as training progresses.


FastAI's callbacks for better CNN training -- meet SaveModelCallback.

#artificialintelligence

FastAI has a very flexible callback system that let's you greatly customize your training process. However, some of the pre-built and useful callbacks are not as easy to find without a deep dive into the documentation and to my knowledge, aren't covered in the regular courses. A common question is thus, "how do I automatically save my best model if it happens in the middle of a training run?" and the answer is to use the SaveModelCallback. The purpose of this callback, as the name implies, is to automatically save a new'best loss' model automatically during training. At the end of training, it then conveniently loads the top model so it's ready for you to continue with.