§
    l¬¸j  ã                   óÞ   — d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
  e	d¦  «        Z	 ddlZ eed¦  «        sJ ‚n# eef$ r dZY nw xY wdedefd	„Zd
„ Zd„ Zd„ Zd„ Zd„ Zereeeedœni ZdS )aó  
MLflow Logging for Ultralytics YOLO.

This module enables MLflow logging for Ultralytics YOLO. It logs metrics, parameters, and model artifacts.
For setting up, a tracking URI should be specified. The logging can be customized using environment variables.

Commands:
    1. To set a project name:
        `export MLFLOW_EXPERIMENT_NAME=<your_experiment_name>` or use the project=<project> argument

    2. To set a run name:
        `export MLFLOW_RUN=<your_run_name>` or use the name=<name> argument

    3. To start a local MLflow server:
        mlflow server --backend-store-uri runs/mlflow
       It will by default start a local server at http://127.0.0.1:5000.
       To specify a different URI, set the MLFLOW_TRACKING_URI environment variable.

é    N)ÚPath)ÚLOGGERÚRUNS_DIRÚSETTINGSÚTESTS_RUNNINGÚcolorstrÚenv_boolzMLflow: Ú__version__ÚxÚreturnc                 ó>   — d„ |                       ¦   «         D ¦   «         S )zQSanitize dictionary keys by removing parentheses and converting values to floats.c                 ó„   — i | ]=\  }}|                      d d¦  «                              dd¦  «        t          |¦  «        “Œ>S )ú(Ú ú))ÚreplaceÚfloat)Ú.0ÚkÚvs      úr/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/utils/callbacks/mlflow.pyú
<dictcomp>z!sanitize_dict.<locals>.<dictcomp>'   sB   € ÐPÐPÐP¹d¸aÀˆA�IŠI�c˜2ÑÔ×&Ò& s¨BÑ/Ô/µ°q±´ÐPÐPÐPó    )Úitems)r   s    r   Úsanitize_dictr   %   s   € àPÐPÀaÇgÂgÁiÄiÐPÑPÔPÐPr   c                 óV  — t           rt          d         durdS t          r$dt          j                             dd¦  «        vrdS t          j                             d¦  «        pt          t          dz  ¦  «        }t          j	        t          › d|› �¦  «         t          j                             d	¦  «        p| j        j        pd
}t          j                             d¦  «        p| j        j        }d| _        d| _        	 t          j        |¦  «         t          j        |¦  «         t          j        ¦   «          t          j        ¦   «         }|€t          j        |¬¦  «        }d| _        t          j        t          › d|j        j        › d|› �¦  «         t/          |¦  «                             ¦   «         rt          j        t          › d|› d�¦  «         t          j        t          › d�¦  «         t          j        t5          | j        ¦  «        ¦  «         d| _        dS # t6          $ r}}t          j        t          › d|› �¦  «         t          j        t          › d�¦  «         | j        r%	 t          j        ¦   «          n# t6          $ r Y nw xY wY d}~dS Y d}~dS Y d}~dS d}~ww xY w)aÑ  Log training parameters to MLflow at the end of the pretraining routine.

    This function sets up MLflow logging based on environment variables and trainer arguments. It sets the tracking URI,
    experiment name, and run name, then starts the MLflow run if not already active. It finally logs the parameters from
    the trainer.

    Args:
        trainer (ultralytics.engine.trainer.BaseTrainer): The training object with arguments and parameters to log.

    Notes:
        MLFLOW_TRACKING_URI: The URI for MLflow tracking. If not set, defaults to 'runs/mlflow'.
        MLFLOW_EXPERIMENT_NAME: The name of the MLflow experiment. If not set, defaults to trainer.args.project.
        MLFLOW_RUN: The name of the MLflow run. If not set, defaults to trainer.args.name.
        MLFLOW_KEEP_RUN_ACTIVE: Whether to keep the MLflow run active after training ends. Truthy values are
            "1", "true", "yes", "on", "y", "t" (case-insensitive); anything else is False.
    ÚmlflowTNÚtest_mlflowÚPYTEST_CURRENT_TESTr   ÚMLFLOW_TRACKING_URIz tracking uri: ÚMLFLOW_EXPERIMENT_NAMEz/Shared/UltralyticsÚ
