Skip to content

on_pretrain_routine_start


Called before the pretraining routine starts.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_pretrain_routine_start(trainer):
    """Called before the pretraining routine starts."""
    pass



on_pretrain_routine_end


Called after the pretraining routine ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_pretrain_routine_end(trainer):
    """Called after the pretraining routine ends."""
    pass



on_train_start


Called when the training starts.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_start(trainer):
    """Called when the training starts."""
    pass



on_train_epoch_start


Called at the start of each training epoch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_epoch_start(trainer):
    """Called at the start of each training epoch."""
    pass



on_train_batch_start


Called at the start of each training batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_batch_start(trainer):
    """Called at the start of each training batch."""
    pass



optimizer_step


Called when the optimizer takes a step.

Source code in ultralytics/yolo/utils/callbacks/base.py
def optimizer_step(trainer):
    """Called when the optimizer takes a step."""
    pass



on_before_zero_grad


Called before the gradients are set to zero.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_before_zero_grad(trainer):
    """Called before the gradients are set to zero."""
    pass



on_train_batch_end


Called at the end of each training batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_batch_end(trainer):
    """Called at the end of each training batch."""
    pass



on_train_epoch_end


Called at the end of each training epoch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_epoch_end(trainer):
    """Called at the end of each training epoch."""
    pass



on_fit_epoch_end


Called at the end of each fit epoch (train + val).

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_fit_epoch_end(trainer):
    """Called at the end of each fit epoch (train + val)."""
    pass



on_model_save


Called when the model is saved.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_model_save(trainer):
    """Called when the model is saved."""
    pass



on_train_end


Called when the training ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_train_end(trainer):
    """Called when the training ends."""
    pass



on_params_update


Called when the model parameters are updated.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_params_update(trainer):
    """Called when the model parameters are updated."""
    pass



teardown


Called during the teardown of the training process.

Source code in ultralytics/yolo/utils/callbacks/base.py
def teardown(trainer):
    """Called during the teardown of the training process."""
    pass



on_val_start


Called when the validation starts.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_val_start(validator):
    """Called when the validation starts."""
    pass



on_val_batch_start


Called at the start of each validation batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_val_batch_start(validator):
    """Called at the start of each validation batch."""
    pass



on_val_batch_end


Called at the end of each validation batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_val_batch_end(validator):
    """Called at the end of each validation batch."""
    pass



on_val_end


Called when the validation ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_val_end(validator):
    """Called when the validation ends."""
    pass



on_predict_start


Called when the prediction starts.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_predict_start(predictor):
    """Called when the prediction starts."""
    pass



on_predict_batch_start


Called at the start of each prediction batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_predict_batch_start(predictor):
    """Called at the start of each prediction batch."""
    pass



on_predict_batch_end


Called at the end of each prediction batch.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_predict_batch_end(predictor):
    """Called at the end of each prediction batch."""
    pass



on_predict_postprocess_end


Called after the post-processing of the prediction ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_predict_postprocess_end(predictor):
    """Called after the post-processing of the prediction ends."""
    pass



on_predict_end


Called when the prediction ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_predict_end(predictor):
    """Called when the prediction ends."""
    pass



on_export_start


Called when the model export starts.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_export_start(exporter):
    """Called when the model export starts."""
    pass



on_export_end


Called when the model export ends.

Source code in ultralytics/yolo/utils/callbacks/base.py
def on_export_end(exporter):
    """Called when the model export ends."""
    pass



get_default_callbacks


Return a copy of the default_callbacks dictionary with lists as default values.

Returns:

Type Description
defaultdict

A defaultdict with keys from default_callbacks and empty lists as default values.

Source code in ultralytics/yolo/utils/callbacks/base.py
def get_default_callbacks():
    """
    Return a copy of the default_callbacks dictionary with lists as default values.

    Returns:
        (defaultdict): A defaultdict with keys from default_callbacks and empty lists as default values.
    """
    return defaultdict(list, deepcopy(default_callbacks))



add_integration_callbacks


Add integration callbacks from various sources to the instance's callbacks.

Parameters:

Name Type Description Default
instance Trainer, Predictor, Validator, Exporter

An object with a 'callbacks' attribute that is a dictionary of callback lists.

required
Source code in ultralytics/yolo/utils/callbacks/base.py
def add_integration_callbacks(instance):
    """
    Add integration callbacks from various sources to the instance's callbacks.

    Args:
        instance (Trainer, Predictor, Validator, Exporter): An object with a 'callbacks' attribute that is a dictionary
            of callback lists.
    """
    from .clearml import callbacks as clearml_cb
    from .comet import callbacks as comet_cb
    from .dvc import callbacks as dvc_cb
    from .hub import callbacks as hub_cb
    from .mlflow import callbacks as mlflow_cb
    from .neptune import callbacks as neptune_cb
    from .raytune import callbacks as tune_cb
    from .tensorboard import callbacks as tensorboard_cb
    from .wb import callbacks as wb_cb

    for x in clearml_cb, comet_cb, hub_cb, mlflow_cb, neptune_cb, tune_cb, tensorboard_cb, wb_cb, dvc_cb:
        for k, v in x.items():
            if v not in instance.callbacks[k]:  # prevent duplicate callbacks addition
                instance.callbacks[k].append(v)  # callback[name].append(func)




Created 2023-04-16, Updated 2023-05-17
Authors: Glenn Jocher (3)