EarlyStopping#

class braintools.trainer.EarlyStopping(monitor='val_loss', mode='min', patience=3, min_delta=0.0, verbose=False, strict=True, check_finite=True)#

Stop training when a monitored metric has stopped improving.

Parameters:
  • monitor (str) – Metric to monitor.

  • mode (str) – One of ‘min’ or ‘max’. In ‘min’ mode, training stops when the quantity monitored has stopped decreasing.

  • patience (int) – Number of epochs with no improvement after which training will be stopped.

  • min_delta (float) – Minimum change to qualify as an improvement.

  • verbose (bool) – Whether to print early stopping messages.

  • strict (bool) – If True, raise error if monitor metric not found.

  • check_finite (bool) – Stop training if the metric becomes NaN or infinite.

Examples

>>> early_stop = EarlyStopping(
...     monitor='val_loss',
...     patience=5,
...     mode='min',
... )
>>> trainer = Trainer(callbacks=[early_stop])
load_state_dict(state_dict)[source]#

Load state from state dict.

on_validation_epoch_end(trainer, module)[source]#

Check if training should stop.

property should_stop: bool#

Whether training should stop.

state_dict()[source]#

Return state dict for checkpointing.

Return type:

Dict[str, Any]