-1

Instead of calling the fit method many times to count how many epoch is necessary to the model fit, can we say to keras, for example, we want the model to stop only when the loss function is less than 4e-4, or if x epochs passed and the loss didn't change more than 1e-4?

Red
  • 26,798
  • 7
  • 36
  • 58

1 Answers1

1

Yes. The "if x epochs passed and the loss didn't change more than 1e-4" is easily done with the EarlyStopping callback:

callbacks = [
  keras.callbacks.EarlyStopping(min_delta=1e-4, patience=num_epochs_to_wait)
]

For the other part, you'll need a custom callback class like the one from this answer that looks at the loss at the end of the epoch and stops the training if it's below the desired value.

GPhilo
  • 18,519
  • 9
  • 63
  • 89