
    h                        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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 NNf = f)    )LOGGERSETTINGSTESTS_RUNNINGclearmlTN)Task__version__titlereturnc                    SSK n[        R                  " 5       =n(       a  U  H  nUR                  5       (       d  M  UR	                  SUR
                  5      nU(       a  [        UR                  5       S   5      OSnUR                  5       R                  XR
                  R                  UR                  5       S5      [        U5      US9  M     gg)z
Log files (images) as debug samples in the ClearML task.

Args:
    files (list[Path]): A list of file paths in PosixPath format.
    title (str): A title that groups together images with the same values.
r   Nz_batch(\d+) )r	   series
local_path	iteration)rer   current_taskexistssearchnameintgroups
get_loggerreport_imagereplacegroupstr)filesr	   r   taskfitr   s          ]/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/utils/callbacks/clearml.py_log_debug_samplesr!      s       ""t"AxxzzYY~qvv635C		A/1	!..rxxz2(FSVWXSYen / 	  #    	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        [        R                  " 5       R                  5       R                  U SUSS9  g)	z
Log an image as a plot in the plot section of ClearML.

Args:
    title (str): The title of the plot.
    plot_path (str): The path to the saved image file.
r   N)r   r      r%   Fauto)frameonaspectxticksyticksr   )r	   r   figurereport_interactive)matplotlib.imageimagematplotlib.pyplotpyplotimreadr+   add_axesimshowr   r   r   report_matplotlib_figure)r	   r#   mpimgpltimgfigaxs          r    	_log_plotr:   %   su     %#
,,y
!C
**,C	lE&TV	WBIIcN""$==Bsu > r"   c           
      
    [         R                  " 5       =n(       a/  SSKJn  SSKJn  UR                  S5        UR                  S5        Od[         R                  " U R                  R                  =(       d    SU R                  R                  S/SSSSS.S	9n[        R                  " S
5        UR                  [        U R                  5      SS9  g! [         a#  n[        R                  " SU 35         SnAgSnAff = f)zHInitialize and connect ClearML task at the start of pretraining routine.r   )PatchPyTorchModelIO)PatchedMatplotlibNUltralyticsTF)pytorch
matplotlib)project_name	task_nametags
output_urireuse_last_task_idauto_connect_frameworkszClearML Initialized a new task. If you want to run remotely, please add clearml-init and connect your arguments before initializing YOLO.General)r   zGClearML installed but not initialized correctly, not logging this run. )r   r   'clearml.binding.frameworks.pytorch_bindr<   clearml.binding.matplotlib_bindr=   update_current_taskinitargsprojectr   r   warningconnectvars	Exception)trainerr   r<   r=   es        r    on_pretrain_routine_startrT   :   s    f$$&&4& TI33D911$799$\\11B]!,,++#_#(49(OD NN_ 	T',,'i8 f`ab`cdeefs   CC 
DC==Dc                    [         R                  " 5       =n(       a  U R                  S:X  a.  [        [	        U R
                  R                  S5      5      S5        U R                  U R                  SS9R                  5        H.  u  p#UR                  5       R                  SX#U R                  S9  M0     U R                  R                  5        H.  u  p#UR                  5       R                  SX#U R                  S9  M0     gg)	zKLog debug samples for the first epoch and report current training progress.r%   ztrain_batch*.jpgMosaictrain)prefixr   lrN)r   r   epochr!   sortedsave_dirgloblabel_loss_itemstlossitemsr   report_scalarrZ   )rR   r   kvs       r    on_train_epoch_endre   W   s      ""t"==Avg&6&6&;&;<N&OPRZ[,,W]]7,KQQSDAOO++GQW]]+S TJJ$$&DAOO++D!'--+P ' #r"   c                    [         R                  " 5       =n(       a  UR                  5       R                  SSU R                  U R
                  S9  U R                  R                  5        HA  u  p#UR                  S5      S   nUR                  5       R                  XBX0R
                  S9  MC     U R
                  S:X  aE  SSK	J
n  U" U 5      R                  5        H$  u  p#UR                  5       R                  X#5        M&     ggg)zFReport model information and metrics to logger at the end of an epoch.z
Epoch Time)r	   r   valuer   /r   rY   )model_info_for_loggersN)r   r   r   rb   
epoch_timer[   metricsra   splitultralytics.utils.torch_utilsri   report_single_value)rR   r   rc   rd   r	   ri   s         r    on_fit_epoch_endro   d   s      ""t"''|7;M;MY`YfYf 	( 	
 OO))+DAGGCLOEOO++Ea==+Q , ==AL.w7==?!55a; @  #r"   c                     [         R                  " 5       (       a/  [        [        U R                  R                  S5      5      S5        gg)z8Log validation results including labels and predictions.zval*.jpg
ValidationN)r   r   r!   r\   r]   r^   )	validators    r    
on_val_endrs   u   s6    6)"4"4"9"9*"EFU r"   c                 >   [         R                  " 5       =n(       a  SSS/S S 5       QnU Vs/ s H5  o0R                  U-  R                  5       (       d  M&  U R                  U-  PM7     nnU H  n[	        UR
                  US9  M     U R                  R                  R                  R                  5        H$  u  pEUR                  5       R                  XE5        M&     UR                  [        U R                  5      U R                  R                   SS9  g	g	s  snf )
z<Log final model and training results on training completion.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     ?(>1:(>s   )F1PRPR)r	   r#   F)
model_path
model_nameauto_delete_fileN)r   r   r]   r   r:   stemrr   rk   results_dictra   r   rn   update_output_modelr   bestrL   r   )rR   r   r   r   rc   rd   s         r    on_train_endr   |   s      ""t" "-
 @(>?	
 27ZA;K;Ka;O:W:W:Y&'""Q&ZAAFFa0  %%--::@@BDAOO11!7 C 	  C,=',,J[J[ns t # [s   %DD)rT   re   ro   rs   r   )zDebug Samples)r
   N)ultralytics.utilsr   r   r   r   r   hasattrImportErrorAssertionErrorr   r!   r:   rT   re   ro   rs   r   	callbacksrv   r"   r    <module>r      s    > =	I$&&&7M****S t (S S T *f:
Q<"Vu8  &?0, $ 
 
 
G 	^$ Gs   -A< <
B	B	