mirror of
https://github.com/ultralytics/ultralytics
synced 2026-04-21 14:07:18 +00:00
improve trainer callbacks docs with precise descriptions (#24122)
Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Co-authored-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com> Co-authored-by: fatih akyon <34196005+fcakyon@users.noreply.github.com>
This commit is contained in:
parent
564f3bbc09
commit
9a0962d97e
2 changed files with 29 additions and 29 deletions
|
|
@ -87,22 +87,22 @@ Below are all the supported callbacks. For more details, refer to the callbacks
|
|||
|
||||
### Trainer Callbacks
|
||||
|
||||
| Callback | Description |
|
||||
| --------------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| `on_pretrain_routine_start` | Triggered at the beginning of the pre-training routine. |
|
||||
| `on_pretrain_routine_end` | Triggered at the end of the pre-training routine. |
|
||||
| `on_train_start` | Triggered when the training starts. |
|
||||
| `on_train_epoch_start` | Triggered at the start of each training [epoch](https://www.ultralytics.com/glossary/epoch). |
|
||||
| `on_train_batch_start` | Triggered at the start of each training batch. |
|
||||
| `optimizer_step` | Triggered during the optimizer step. |
|
||||
| `on_before_zero_grad` | Triggered before gradients are zeroed. |
|
||||
| `on_train_batch_end` | Triggered at the end of each training batch. |
|
||||
| `on_train_epoch_end` | Triggered at the end of each training epoch. |
|
||||
| `on_fit_epoch_end` | Triggered at the end of each fit epoch. |
|
||||
| `on_model_save` | Triggered when the model is saved. |
|
||||
| `on_train_end` | Triggered when the training process ends. |
|
||||
| `on_params_update` | Triggered when model parameters are updated. |
|
||||
| `teardown` | Triggered when the training process is being cleaned up. |
|
||||
| Callback | Description |
|
||||
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `on_pretrain_routine_start` | Triggered at the beginning of the pre-training routine, before data loading and model setup. |
|
||||
| `on_pretrain_routine_end` | Triggered at the end of the pre-training routine, after data loading and model setup are complete. |
|
||||
| `on_train_start` | Triggered when the training starts, before the first [epoch](https://www.ultralytics.com/glossary/epoch) begins. |
|
||||
| `on_train_epoch_start` | Triggered at the start of each training [epoch](https://www.ultralytics.com/glossary/epoch), before batch iteration begins. |
|
||||
| `on_train_batch_start` | Triggered at the start of each training batch, before the forward pass. |
|
||||
| `optimizer_step` | Triggered during the optimizer step. Reserved for custom integrations; not called by the default training loop. |
|
||||
| `on_before_zero_grad` | Triggered before gradients are zeroed. Reserved for custom integrations; not called by the default training loop. |
|
||||
| `on_train_batch_end` | Triggered at the end of each training batch, after the backward pass. The optimizer step may be deferred due to gradient accumulation. |
|
||||
| `on_train_epoch_end` | Triggered at the end of each training epoch, after all batches are processed but **before** validation. Validation metrics and fitness may not be available yet. |
|
||||
| `on_model_save` | Triggered when the model checkpoint is saved, after validation. |
|
||||
| `on_fit_epoch_end` | Triggered at the end of each fit epoch (train + val), **after** validation and any checkpoint save. Validation metrics are available, and fitness is available for the per-epoch training call. This callback is also called during final best-model evaluation, where no checkpoint save occurs and fitness may not be present. |
|
||||
| `on_train_end` | Triggered when the training process ends, after final evaluation of the best model. |
|
||||
| `on_params_update` | Triggered when model parameters are updated. Reserved for custom integrations; not called by the default training loop. |
|
||||
| `teardown` | Triggered when the training process is being cleaned up. |
|
||||
|
||||
### Validator Callbacks
|
||||
|
||||
|
|
|
|||
|
|
@ -8,67 +8,67 @@ from copy import deepcopy
|
|||
|
||||
|
||||
def on_pretrain_routine_start(trainer):
|
||||
"""Called before the pretraining routine starts."""
|
||||
"""Called at the beginning of the pre-training routine, before data loading and model setup."""
|
||||
pass
|
||||
|
||||
|
||||
def on_pretrain_routine_end(trainer):
|
||||
"""Called after the pretraining routine ends."""
|
||||
"""Called at the end of the pre-training routine, after data loading and model setup are complete."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_start(trainer):
|
||||
"""Called when the training starts."""
|
||||
"""Called when the training starts, before the first epoch begins."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_epoch_start(trainer):
|
||||
"""Called at the start of each training epoch."""
|
||||
"""Called at the start of each training epoch, before batch iteration begins."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_batch_start(trainer):
|
||||
"""Called at the start of each training batch."""
|
||||
"""Called at the start of each training batch, before the forward pass."""
|
||||
pass
|
||||
|
||||
|
||||
def optimizer_step(trainer):
|
||||
"""Called when the optimizer takes a step."""
|
||||
"""Called during the optimizer step. Reserved for custom integrations; not called by default."""
|
||||
pass
|
||||
|
||||
|
||||
def on_before_zero_grad(trainer):
|
||||
"""Called before the gradients are set to zero."""
|
||||
"""Called before the gradients are set to zero. Reserved for custom integrations; not called by default."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_batch_end(trainer):
|
||||
"""Called at the end of each training batch."""
|
||||
"""Called at the end of each training batch, after the backward pass. Optimizer step may be deferred by accumulation."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_epoch_end(trainer):
|
||||
"""Called at the end of each training epoch."""
|
||||
"""Called at the end of each training epoch, after all batches but before validation."""
|
||||
pass
|
||||
|
||||
|
||||
def on_fit_epoch_end(trainer):
|
||||
"""Called at the end of each fit epoch (train + val)."""
|
||||
"""Called at the end of each fit epoch (train + val), after validation and any checkpoint save."""
|
||||
pass
|
||||
|
||||
|
||||
def on_model_save(trainer):
|
||||
"""Called when the model is saved."""
|
||||
"""Called when the model checkpoint is saved, after validation."""
|
||||
pass
|
||||
|
||||
|
||||
def on_train_end(trainer):
|
||||
"""Called when the training ends."""
|
||||
"""Called when the training ends, after final evaluation of the best model."""
|
||||
pass
|
||||
|
||||
|
||||
def on_params_update(trainer):
|
||||
"""Called when the model parameters are updated."""
|
||||
"""Called when the model parameters are updated. Reserved for custom integrations; not called by default."""
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue