
    v-j,              
       v   d Z ddlmZ ddlmZ d Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd 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d.Zd/ Zd0 Z d1S )2zVBase callbacks for Ultralytics training, validation, prediction, and export processes.    )defaultdict)deepcopyc                     dS )zYCalled at the beginning of the pre-training routine, before data loading and model setup.N trainers    `/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/ultralytics/utils/callbacks/base.pyon_pretrain_routine_startr
   
       D    c                     dS )z_Called at the end of the pre-training routine, after data loading and model setup are complete.Nr   r   s    r	   on_pretrain_routine_endr      r   r   c                     dS )z?Called when the training starts, before the first epoch begins.Nr   r   s    r	   on_train_startr      r   r   c                     dS )zJCalled at the start of each training epoch, before batch iteration begins.Nr   r   s    r	   on_train_epoch_startr      r   r   c                     dS )zDCalled at the start of each training batch, before the forward pass.Nr   r   s    r	   on_train_batch_startr      r   r   c                     dS )zZCalled during the optimizer step. Reserved for custom integrations; not called by default.Nr   r   s    r	   optimizer_stepr   #   r   r   c                     dS )zeCalled before the gradients are set to zero. Reserved for custom integrations; not called by default.Nr   r   s    r	   on_before_zero_gradr   (   r   r   c                     dS )z{Called at the end of each training batch, after the backward pass. Optimizer step may be deferred by
    accumulation.
    Nr   r   s    r	   on_train_batch_endr   -   s	     	Dr   c                     dS )zRCalled at the end of each training epoch, after all batches but before validation.Nr   r   s    r	   on_train_epoch_endr   4   r   r   c                     dS )z\Called at the end of each fit epoch (train + val), after validation and any checkpoint save.Nr   r   s    r	   on_fit_epoch_endr   9   r   r   c                     dS )z<Called when the model checkpoint is saved, after validation.Nr   r   s    r	   on_model_saver    >   r   r   c                     dS )zHCalled when the training ends, after final evaluation of the best model.Nr   r   s    r	   on_train_endr"   C   r   r   c                     dS )zfCalled when the model parameters are updated. Reserved for custom integrations; not called by default.Nr   r   s    r	   on_params_updater$   H   r   r   c                     dS )z3Called during the teardown of the training process.Nr   r   s    r	   teardownr&   M   r   r   c                     dS )z"Called when the validation starts.Nr   	validators    r	   on_val_startr*   U   r   r   c                     dS )z-Called at the start of each validation batch.Nr   r(   s    r	   on_val_batch_startr,   Z   r   r   c                     dS )z+Called at the end of each validation batch.Nr   r(   s    r	   on_val_batch_endr.   _   r   r   c                     dS )z Called when the validation ends.Nr   r(   s    r	   
on_val_endr0   d   r   r   c                     dS )z"Called when the prediction starts.Nr   	predictors    r	   on_predict_startr4   l   r   r   c                     dS )z-Called at the start of each prediction batch.Nr   r2   s    r	   on_predict_batch_startr6   q   r   r   c                     dS )z+Called at the end of each prediction batch.Nr   r2   s    r	   on_predict_batch_endr8   v   r   r   c                     dS )z8Called after the post-processing of the prediction ends.Nr   r2   s    r	   on_predict_postprocess_endr:   {   r   r   c                     dS )z Called when the prediction ends.Nr   r2   s    r	   on_predict_endr<      r   r   c                     dS )z$Called when the model export starts.Nr   exporters    r	   on_export_startr@      r   r   c                     dS )z"Called when the model export ends.Nr   r>   s    r	   on_export_endrB      r   r   r
   r   r   r   r   r   r   r   r   r   r    r"   r$   r&   r*   r,   r.   )r0   r4   r6   r:   r8   r<   r@   rB   c                  P    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 represents an event during the
            training process, and the corresponding value is a list of callback functions 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	   get_default_callbacksrF      s     tX&788999r   c           
      x   ddl m} ddlm} ||g}d| j        j        v rMd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 ]K}|                                D ]4\  }}|| j        |         vr | j        |                             |           5LdS )a+  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)hubrI   platform	__class____name__clearmlcometdvcmlflowneptuneraytunetensorboardwbextenditemsappend)instancehub_cbplatform_cbcallbacks_listclear_cbcomet_cbdvc_cb	mlflow_cb
neptune_cbtune_cbtb_cbwb_cbrI   kvs                  r	   add_integration_callbacksrh      sl   " )(((((222222 k*N H&///222222000000,,,,,,222222444444111111333333******x69jRY[`bghiii $ 0 0	OO%% 	0 	0DAq*1---"1%,,Q///	00 0r   N)!__doc__collectionsr   copyr   r
   r   r   r   r   r   r   r   r   r   r    r"   r$   r&   r*   r,   r.   r0   r4   r6   r8   r:   r<   r@   rB   rE   rF   rh   r   r   r	   <module>rl      s   \ \ # # # # # #      
	 	 	
	 	 	
	 	 	
	 	 	
	 	 	
	 	 	
	 	 	
	 	 		 	 	
	 	 	
	 	 	
	 	 	
	 	 	
	 	 		 	 	
	 	 	
	 	 	
	 	 		 	 	
	 	 	
	 	 	
	 	 	
	 	 		 	 	
	 	 	
";!<  78 ~&	
 12 12 ~& /0 -. -. )* m_ \N )* 
" \N#$ -.%& )*'( ,)*56#=">12%&'(#_;   B: : : (0 (0 (0 (0 (0r   