跳至内容

参考资料 ultralytics/utils/callbacks/base.py

备注

该文件可从https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/utils/callbacks/base .py 获取。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!



ultralytics.utils.callbacks.base.on_pretrain_routine_start(trainer)

在预培训程序开始前调用。

源代码 ultralytics/utils/callbacks/base.py
def on_pretrain_routine_start(trainer):
    """Called before the pretraining routine starts."""
    pass



ultralytics.utils.callbacks.base.on_pretrain_routine_end(trainer)

在预培训例程结束后调用。

源代码 ultralytics/utils/callbacks/base.py
def on_pretrain_routine_end(trainer):
    """Called after the pretraining routine ends."""
    pass



ultralytics.utils.callbacks.base.on_train_start(trainer)

培训开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_start(trainer):
    """Called when the training starts."""
    pass



ultralytics.utils.callbacks.base.on_train_epoch_start(trainer)

在每个训练期开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_epoch_start(trainer):
    """Called at the start of each training epoch."""
    pass



ultralytics.utils.callbacks.base.on_train_batch_start(trainer)

在每批训练开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_batch_start(trainer):
    """Called at the start of each training batch."""
    pass



ultralytics.utils.callbacks.base.optimizer_step(trainer)

当优化器迈出一步时调用。

源代码 ultralytics/utils/callbacks/base.py
def optimizer_step(trainer):
    """Called when the optimizer takes a step."""
    pass



ultralytics.utils.callbacks.base.on_before_zero_grad(trainer)

在梯度设置为零之前调用。

源代码 ultralytics/utils/callbacks/base.py
def on_before_zero_grad(trainer):
    """Called before the gradients are set to zero."""
    pass



ultralytics.utils.callbacks.base.on_train_batch_end(trainer)

在每批训练结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_batch_end(trainer):
    """Called at the end of each training batch."""
    pass



ultralytics.utils.callbacks.base.on_train_epoch_end(trainer)

在每个训练周期结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_epoch_end(trainer):
    """Called at the end of each training epoch."""
    pass



ultralytics.utils.callbacks.base.on_fit_epoch_end(trainer)

在每个拟合历元(train + val)结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_fit_epoch_end(trainer):
    """Called at the end of each fit epoch (train + val)."""
    pass



ultralytics.utils.callbacks.base.on_model_save(trainer)

保存模型时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_model_save(trainer):
    """Called when the model is saved."""
    pass



ultralytics.utils.callbacks.base.on_train_end(trainer)

培训结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_train_end(trainer):
    """Called when the training ends."""
    pass



ultralytics.utils.callbacks.base.on_params_update(trainer)

更新模型参数时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_params_update(trainer):
    """Called when the model parameters are updated."""
    pass



ultralytics.utils.callbacks.base.teardown(trainer)

在拆卸训练过程中调用。

源代码 ultralytics/utils/callbacks/base.py
def teardown(trainer):
    """Called during the teardown of the training process."""
    pass



ultralytics.utils.callbacks.base.on_val_start(validator)

验证开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_val_start(validator):
    """Called when the validation starts."""
    pass



ultralytics.utils.callbacks.base.on_val_batch_start(validator)

在每个验证批次开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_val_batch_start(validator):
    """Called at the start of each validation batch."""
    pass



ultralytics.utils.callbacks.base.on_val_batch_end(validator)

在每个验证批次结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_val_batch_end(validator):
    """Called at the end of each validation batch."""
    pass



ultralytics.utils.callbacks.base.on_val_end(validator)

验证结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_val_end(validator):
    """Called when the validation ends."""
    pass



ultralytics.utils.callbacks.base.on_predict_start(predictor)

预测开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_predict_start(predictor):
    """Called when the prediction starts."""
    pass



ultralytics.utils.callbacks.base.on_predict_batch_start(predictor)

在每批预测开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_predict_batch_start(predictor):
    """Called at the start of each prediction batch."""
    pass



ultralytics.utils.callbacks.base.on_predict_batch_end(predictor)

在每批预测结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_predict_batch_end(predictor):
    """Called at the end of each prediction batch."""
    pass



ultralytics.utils.callbacks.base.on_predict_postprocess_end(predictor)

在预测的后处理结束后调用。

源代码 ultralytics/utils/callbacks/base.py
def on_predict_postprocess_end(predictor):
    """Called after the post-processing of the prediction ends."""
    pass



ultralytics.utils.callbacks.base.on_predict_end(predictor)

预测结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_predict_end(predictor):
    """Called when the prediction ends."""
    pass



ultralytics.utils.callbacks.base.on_export_start(exporter)

模型导出开始时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_export_start(exporter):
    """Called when the model export starts."""
    pass



ultralytics.utils.callbacks.base.on_export_end(exporter)

模型导出结束时调用。

源代码 ultralytics/utils/callbacks/base.py
def on_export_end(exporter):
    """Called when the model export ends."""
    pass



ultralytics.utils.callbacks.base.get_default_callbacks()

返回默认值为列表的 default_callbacks 字典副本。

返回:

类型 说明
defaultdict

defaultdict 包含 default_callbacks 中的键和作为默认值的空列表。

源代码 ultralytics/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))



ultralytics.utils.callbacks.base.add_integration_callbacks(instance)

将不同来源的集成回调添加到实例的回调中。

参数

名称 类型 说明 默认值
instance (Trainer, Predictor, Validator, Exporter)

对象,其 "回调 "属性是一个回调列表字典。 回调列表的字典。

所需
源代码 ultralytics/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.
    """

    # Load HUB callbacks
    from .hub import callbacks as hub_cb

    callbacks_list = [hub_cb]

    # Load training callbacks
    if "Trainer" in instance.__class__.__name__:
        from .clearml import callbacks as clear_cb
        from .comet import callbacks as comet_cb
        from .dvc import callbacks as dvc_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 tb_cb
        from .wb import callbacks as wb_cb

        callbacks_list.extend([clear_cb, comet_cb, dvc_cb, mlflow_cb, neptune_cb, tune_cb, tb_cb, wb_cb])

    # Add the callbacks to the callbacks dictionary
    for callbacks in callbacks_list:
        for k, v in callbacks.items():
            if v not in instance.callbacks[k]:
                instance.callbacks[k].append(v)





创建于 2023-11-12,更新于 2023-11-25
作者:glenn-jocher(3),Laughing-q(1)