finetuner.tuner.callback.early_stopping module

class finetuner.tuner.callback.early_stopping.EarlyStopping(monitor='val_loss', mode='auto', patience=2, min_delta=0, baseline=None, verbose=False)[source]

Bases: finetuner.tuner.callback.base.BaseCallback

Callback to stop training when a monitored metric has stopped improving. A training loop will check at the end of every epoch whether the monitored metric is still improving or not.

  • monitor (str) – if monitor=’train_loss’ training will stop/resume according to the training loss, while if monitor=’val_loss’ training will stop/resume according to the validation loss. If monitor is set to an evaluation metric, training will stop/resume according to the value of this metric.

  • mode (str) – one of {‘auto’, ‘min’, ‘max’}. The decision to overwrite the current best monitor value is made based on either the maximization or the minimization of the monitored quantity. For an evaluation metric, this should be max, for val_loss this should be min, etc. In auto mode, the mode is set to min if monitor=’loss’ or monitor=’val_loss’ and to min otherwise.

  • patience (int) – integer, the number of epochs after which the training is stopped if there is no improvement. For example for patience = 2’, if the model doesn’t improve for 2 consecutive epochs, the training is stopped.

  • min_delta (int) – Minimum change in the monitored quantity to qualify as an improvement, i.e. an absolute change of less than min_delta, will count as no improvement.

  • baseline (Optional[float]) – Baseline value for the monitored quantity. Training will stop if the model doesn’t show improvement over the baseline.

  • verbose (bool) – Wheter to log score improvement events.


Called at the end of a training batch, after the backward pass.


Called at the end of an evaluation batch.


Called at the end of an epoch, after both training and validation (or just training if no validaton is provided).