
    h                     8   S SK JrJrJr   \(       a   e\S   SL d   eS SKrS SKJr  \" \S5      (       d   eSqSS\S\S	S4S
 jjrSS\S\S	S4S jjrS\S\S	S4S jrSS jrSS jrSS jrSS jrSS jr\(       a	  \\\\\S.rg0 rg! \	\
4 a    Sr N]f = f)    )LOGGERSETTINGSTESTS_RUNNINGneptuneTN)File__version__scalarsstepreturnc                 z    [         (       a0  U R                  5        H  u  p#[         U   R                  X1S9  M     gg)a*  
Log scalars to the NeptuneAI experiment logger.

Args:
    scalars (dict): Dictionary of scalar values to log to NeptuneAI.
    step (int, optional): The current step or iteration number for logging.

Examples:
    >>> metrics = {"mAP": 0.85, "loss": 0.32}
    >>> _log_scalars(metrics, step=100)
)valuer
   N)runitemsappend)r	   r
   kvs       ]/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/utils/callbacks/neptune.py_log_scalarsr      s2     sMMODAFMMM- $     	imgs_dictgroupc                     [         (       a@  U R                  5        H+  u  p#[         U SU 3   R                  [        U5      5        M-     gg)a  
Log images to the NeptuneAI experiment logger.

This function logs image data to Neptune.ai when a valid Neptune run is active. Images are organized
under the specified group name.

Args:
    imgs_dict (dict): Dictionary of images to log, with keys as image names and values as image data.
    group (str, optional): Group name to organize images under in the Neptune UI.

Examples:
    >>> # Log validation images
    >>> _log_images({"val_batch": img_tensor}, group="validation")
/N)r   r   uploadr   )r   r   r   r   s       r   _log_imagesr   %   sB     sOO%DA5'1#&&tAw/ & r   title	plot_pathc                     SSK Jn  SSKJn  UR	                  U5      nUR                  5       nUR                  / SQSS/ / S9nUR                  U5        [        SU  3   R                  U5        g)z-Log plots to the NeptuneAI experiment logger.r   N)r   r      r   Fauto)frameonaspectxticksytickszPlots/)
matplotlib.imageimagematplotlib.pyplotpyplotimreadfigureadd_axesimshowr   r   )r   r   mpimgpltimgfigaxs          r   	_log_plotr2   9   s_    $#
,,y
!C
**,C	lE&TV	WBIIcN&  %r   c                     [         R                  " U R                  R                  =(       d    SU R                  R                  S/S9q[        U R                  5      R                  5        VVs0 s H  u  pXc  SOU_M     snn[
        S'   gs  snnf ! [         a#  n[        R                  " SU 35         SnAgSnAff = f)zHInitialize NeptuneAI run and log hyperparameters before training starts.Ultralytics)projectnametagsN zConfiguration/HyperparameterszINeptuneAI installed but not initialized correctly, not logging this run. )r   init_runargsr5   r6   r   varsr   	Exceptionr   warning)trainerr   r   es       r   on_pretrain_routine_startr@   E   s    	hLL((9M""

 W[[b[g[gVhVnVnVp/qVpda20IVp/q+,/q hbcdbefgghs*   A.B 0BB B 
CB==Cc           	      j   [        U R                  U R                  SS9U R                  S-   5        [        U R                  U R                  S-   5        U R                  S:X  aJ  [        U R                  R                  S5       Vs0 s H  oR                  [        U5      _M     snS5        ggs  snf )zILog training metrics and learning rate at the end of each training epoch.train)prefixr   ztrain_batch*.jpgMosaicN)
r   label_loss_itemstlossepochlrr   save_dirglobstemstr)r>   fs     r   on_train_epoch_endrN   S   s    ))'--)H'--Z[J[\W]]Q./}}W-=-=-B-BCU-VW-VVVSV^-VWYab Ws   B0c                     [         (       a%  U R                  S:X  a  SSKJn  U" U 5      [         S'   [	        U R
                  U R                  S-   5        g)zCLog model info and validation metrics at the end of each fit epoch.r   )model_info_for_loggerszConfiguration/Modelr   N)r   rG   ultralytics.utils.torch_utilsrP   r   metrics)r>   rP   s     r   on_fit_epoch_endrS   [   s<    
sw}}!H%;G%D!"'--!"34r   c           	          [         (       aJ  [        U R                  R                  S5       Vs0 s H  oR                  [        U5      _M     snS5        ggs  snf )z/Log validation images at the end of validation.zval*.jpg
ValidationN)r   r   rI   rJ   rK   rL   )	validatorrM   s     r   
on_val_endrW   d   sF    
sY-?-?-D-DZ-PQ-PVVSV^-PQS_` Qs   Ac                    [         (       a  SSS/S S 5       QnU Vs/ s H5  o R                  U-  R                  5       (       d  M&  U R                  U-  PM7     nnU H  n[        UR                  US9  M     [         SU R
                  R                  =(       d    U R
                  R                   SU R                  R                   3   R                  [        [        U R                  5      5      5        g	g	s  snf )
zCLog final results, plots, and model weights at the end of training.zresults.pngzconfusion_matrix.pngzconfusion_matrix_normalized.pngc              3   *   #    U  H	  o S 3v   M     g7f)z
_curve.pngN ).0xs     r   	<genexpr>on_train_end.<locals>.<genexpr>s   s     ?(>1:(>s   )F1PRPR)r   r   zweights/r   N)r   rI   existsr2   rK   r:   r6   taskbestr   r   rL   )r>   filesrM   s      r   on_train_endrg   k   s    
s "-
 @(>?	
 27ZA;K;Ka;O:W:W:Y&'""Q&ZAAFFa0  	hw||((=GLL,=,=>a@Q@Q?RST[[\`adeleqeqar\st  [s   %C:C:)r@   rN   rS   rW   rg   )r   )r8   )r   N)ultralytics.utilsr   r   r   r   neptune.typesr   hasattrr   ImportErrorAssertionErrordictintr   rL   r   r2   r@   rN   rS   rW   rg   	callbacksrZ   r   r   <module>rp      s    > =I$&&&"7M****
C.$ .c .$ ."04 0 0T 0(	&S 	&S 	&T 	&hc5au2  &?0, $ 
 
 
Y 	^$ Gs   /B 
BB