o
    WñhÀ  ã                
   @   sª  d Z ddlmZ ddlmZ dd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zi deg“deg“d	eg“deg“de	g“de
g“deg“deg“deg“deg“deg“deg“deg“deg“d!eg“d#eg“d%eg“egegegegegegegegd6œ¥Zd7d8„ Zd9d:„ Z d;S )<zVBase callbacks for Ultralytics training, validation, prediction, and export processes.é    )Údefaultdict)Údeepcopyc                 C   ó   dS )z-Called before the pretraining routine starts.N© ©Útrainerr   r   úT/var/www/vscode/kcb/lib/python3.10/site-packages/ultralytics/utils/callbacks/base.pyÚon_pretrain_routine_start
   ó   r	   c                 C   r   )z*Called after the pretraining routine ends.Nr   r   r   r   r   Úon_pretrain_routine_end   r
   r   c                 C   r   )z Called when the training starts.Nr   r   r   r   r   Úon_train_start   r
   r   c                 C   r   )z+Called at the start of each training epoch.Nr   r   r   r   r   Úon_train_epoch_start   r
   r   c                 C   r   )z+Called at the start of each training batch.Nr   r   r   r   r   Úon_train_batch_start   r
   r   c                 C   r   )z'Called when the optimizer takes a step.Nr   r   r   r   r   Úoptimizer_step#   r
   r   c                 C   r   )z,Called before the gradients are set to zero.Nr   r   r   r   r   Úon_before_zero_grad(   r
   r   c                 C   r   )z)Called at the end of each training batch.Nr   r   r   r   r   Úon_train_batch_end-   r
   r   c                 C   r   )z)Called at the end of each training epoch.Nr   r   r   r   r   Úon_train_epoch_end2   r
   r   c                 C   r   )z2Called at the end of each fit epoch (train + val).Nr   r   r   r   r   Úon_fit_epoch_end7   r
   r   c                 C   r   )zCalled when the model is saved.Nr   r   r   r   r   Úon_model_save<   r
   r   c                 C   r   )zCalled when the training ends.Nr   r   r   r   r   Úon_train_endA   r
   r   c                 C   r   )z-Called when the model parameters are updated.Nr   r   r   r   r   Úon_params_updateF   r
   r   c                 C   r   )z3Called during the teardown of the training process.Nr   r   r   r   r   ÚteardownK   r
   r   c                 C   r   )z"Called when the validation starts.Nr   ©Ú	validatorr   r   r   Úon_val_startS   r
   r   c                 C   r   )z-Called at the start of each validation batch.Nr   r   r   r   r   Úon_val_batch_startX   r
   r   c                 C   r   )z+Called at the end of each validation batch.Nr   r   r   r   r   Úon_val_batch_end]   r
   r   c                 C   r   )z Called when the validation ends.Nr   r   r   r   r   Ú
on_val_endb   r
   r   c                 C   r   )z"Called when the prediction starts.Nr   ©Ú	predictorr   r   r   Úon_predict_startj   r
   r    c                 C   r   )z-Called at the start of each prediction batch.Nr   r   r   r   r   Úon_predict_batch_starto   r
   r!   c                 C   r   )z+Called at the end of each prediction batch.Nr   r   r   r   r   Úon_predict_batch_endt   r
   r"   c                 C   r   )z8Called after the post-processing of the prediction ends.Nr   r   r   r   r   Úon_predict_postprocess_endy   r
   r#   c                 C   r   )z Called when the prediction ends.Nr   r   r   r   r   Úon_predict_end~   r
   r$   c                 C   r   )z$Called when the model export starts.Nr   ©Úexporterr   r   r   Úon_export_start†   r
   r'   c                 C   r   )z"Called when the model export ends.Nr   r%   r   r   r   Úon_export_end‹   r
   r(   )r   r    r!   r#   r"   r$   r'   r(   c                   C   s   t tttƒƒS )ae  
    Get the default callbacks for Ultralytics training, validation, prediction, and export processes.

    Returns:
        (dict): Dictionary of default callbacks for various training events. Each key in the dictionary represents an
            event during the training process, and the corresponding value is a list of callback functions that are
            executed when that event occurs.

    Examples:
        >>> callbacks = get_default_callbacks()
        >>> print(list(callbacks.keys()))  # show all available callback events
        ['on_pretrain_routine_start', 'on_pretrain_routine_end', ...]
    )r   Úlistr   Údefault_callbacksr   r   r   r   Úget_default_callbacks±   s   r+   c              
   C   sÖ   ddl m} |g}d| jjv rLddlm} ddlm} ddlm} ddlm} ddlm} ddl	m} ddl
m}	 ddlm}
 | |||||||	|
g¡ |D ]}| ¡ D ]\}}|| j| vrg| j|  |¡ qTqNdS )a0  
    Add integration callbacks to the instance's callbacks dictionary.

    This function loads and adds various integration callbacks to the provided instance. The specific callbacks added
    depend on the type of instance provided. All instances receive HUB callbacks, while Trainer instances also receive
    additional callbacks for various integrations like ClearML, Comet, DVC, MLflow, Neptune, Ray Tune, TensorBoard,
    and Weights & Biases.

    Args:
        instance (Trainer | Predictor | Validator | Exporter): The object instance to which callbacks will be added.
            The type of instance determines which callbacks are loaded.

    Examples:
        >>> from ultralytics.engine.trainer import BaseTrainer
        >>> trainer = BaseTrainer()
        >>> add_integration_callbacks(trainer)
    é   )Ú	callbacksÚTrainerN)Úhubr-   Ú	__class__Ú__name__ÚclearmlÚcometÚdvcÚmlflowÚneptuneÚraytuneÚtensorboardÚwbÚextendÚitemsÚappend)ÚinstanceÚhub_cbÚcallbacks_listÚclear_cbÚcomet_cbÚdvc_cbÚ	mlflow_cbÚ
neptune_cbÚtune_cbÚtb_cbÚwb_cbr-   ÚkÚvr   r   r   Úadd_integration_callbacksÂ   s&   €þÿrJ   N)!Ú__doc__Úcollectionsr   Úcopyr   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r'   r(   r*   r+   rJ   r   r   r   r   Ú<module>   s”   þýüûúùø	÷
öõôóòñïîíã!