
    j                         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 n# eef$ r dZY nw xY wd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ni ZdS )    )LOGGERSETTINGSTESTS_RUNNINGclearmlTN)Task__version__Debug Samplestitlereturnc                    ddl }t          j                    x}r| D ]}|                                r|                    d|j                  }|r't          |                                d                   nd}|                                	                    ||j        
                    |                                d          t          |          |           dS dS )zLog 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          h/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/utils/callbacks/clearml.py_log_debug_samplesr"      s     III """t  	 	Axxzz YY~qv6635<C		A///1	!!..rxxzz2(F(FSVWXSYSYen /    	 	    	plot_pathc                 J   ddl m} ddlm} |                    |          }|                                }|                    g dddg g           }|                    |           t          j	                    
                                                    | d|d           dS )	zLog an image as a plot in the plot section of ClearML.

    Args:
        title (str): The title of the plot.
        plot_path (str | Path): 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;   $   s     %$$$$$######
,,y
!
!C
**,,C	lllE&TV	W	WBIIcNNN""$$==Bsu >     r#   c           
         	 t          j                    x}r7ddlm} ddlm} |                    d           |                    d           nHt          j        | j        j	        pd| j        j
        dgddddd	          }t          j        d
           |                    t          | j                  dd           dS # t          $ r"}t          j        d|            Y d}~dS d}~ww xY w)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   ignore_remote_overrideszGClearML 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_startrV   8   sG   f$&&&4 	 TSSSSSIIIIII33D99911$77779$\1B]!,+#_#(49(O(O  D N_   	T',''iQUVVVVV f f fdabddeeeeeeeeefs   B>C 
C.C))C.c                    t          j                    x}r| j        dk    r5t          t	          | j                            d                    d           |                     | j        d          	                                D ]5\  }}|
                                                    d||| j                   6| j        	                                D ]7\  }}|
                                                    d||| j                   6dS dS )	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_scalarr\   )rT   r   kvs       r!   on_train_epoch_endrg   U   s    """t Q=Avg&6&;&;<N&O&OPPRZ[[[,,W]7,KKQQSS 	T 	TDAqOO++GQW]+SSSSJ$$&& 	Q 	QDAqOO++D!Q'-+PPPPQ Q	Q 	Qr#   c                 .   t          j                    x}r|                                                    dd| j        | j                   | j                                        D ]P\  }}|                    d          d         }|                                                    |||| j                   Q| j        dk    rSddl	m
}  ||                                           D ]1\  }}|                                                    ||           .dS dS dS )zFReport model information and metrics to logger at the end of an epoch.z
Epoch Time)r
   r   valuer   /r   r[   )model_info_for_loggersN)r   r   r   rd   
epoch_timer]   metricsrc   splitultralytics.utils.torch_utilsrk   report_single_value)rT   r   re   rf   r
   rk   s         r!   on_fit_epoch_endrq   b   s;    """t <''|7;MY`Yf 	( 	
 	
 	
 O))++ 	R 	RDAqGGCLLOEOO++E1a7=+QQQQ=ALLLLLL..w77==?? < <1!!55a;;;;< < < <r#   c                     t          j                    r7t          t          | j                            d                    d           dS dS )z8Log validation results including labels and predictions.zval*.jpg
ValidationN)r   r   r"   r^   r_   r`   )	validators    r!   
on_val_endru   s   sO     V6)"4"9"9*"E"EFFUUUUUV Vr#   c                    t          j                    x}rg | j                                        | j        j                                        D ]!}d|j        vrt          |j        |           "| j        j        j	        
                                D ]-\  }}|                                                    ||           .|                    t          | j                  | j        j        d           dS dS )z<Log final model and training results on training completion.batch)r
   r$   F)
model_path
model_nameauto_delete_fileN)r   r   plotskeysrt   r   r;   stemrm   results_dictrc   r   rp   update_output_modelr   bestrN   )rT   r   r   re   rf   s        r!   on_train_endr   z   s     """t 	uI7=%%''I'*;*A*F*F*H*HI 	5 	5Aaf$$!4444%-:@@BB 	8 	8DAqOO11!Q7777  C,=,=',J[ns ttttt	u 	ur#   )rV   rg   rq   ru   r   )r	   )r   N)ultralytics.utilsr   r   r   r   r   hasattrImportErrorAssertionErrorr   r"   r;   rV   rg   rq   ru   r   	callbacks r#   r!   <module>r      s   > = = = = = = = = =	I$&&&&NNN77M******^$   GGG S t    &S S T    (f f f f:
Q 
Q 
Q 
Q< < < <"V V V Vu u u u, %>0, $   
 
		s   (5 	A A