yolov10/docs/usage/callbacks.md
Glenn Jocher f921e1ac21
ultralytics 8.0.53 DDP AMP and Edge TPU fixes (#1362)
Co-authored-by: Richard Aljaste <richardaljasteabramson@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Vuong Kha Sieu <75152429+hotfur@users.noreply.github.com>
2023-03-12 02:08:13 +01:00

87 lines
1.5 KiB
Markdown

## Callbacks
Ultralytics framework supports callbacks as entry points in strategic stages of train, val, export, and predict modes.
Each callback accepts a `Trainer`, `Validator`, or `Predictor` object depending on the operation type. All properties of
these objects can be found in Reference section of the docs.
## Examples
### Returning additional information with Prediction
In this example, we want to return the original frame with each result object. Here's how we can do that
```python
def on_predict_batch_end(predictor):
# results -> List[batch_size]
_, _, im0s, _, _ = predictor.batch
im0s = im0s if isinstance(im0s, list) else [im0s]
predictor.results = zip(predictor.results, im0s)
model = YOLO(f"yolov8n.pt")
model.add_callback("on_predict_batch_end", on_predict_batch_end)
for (result, frame) in model.track/predict():
pass
```
## All callbacks
Here are all supported callbacks.
### Trainer
`on_pretrain_routine_start`
`on_pretrain_routine_end`
`on_train_start`
`on_train_epoch_start`
`on_train_batch_start`
`optimizer_step`
`on_before_zero_grad`
`on_train_batch_end`
`on_train_epoch_end`
`on_fit_epoch_end`
`on_model_save`
`on_train_end`
`on_params_update`
`teardown`
### Validator
`on_val_start`
`on_val_batch_start`
`on_val_batch_end`
`on_val_end`
### Predictor
`on_predict_start`
`on_predict_batch_start`
`on_predict_postprocess_end`
`on_predict_batch_end`
`on_predict_end`
### Exporter
`on_export_start`
`on_export_end`