Ë
    Fêñi=  ã                   ó6  — d dl mZ d dlmZmZmZmZ 	 erJ ‚ed   du sJ ‚d dlZ ej                  ddd¬«      sJ ‚d dl	Z	d dl
Z
dai Zd	add
ededdfd„Zddededdfd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zer
eeeeeedœZyi Zy# eeef$ r dZY ŒMw xY w)é    )ÚPath)ÚLOGGERÚSETTINGSÚTESTS_RUNNINGÚchecksÚdvcTNÚdvclivez2.11.0)ÚverboseFÚpathÚprefixÚreturnc                 ó\  — t         r¦| j                  }t        j                  d|«      x}rM|d   }t        j                  dd| j
                  «      }t        |«      |z  j                  | j                  «      }t         j                  t        j                  j                  ||«      | «       yy)a`  Log images at specified path with an optional prefix using DVCLive.

    This function logs images found at the given path to DVCLive, organizing them by batch to enable slider
    functionality in the UI. It processes image filenames to extract batch information and restructures the path
    accordingly.

    Args:
        path (Path): Path to the image file to be logged.
        prefix (str, optional): Optional prefix to add to the image name when logging.

    Examples:
        >>> from pathlib import Path
        >>> _log_images(Path("runs/train/exp/val_batch0_pred.jpg"), prefix="validation")
    z_batch(\d+)é   Ú_batchN)ÚliveÚnameÚreÚsearchÚsubÚstemr   Úwith_suffixÚsuffixÚ	log_imageÚosr   Újoin)r   r   r   ÚmÚniÚnew_stems         úa/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/utils/callbacks/dvc.pyÚ_log_imagesr       s†   € õ Ø�y‰yˆô —	‘	˜.¨$Ó/Ð/ˆ1Ð/Ø�1‘ˆBÜ—v‘v˜n¨h¸¿	¹	ÓBˆHÜ˜“N RÑ'×4Ñ4°T·[±[ÓAˆDä�‰”r—w‘w—|‘| F¨DÓ1°4Õ8ð ó    Úplotsc                 óš   — | j                  «       D ]8  \  }}|d   }t        j                  |«      |k7  sŒ$t        ||«       |t        |<   Œ: y)a  Log plot images for training progress if they have not been previously processed.

    Args:
        plots (dict): Dictionary containing plot information with timestamps.
        prefix (str, optional): Optional prefix to add to the logged image paths.
    Ú	timestampN)ÚitemsÚ_processed_plotsÚgetr    )r"   r   r   Úparamsr$   s        r   Ú
_log_plotsr)   8   sO   € ð Ÿ™›ò /‰ˆˆfØ˜;Ñ'ˆ	Ü×Ñ Ó%¨Ó2Ü˜˜fÔ%Ø%.Ô˜TÒ"ñ	/r!   c                 óÖ  — g }g }| j                   j                  }t        | j                  j	                  «       «      }| j                   j
                  dk(  r|dgz  }t        |j                  j                  t        «      «      D ]H  \  }}t        |«      D ]5  \  }}|j                  ||   g|z  «       |j                  ||   g|z  «       Œ7 ŒJ t        j                  d||dd¬«       y)a²  Log confusion matrix for a validator using DVCLive.

    This function processes the confusion matrix from a validator object and logs it to DVCLive by converting the matrix
    into lists of target and prediction labels.

    Args:
        validator (BaseValidator): The validator object containing the confusion matrix and class names. Must have
            attributes confusion_matrix.matrix, confusion_matrix.task, and names.
    ÚdetectÚ
backgroundÚconfusion_matrixzcf.jsonT)r   Ú
normalizedN)r-   ÚmatrixÚlistÚnamesÚvaluesÚtaskÚ	enumerateÚTÚastypeÚintÚextendr   Úlog_sklearn_plot)	Ú	validatorÚtargetsÚpredsr/   r1   ÚtiÚpredÚpiÚnums	            r   Ú_log_confusion_matrixrA   F   sÝ   € ð €GØ€EØ×'Ñ'×.Ñ.€FÜ�—‘×'Ñ'Ó)Ó*€EØ×!Ñ!×&Ñ&¨(Ò2Ø�,�Ñˆä˜fŸh™hŸo™o¬cÓ2Ó3ò ,‰ˆˆDÜ  “ò 	,‰GˆB�Ø�N‰N˜E "™I˜;¨Ñ,Ô-Ø�L‰L˜% ™)˜ sÑ*Õ+ñ	,ð,ô
 	×ÑÐ,¨g°uÀ9ÐY]ÐÕ^r!   c                 óº   — 	 t        j                  dd¬«      at        j                  d«       y# t
        $ r"}t        j                  d|› �«       Y d}~yd}~ww xY w)zLInitialize DVCLive logger for training metadata during pre-training routine.T)Úsave_dvc_expÚcache_imagesz[DVCLive is detected and auto logging is enabled (run 'yolo settings dvc=False' to disable).zGDVCLive installed but not initialized correctly, not logging this run. N)r	   ÚLiver   r   ÚinfoÚ	ExceptionÚwarning)ÚtrainerÚes     r   Úon_pretrain_routine_startrK   _   sP   € ðfä�|‰|¨¸DÔAˆÜ�‰ÐqÕrøÜò fÜ�‰Ð`ÐabÐ`cÐd×eÑeûðfús   ‚,/ ¯	A¸AÁAc                 ó0   — t        | j                  d«       y)zPLog plots related to the training process at the end of the pretraining routine.ÚtrainN)r)   r"   ©rI   s    r   Úon_pretrain_routine_endrO   i   s   € äˆw�}‰}˜gÕ&r!   c                 óP   — t         r t         j                  | j                  «       yy)z9Log the training parameters if DVCLive logging is active.N)r   Ú
log_paramsÚargsrN   s    r   Úon_train_startrS   n   s   € åÜ�‰˜Ÿ™Õ%ð r!   c                 ó   — da y)zZSet the global variable _training_epoch value to True at the start of each training epoch.TN)Ú_training_epochrN   s    r   Úon_train_epoch_startrV   t   s	   € ð �Or!   c                 ó  — t         �rt        rýi | j                  | j                  d¬«      ¥| j                  ¥| j
                  ¥}|j                  «       D ]  \  }}t         j                  ||«       Œ | j                  dk(  r<ddl	m
}  || «      j                  «       D ]  \  }}t         j                  ||d¬«       Œ t        | j                  d«       t        | j                  j                  d«       t         j                  «        dayyy)	aõ  Log training metrics, model info, and advance to next step at the end of each fit epoch.

    This function is called at the end of each fit epoch during training. It logs various metrics including training
    loss items, validation metrics, and learning rates. On the first epoch, it also logs model
    information. Additionally, it logs training and validation plots and advances the DVCLive step counter.

    Args:
        trainer (BaseTrainer): The trainer object containing training state, metrics, and plots.

    Notes:
        This function only performs logging operations when DVCLive logging is active and during a training epoch.
        The global variable _training_epoch is used to track whether the current epoch is a training epoch.
    rM   ©r   r   )Úmodel_info_for_loggersF©ÚplotÚvalN)r   rU   Úlabel_loss_itemsÚtlossÚmetricsÚlrr%   Ú
log_metricÚepochÚultralytics.utils.torch_utilsrY   r)   r"   r:   Ú	next_step)rI   Úall_metricsÚmetricÚvaluerY   s        r   Úon_fit_epoch_endrh   z   sé   € ö •Ør˜×1Ñ1°'·-±-ÈÐ1ÓPÐrÐT[×TcÑTcÐrÐgn×gqÑgqÐrˆØ(×.Ñ.Ó0ò 	+‰MˆF�EÜ�O‰O˜F EÕ*ð	+ð �=‰=˜AÒÝLá!7¸Ó!@×!FÑ!FÓ!Hò ;‘�˜Ü—‘ ¨°E�Õ:ð;ô 	�7—=‘= 'Ô*Ü�7×$Ñ$×*Ñ*¨EÔ2ä�‰ÔØ‰ð  €tr!   c                 ó  — t         �ri | j                  | j                  d¬«      ¥| j                  ¥| j                  ¥}|j                  «       D ]  \  }}t         j                  ||d¬«       Œ t        | j                  d«       t        | j                  j                  d«       t        | j                  «       | j                  j                  «       r"t         j                  | j                  dd¬«       t         j                  «        y	y	)
aª  Log best metrics, plots, and confusion matrix at the end of training.

    This function is called at the conclusion of the training process to log final metrics, visualizations, and model
    artifacts if DVCLive logging is active. It captures the best model performance metrics, training plots, validation
    plots, and confusion matrix for later analysis.

    Args:
        trainer (BaseTrainer): The trainer object containing training state, metrics, and validation results.

    Examples:
        >>> # Inside a custom training loop
        >>> from ultralytics.utils.callbacks.dvc import on_train_end
        >>> on_train_end(trainer)  # Log final metrics and artifacts
    rM   rX   FrZ   r\   TÚmodel)ÚcopyÚtypeN)r   r]   r^   r_   r`   r%   ra   r)   r"   r:   rA   ÚbestÚexistsÚlog_artifactÚend)rI   re   rf   rg   s       r   Úon_train_endrq   ›   sÖ   € ö àr˜×1Ñ1°'·-±-ÈÐ1ÓPÐrÐT[×TcÑTcÐrÐgn×gqÑgqÐrˆØ(×.Ñ.Ó0ò 	7‰MˆF�EÜ�O‰O˜F E°ˆOÕ6ð	7ô 	�7—=‘= %Ô(Ü�7×$Ñ$×*Ñ*¨EÔ2Ü˜g×/Ñ/Ô0à�<‰<×ÑÔ Ü×Ñ˜gŸl™l°¸GÐÔDä�‰�
ð r!   )rK   rO   rS   rV   rh   rq   )Ú )r   N)Úpathlibr   Úultralytics.utilsr   r   r   r   r	   Úcheck_versionr   r   r   r&   rU   ÚImportErrorÚAssertionErrorÚ	TypeErrorÚstrr    Údictr)   rA   rK   rO   rS   rV   rh   rq   Ú	callbacks© r!   r   ú<module>r}      s  ðõ ç EÓ EðÙÐÐØ�E‰?˜dÑ"Ð"Ð"Ûàˆ6×Ñ 	¨8¸TÕBÐBÐBãÛð €DØÐð €Oñ9�dð 9 Cð 9°ó 9ñ6/�dð / Cð /°ó /ó_ó2fó'ó
&óó óBñP ð &?Ø#:Ø(Ø 4Ø,Ø$ññ 
ð 
ñ 
øðC 	�^ YÐ/ò Ø‚Gðús   ”6B Â
BÂB