
    hh                        d dl mZmZmZ 	 erJ ed   du sJ d dlZd dlmZ  eed      sJ daddeded	dfd
Zddeded	dfdZdeded	dfdZddZddZddZddZddZer	eeeeedZyi Zy# e	e
f$ r dZY Mw xY w)    )LOGGERSETTINGSTESTS_RUNNINGneptuneTN)File__version__scalarsstepreturnc                 v    t         r3| j                         D ]  \  }}t         |   j                  ||       ! yy)aJ  
    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       a/var/www/html/dev/engine/venv/lib/python3.12/site-packages/ultralytics/utils/callbacks/neptune.py_log_scalarsr      s9     MMO 	.DAqFMMM-	.     	imgs_dictgroupc                     t         r?| j                         D ]+  \  }}t         | d|    j                  t        |             - yy)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   %   sG     OO% 	0DAq5'1#&&tAw/	0 r   title	plot_pathc                     ddl m} ddlm} |j	                  |      }|j                         }|j                  g dddg g       }|j                  |       t        d|     j                  |       y)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                 |   	 t        j                  | j                  j                  xs d| j                  j                  dg      at        | j                        j                         D ci c]  \  }}||dn| c}}t
        d<   yc c}}w # t        $ r"}t        j                  d|        Y d}~yd}~ww xY w)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/qdaQR20I/q+,/q hbcdbefgghs*   A+B -B
>B 
B 	B;B66B;c           	      j   t        | j                  | j                  d      | j                  dz          t        | j                  | j                  dz          | j                  dk(  rHt        | j                  j                  d      D ci c]  }|j                  t        |       c}d       yyc c}w )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QVVSV^WYab Ws   	B0c                     t         r$| j                  dk(  rddlm}  ||       t         d<   t	        | j
                  | j                  dz          y)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:    
w}}!H%;G%D!"'--!"34r   c           	          t         rHt        | j                  j                  d      D ci c]  }|j                  t        |       c}d       yyc c}w )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   s@    
Y-?-?-D-DZ-PQQVVSV^QS_` Qs   Ac                    t         rdddgd dD        }|D cg c]/  }| j                  |z  j                         s!| j                  |z  1 }}|D ]  }t        |j                  |        t         d| j
                  j                  xs | j
                  j                   d| j                  j                      j                  t        t        | j                                     y	y	c c}w )
zCLog final results, plots, and model weights at the end of training.zresults.pngzconfusion_matrix.pngzconfusion_matrix_normalized.pngc              3   &   K   | ]	  }| d   yw)z
_curve.pngN ).0xs     r   	<genexpr>z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_endrf   k   s    
 "-
 @(>?	
 27ZA7;K;Ka;O:W:W:Y'""Q&ZZ 	1AAFFa0	1 	hw||((=GLL,=,=>a@Q@Q?RST[[\`adeleqeqar\st  [s
   "C)C))r@   rN   rS   rW   rf   )r   )r8   )r   N)ultralytics.utilsr   r   r   r   neptune.typesr   hasattrr   ImportErrorAssertionErrordictintr   rL   r   r2   r@   rN   rS   rW   rf   	callbacksrZ   r   r   <module>ro      s    > =I$&&&"7M***
C.$ .c .$ ."04 0 0T 0(	&S 	&S 	&T 	&hc5au2  &?0, $ 
 
 
Y 	^$ Gs   $A2 2	A>=A>