# What is better to use: early stopping, model checkpoint or both?

I want to get a model which works best, what should I go for while training the model, ModelCheckpoint, EarlyStopping, or both?

• Early stopping: stop the training when a condition is met
• Checkpoint : frequently save the model

The purpose of Early Stopping is to avoid overfitting by stopping the model before it happens using a defined condition. If you use it, and then you save the model when the training is stopped*, you will get a model that is assumed to be good enough and not overfitted.

The purpose of the class ModelCheckpoint is to save models several times while training. This can be useful to find at which epoch the model gets the best performance. So, if you use it, you will get several models that are saved at different epochs (or, more generally, "checkpoints").

Even after using both methods, you will get some models, but they have a different purpose. None of them is better than the other. I almost always use both methods at the same time. You can use early stopping to stop the training and save a lot of models while training using ModelCheckpoint. In most of my cases, the best model is around the epoch during early stopping.

*note: the model saving process is not done by EarlyStopping

• What do you mean by "Even both methods "save the model,". As far as I remember, Early stopping does not save any model automatically. The EarlyStopping class has a parameter restore_best_weights, but this is just about restoring the weights of your final neural network (if I remember correctly).
– nbro
Sep 13 at 16:24
• ah that's correct! I have edited my answer Sep 13 at 16:34
• I try to highlight "save the model" part because in this part both methods may look similar (and I think that's the reason OP is confuse) Sep 13 at 16:37
• Maybe it's obvious but other (very important) checkpointing's purpose is to safeguard the training, especially if the training takes very long time and is being done on a (campus/company/shared) server that have risks of stopping the training (hardware issues, electrical issues, etc) we can still continue our training from the last checkpoint. Sep 13 at 17:00
• @Sanyou Yes, but you need to load the weights manually from the checkpoint, at least, as far as I remember, that's how keras works, i.e. it doesn't automatically restart training from the last saved checkpoint, unless you manually tell keras to do that. Feel free to edit this answer to add that detail or feel free to add another formal answer, because I think this "detail" is important, you also think.
– nbro
Sep 13 at 18:48