towhee.trainer.callback.EarlyStoppingCallback¶
- class towhee.trainer.callback.EarlyStoppingCallback(trainercontrol: TrainerControl, monitor: str, min_delta: float = 0, patience: int = 0, mode: str = 'max', baseline: Optional[float] = None)[source]¶
Bases:
Callback
Assuming the goal of a training is to minimize the loss. With this, the metric to be monitored would be ‘loss’, and mode would be ‘min’. Training loop will check at end of every epoch whether the loss is no longer decreasing, considering the min_delta and patience if applicable. Once it’s found no longer decreasing. trainercontrol. should_training_stop is marked True.
- Parameters:
trainercontrol (towhee.trainer.callback.TrainerControl) – The trainercontrol which callback can operate.
monitor (str) – Quantity to be monitored.
min_delta (float) – 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.
patience (str) – Number of epochs with no improvement after which training will be stopped.
mode (str) – One of {“min”, “max”}. In min mode, training will stop when the quantity monitored has stopped decreasing; in “max” mode it will stop when the quantity monitored has stopped increasing.
baseline (float) – Baseline value for the monitored quantity. Training will stop if the model doesn’t show improvement over the baseline.
Methods
get_monitor_value
Hook function invoked before every batch calculation.
Hook function invoked after every batch calculation.
Hook function invoked before each epoch.
Hook function invoked after each epoch.
Hook function invoked before every batch calculation in evaluate stage.
Hook function invoked after every batch calculation in evaluate stage.
Hook function invoked before evaluate stage.
Hook function invoked after evaluate stage.
Hook function invoked before train stage.
Hook function invoked before every batch calculation in train stage.
Hook function invoked before train stage.
Hook function invoked after train stage.
Set the model to callback.
Set the optimizer to callback.
Set the trainercontrol to callback.
- __init__(trainercontrol: TrainerControl, monitor: str, min_delta: float = 0, patience: int = 0, mode: str = 'max', baseline: Optional[float] = None)[source]¶
- on_batch_begin(batch: Tuple, logs: Dict) None ¶
Hook function invoked before every batch calculation.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_batch_end(batch: Tuple, logs: Dict) None ¶
Hook function invoked after every batch calculation.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_epoch_begin(epochs: int, logs: Dict) None ¶
Hook function invoked before each epoch.
- Parameters:
epochs (int) – Epoch index.
logs (Dict) – Kv store to save and load info.
- on_epoch_end(epochs: int, logs: Optional[Dict] = None)[source]¶
Hook function invoked after each epoch.
- Parameters:
epochs (int) – Epoch index.
logs (Dict) – Kv store to save and load info.
- on_eval_batch_begin(batch: Tuple, logs: Dict) None ¶
Hook function invoked before every batch calculation in evaluate stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_eval_batch_end(batch: Tuple, logs: Dict) None ¶
Hook function invoked after every batch calculation in evaluate stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_eval_begin(logs: Dict) None ¶
Hook function invoked before evaluate stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_eval_end(logs: Dict) None ¶
Hook function invoked after evaluate stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_batch_begin(batch: Tuple, logs: Dict) None ¶
Hook function invoked before train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_batch_end(batch: Tuple, logs: Dict) None ¶
Hook function invoked before every batch calculation in train stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_train_begin(logs: Optional[Dict] = None)[source]¶
Hook function invoked before train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_end(logs: Optional[Dict] = None)[source]¶
Hook function invoked after train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- set_model(model: Module) None ¶
Set the model to callback.
- Parameters:
model (torch.nn.Module) – The model which callback can operate.
- set_optimizer(optimizer: Optimizer) None ¶
Set the optimizer to callback.
- Parameters:
optimizer (torch.optim.Optimizer) – The optimizer which callback can operate.
- set_trainercontrol(trainercontrol: TrainerControl) None ¶
Set the trainercontrol to callback.
- Parameters:
trainercontrol (towhee.trainer.callback.TrainerControl) – The trainercontrol which callback can operate.