MLFLOW_RUNF)Úrun_namezlogging run_id(z) to zFview at http://127.0.0.1:5000 with 'mlflow server --backend-store-uri ú'ú)disable with 'yolo settings mlflow=False'zFailed to initialize: zNot tracking this run)r   r   r   ÚosÚenvironÚgetÚstrr   r   ÚdebugÚPREFIXÚargsÚprojectÚnameÚ_mlflow_activeÚ_mlflow_started_runÚset_tracking_uriÚset_experimentÚautologÚ
active_runÚ	start_runÚinfoÚrun_idr   Úis_dirÚ
log_paramsÚdictÚ	ExceptionÚwarningÚend_run)ÚtrainerÚuriÚexperiment_namer#   r4   Úes         r   Úon_pretrain_routine_endrB   *   sÂ  € õ& ð •X˜hÔ'¨tÐ3Ð3ØˆÝð ˜­b¬j¯nªnÐ=RÐTVÑ.WÔ.WÐWÐWØˆå
Œ*�.Š.Ð.Ñ
/Ô
/Ð
Kµ3µxÀ(Ñ7JÑ3KÔ3K€CÝ
„L•FÐ0Ð0¨3Ð0Ð0Ñ1Ô1Ð1õ ”j—n’nÐ%=Ñ>Ô>ÐoÀ'Ä,ÔBVÐoÐZo€OÝŒz�~Š~˜lÑ+Ô+Ð@¨w¬|Ô/@€Hà"€GÔØ"'€GÔðÝÔ Ñ$Ô$Ð$ÝÔ˜oÑ.Ô.Ð.ÝŒÑÔÐÝÔ&Ñ(Ô(ˆ
ØÐÝÔ)°8Ð<Ñ<Ô<ˆJØ*.ˆGÔ'ÝŒ•vÐPÐP¨j¬oÔ.DÐPÐPÈ3ÐPÐPÑQÔQÐQÝ�‰9Œ9×ÒÑÔð 	qÝŒK�6ÐoÐoÐilÐoÐoÐoÑpÔpÐpÝŒ•vÐHÐHÐHÑIÔIÐIÝÔ�$˜wœ|Ñ,Ô,Ñ-Ô-Ð-Ø!%ˆÔÐÐøÝð ð ð ÝŒ�&Ð;Ð;¸Ð;Ð;Ñ<Ô<Ð<ÝŒ�&Ð7Ð7Ð7Ñ8Ô8Ð8ØÔ&ð 	ðÝ”Ñ Ô Ð Ð øÝð ð ð Ø�ðøøøð	ð 	ð 	ð 	ð 	ð 	à Ð Ð Ð Ð Ð à�����øøøøðøøøs>   Ã?D H! È!
J(È+AJ#É-JÊ J#Ê
JÊJ#ÊJÊJ#Ê#J(c                 ó¸   — 	 t          j        || j        ¬¦  «         dS # t          $ r0}t	          j        t          › d|› �¦  «         d| _        Y d}~dS d}~ww xY w)z_Log metrics to MLflow, disabling tracking for this run on failure so it never crashes training.)ÚmetricsÚstepz8metric logging failed, disabling tracking for this run: FN)r   Úlog_metricsÚepochr;   r   r<   r+   r/   )r>   rD   rA   s      r   Ú_log_metricsrH   c   s}   € ð'ÝÔ 7°´Ð?Ñ?Ô?Ð?Ð?Ð?øÝð 'ð 'ð 'ÝŒ�&Ð]Ð]ÐZ[Ð]Ð]Ñ^Ô^Ð^Ø!&ˆÔÐÐÐÐÐÐøøøøð'øøøs   ‚ Ÿ
A©%AÁAc           
      óØ   — t           r`t          | dd¦  «        rQt          | i t          | j        ¦  «        ¥t          |                      | j        d¬¦  «        ¦  «        ¥¦  «         dS dS dS )z>Log training metrics at the end of each train epoch to MLflow.r/   FÚtrain)ÚprefixN)r   ÚgetattrrH   r   ÚlrÚlabel_loss_itemsÚtloss©r>   s    r   Úon_train_epoch_endrQ   l   s�   € åð 
•'˜'Ð#3°UÑ;Ô;ð 
ÝØðÝ ¤
Ñ+Ô+ðå × 8Ò 8¸¼ÈwÐ 8Ñ WÔ WÑXÔXðñ	
ô 	
ð 	
ð 	
ð 	
ð
ð 
ð 
ð 
r   c                 ó‚   — t           r5t          | dd¦  «        r&t          | t          | j        ¦  «        ¦  «         dS dS dS )z<Log training metrics at the end of each fit epoch to MLflow.r/   FN)r   rL   rH   r   rD   rP   s    r   Úon_fit_epoch_endrS   x   sR   € åð >•'˜'Ð#3°UÑ;Ô;ð >Ý�W�m¨G¬OÑ<Ô<Ñ=Ô=Ð=Ð=Ð=ð>ð >ð >ð >r   c                 óþ  — t           sdS t          | dd¦  «        rá	 t          j        t          | j        j        ¦  «        ¦  «         | j                             d¦  «        D ],}|j        dv r!t          j        t          |¦  «        ¦  «         Œ-t          j
        t          › dt          j        ¦   «         › dt          › d�¦  «         n5# t          $ r(}t          j        t          › d	|› �¦  «         Y d}~nd}~ww xY wt          | d
d¦  «        rpt          d¦  «        rt          j
        t          › d�¦  «         dS 	 t          j        ¦   «          t          j        t          › d�¦  «         dS # t          $ r Y dS w xY wdS )zRLog model artifacts at the end of training and close any run this callback opened.Nr/   FÚ*>   ú.ptú.csvú.jpgú.pngú.yamlzresults logged to ú
r%   zfailed to log artifacts: r0   ÚMLFLOW_KEEP_RUN_ACTIVEzCmlflow run still alive, remember to close it using mlflow.end_run()zmlflow run ended)r   rL   Úlog_artifactr)   ÚbestÚparentÚsave_dirÚglobÚsuffixr   r6   r+   Úget_tracking_urir;   r<   r	   r=   r*   )r>   ÚfrA   s      r   Úon_train_endre   ~   sÂ  € åð ØˆÝˆwÐ(¨%Ñ0Ô0ð 
Dð		DÝÔ¥ G¤LÔ$7Ñ 8Ô 8Ñ9Ô9Ð9ØÔ%×*Ò*¨3Ñ/Ô/ð 0ð 0�Ø”8ÐGÐGÐGÝÔ'­¨A©¬Ñ/Ô/Ð/øÝŒKÝÐ{Ð{­VÔ-DÑ-FÔ-FÐ{Ð{Í&Ð{Ð{Ð{ñô ð ð øõ ð 	Dð 	Dð 	DÝŒN�fÐBÐB¸qÐBÐBÑCÔCÐCÐCÐCÐCÐCÐCøøøøð	DøøøåˆwÐ-¨uÑ5Ô5ð ÝÐ,Ñ-Ô-ð 	ÝŒK�6ÐfÐfÐfÑgÔgÐgÐgÐgðÝ”Ñ Ô Ð Ý”¥Ð8Ð8Ð8Ñ9Ô9Ð9Ð9Ð9øÝð ð ð Ø��ðøøøðð s*   œB*C Ã
C9ÃC4Ã4C9Ä;/E, Å,
E:Å9E:)rB   rQ   rS   re   )Ú__doc__r&   Úpathlibr   Úultralytics.utilsr   r   r   r   r   r	   r+   r   ÚhasattrÚImportErrorÚAssertionErrorr:   r   rB   rH   rQ   rS   re   Ú	callbacks© r   r   ú<module>rn      se  ððð ð( 
€	€	€	Ø Ð Ð Ð Ð Ð à [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [à	ˆ�*Ñ	Ô	€ðØ€M€M€Màˆ7�6˜=Ñ)Ô)Ð)Ð)Ð)Ð)øØ�^Ð$ð ð ð Ø€F€F€FðøøøðQ�Tð Q˜dð Qð Qð Qð Qð
6ð 6ð 6ðr'ð 'ð 'ð	
ð 	
ð 	
ð>ð >ð >ðð ð ðB ðØ#:Ø0Ø,Ø$ð	ð ð ð 
ð 
€	€	s   ©< ¼	AÁA