Answers.Body: <ul>
  <li><strong>Early stopping</strong>: stop the training when a condition is met</li>
  <li><strong>Checkpoint</strong> : frequently save the model</li>
  </ul>
  <p>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 <strong>a model</strong> that is <strong>assumed</strong> to be good enough and not overfitted.</p>
  <p>The purpose of the class <code>ModelCheckpoint</code> 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 <strong>several models</strong> that are saved at different epochs (or, more generally, &quot;checkpoints&quot;).</p>
  <p>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 <code>ModelCheckpoint</code>. In most of my cases, the best model is around the epoch during early stopping.</p>
  <p>*note: the model saving process is not done by <code>EarlyStopping</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T16:24:39.980Z
Answers.Text: 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).
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T16:34:27.077Z
Answers.Text: ah that's correct! I have edited my answer
Answers.UserDisplayName: malioboro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T16:37:25.837Z
Answers.Text: 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)
Answers.UserDisplayName: malioboro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T17:00:28.147Z
Answers.Text: 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.
Answers.UserDisplayName: Sanyou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T18:48:36.633Z
Answers.Text: @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.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T16:12:45.913Z
Answers.LastActivityDate: 2021-09-13T16:43:57.307Z
Answers.LastEditDate: 2021-09-13T16:43:57.307Z
Answers.UserDisplayName: malioboro
Body: <p>I want to get a model which works best, what should I go for while training the model, <a href="https://keras.io/api/callbacks/model_checkpoint/" rel="nofollow noreferrer">ModelCheckpoint</a>, <a href="https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/EarlyStopping" rel="nofollow noreferrer">EarlyStopping</a>, or both?</p>
  
Tags: <deep-learning><tensorflow><early-stopping>
Title: What is better to use: early stopping, model checkpoint or both?
UserDisplayName: Sadaf Shafi
ThreadText: # What is better to use: early stopping, model checkpoint or both?
  
  (Asked by: username_0 on 2021-09-13)
  
  I want to get a model which works best, what should I go for while training the model, [ModelCheckpoint](https://keras.io/api/callbacks/model_checkpoint/), [EarlyStopping](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/EarlyStopping), or both?
  
  **Tags:** deep-learning, tensorflow, early-stopping
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-09-13. Score: 3
  
  * **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`
  
  > **Comments:**
  > **username_2**: 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).  
  > **username_1**: ah that's correct! I have edited my answer  
  > **username_1**: 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)  
  > **username_3**: 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.  
  > **username_2**: @username_3 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.  
  
  ---
  
  