2
$\begingroup$

I train my CNN model with a large number of epochs, with each epoch I print the training loss and accuracy, but there is a lot of high and low in these two metrics, I want to do early stopping with for example loss at 0.2 and accuracy at %95 or more because I get this at more than one epoch, my question is:

1- is early stopping done on train set or validation set?

2- if on validation set, should I print validation loss and accuracy for each epoch with with a train set loss and accuracy?

3- can you give an idea to do early stopping with a piece of code but not in keras, because I use tensorflow not keras?

$\endgroup$
3
$\begingroup$
  1. Early stopping is determined based on the validation set's results (either loss, accuracy or some other special metric).

  2. Usually early stopping is checked every single epoch so you will need to check your validation accuracy/loss after each epoch. You don't have to print it, but if it is already calculated, there is no reason to withhold it from yourself. (you can also check validation results every x epochs if it slows your training process too much).

  3. There are many sources that show how to use early stopping with tensorflow:

Early Stopping with TensorFlow and TFLearn

Early stopping with tf.estimator, how?

Early-stopping functionality for use with tf.estimator API.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you for your detailed answer, with one or more epoch should I check it with all the validation set or a batch of it? Also if I get the loss and accuracy that I want with validation set, should I stop it without care about loss and accuracy of train set? $\endgroup$ – Hunar A.Ahmed Jan 26 '19 at 10:46
  • $\begingroup$ You should check it on all the validation set and stop once you have reached your stopping criteria without taking into account the training set. $\endgroup$ – Mark.F Jan 26 '19 at 11:43
  • $\begingroup$ Usually you look at the validation loss, and when it starts increasing (preferably for at least 3-4 following epochs so that training won't stop due to 1 single back epoch), it means that your model starts to overfit and that's your cue to stop. $\endgroup$ – Mark.F Jan 26 '19 at 11:44
  • $\begingroup$ I am not using tf.estimator in my tensorflow model, is there any other way to do it without using estimator? thank you. $\endgroup$ – Hunar A.Ahmed Jan 27 '19 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.