§
    l¬¸j   ã                   óÞ   — d dl mZmZ d dlmZ 	 erJ ‚ed         du sJ ‚d dlZ eed¦  «        sJ ‚i Zn# e	e
f$ r dZY nw xY wdd
„Z	 	 	 	 	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zereeeedœni ZdS )é    )ÚSETTINGSÚTESTS_RUNNING)Úmodel_info_for_loggersÚwandbTNÚ__version__úPrecision Recall CurveÚRecallÚ	Precisionc                 ó~  — ddl }ddlm} |                     ||| dœ¦  «                             |                     ¦   «                              d¦  «        ¦  «        }|                     g d¢¦  «                             ¦   «         }	ddddœ}
|||d	œ}t          j
        d
t          j        |	g d¢¬¦  «        |
|¬¦  «        S )aL  Create and log a custom metric visualization table.

    This function crafts a custom metric visualization that mimics the behavior of the default wandb precision-recall
    curve while allowing for enhanced customization. The visual metric is useful for monitoring model performance across
    different classes.

    Args:
        x (list): Values for the x-axis; expected to have length N.
        y (list): Corresponding values for the y-axis; also expected to have length N.
        classes (list): Labels identifying the class of each point; length N.
        title (str, optional): Title for the plot.
        x_title (str, optional): Label for the x-axis.
        y_title (str, optional): Label for the y-axis.

    Returns:
        (wandb.Object): A wandb object suitable for logging, showcasing the crafted metric visualization.
    r   N)ÚclassÚyÚxé   r   r   r   )r   r   r   )Útitlezx-axis-titlezy-axis-titlezwandb/area-under-curve/v0©ÚdataÚcolumns)ÚfieldsÚstring_fields)ÚpolarsÚpolars.selectorsÚ	selectorsÚ	DataFrameÚwith_columnsÚnumericÚroundÚselectÚrowsÚwbÚ
plot_tableÚTable)r   r   Úclassesr   Úx_titleÚy_titleÚplÚcsÚdfr   r   r   s               ún/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/utils/callbacks/wb.pyÚ_custom_tabler)      sß   € ð$ ÐÐÐØ!Ð!Ð!Ð!Ð!Ð!à	�Š ¨a°aÐ8Ð8Ñ	9Ô	9×	FÒ	FÀrÇzÂzÁ|Ä|×GYÒGYÐZ[ÑG\ÔG\Ñ	]Ô	]€BØ�9Š9Ð(Ð(Ð(Ñ)Ô)×.Ò.Ñ0Ô0€Dà˜S¨7Ð3Ð3€FØ#°WÈgÐVÐV€MÝŒ=Ø#Ý
Œ�dÐ$7Ð$7Ð$7Ð8Ñ8Ô8ØØ#ð	ñ ô ð ó    úprecision-recalléd   Fc	                 ó¸  — ddl }	|€g }|	                     | d         | d         |¦  «                             d¦  «        }
|
                     ¦   «         }|	                     |
| |	                     |d¬¦  «        ¦  «                             d¦  «                             ¦   «         }|rwt          j        t          t          ||¦  «        ¦  «        ||g¬¦  «        }t          j
                             |t          j                             ||||¬¦  «        i¦  «         dS d	gt          |¦  «        z  }t          |¦  «        D ]p\  }}|                     |
¦  «         |                     |	                     |
| |¦  «        ¦  «         |                     ||         gt          |
¦  «        z  ¦  «         Œqt          j        |t#          ||||||¦  «        id
¬¦  «         dS )a<  Log a metric curve visualization.

    This function generates a metric curve based on input data and logs the visualization to wandb. The curve can
    represent aggregated data (mean) or individual class data, depending on the 'only_mean' flag.

    Args:
        x (np.ndarray): Data points for the x-axis with length N.
        y (np.ndarray): Corresponding data points for the y-axis with shape (C, N), where C is the number of classes.
        names (list, optional): Names of the classes corresponding to the y-axis data; length C.
        id (str, optional): Unique identifier for the logged data in wandb.
        title (str, optional): Title for the visualization plot.
        x_title (str, optional): Label for the x-axis.
        y_title (str, optional): Label for the y-axis.
        num_x (int, optional): Number of interpolated data points for visualization.
        only_mean (bool, optional): Flag to indicate if only the mean curve should be plotted.

    Notes:
        The function leverages the '_custom_table' function to generate the actual visualization.
    r   Néÿÿÿÿé   )Úaxisr   r   )r   ÚmeanF)Úcommit)ÚnumpyÚlinspacer   ÚtolistÚinterpr1   r   r!   ÚlistÚzipÚrunÚlogÚplotÚlineÚlenÚ	enumerateÚextendr)   )r   r   ÚnamesÚidr   r#   r$   Únum_xÚ	only_meanÚnpÚx_newÚx_logÚy_logÚtabler"   ÚiÚyis                    r(   Ú_plot_curverK   4   s¶  € ð< ÐÐÐð €}ØˆØ�KŠK˜˜!œ˜a œe UÑ+Ô+×1Ò1°!Ñ4Ô4€Eð �LŠL‰NŒN€EØ�IŠI�e˜Q §¢¨° Ñ 2Ô 2Ñ3Ô3×9Ò9¸!Ñ<Ô<×CÒCÑEÔE€Eàð 	bÝ”�d¥3 u¨eÑ#4Ô#4Ñ5Ô5ÀÈÐ?QÐRÑRÔRˆÝ
Œ�
Š
�E�2œ7Ÿ<š<¨¨w¸Àu˜<ÑMÔMÐNÑOÔOÐOÐOÐOà�(�S ™ZœZÑ'ˆÝ˜q‘\”\ð 	4ð 	4‰EˆAˆrØ�LŠL˜ÑÔÐØ�LŠL˜Ÿš 5¨!¨RÑ0Ô0Ñ1Ô1Ð1Ø�NŠN˜E !œH˜:­¨E©
¬
Ñ2Ñ3Ô3Ð3Ð3Ý
Œ�•M %¨°¸ÀÈÑQÔQÐRÐ[`ÐaÑaÔaÐaÐaÐar*   c           	      óL  — |                       ¦   «                              ¦   «         D ]|\  }}|d         }t                               |¦  «        |k    rQt          j                             |j        t	          j        t          |¦  «        ¦  «        i|¬¦  «         |t          |<   Œ}dS )aç  Log plots to WandB at a specific step if they haven't been logged already.

    This function checks each plot in the input dictionary against previously processed plots and logs new or updated
    plots to WandB at the specified step.

    Args:
        plots (dict): Dictionary of plots to log, where keys are plot names and values are dictionaries containing plot
            metadata including timestamps.
        step (int): The step/epoch at which to log the plots in the WandB run.

    Notes:
        The function uses a shallow copy of the plots dictionary to prevent modification during iteration.
        Plots are identified by their stem name (filename without extension).
        Each plot is logged as a WandB Image object.
    Ú	timestamp©ÚstepN)
ÚcopyÚitemsÚ_processed_plotsÚgetr   r9   r:   ÚstemÚImageÚstr)ÚplotsrO   ÚnameÚparamsrM   s        r(   Ú
_log_plotsrZ   i   s“   € ð  Ÿ
š
™œ×*Ò*Ñ,Ô,ð /ð /‰ˆˆfØ˜;Ô'ˆ	Ý×Ò Ñ%Ô%¨Ò2Ð2ÝŒF�JŠJ˜œ	¥2¤8­C°©I¬IÑ#6Ô#6Ð7¸dˆJÑCÔCÐCØ%.Õ˜TÑ"øð	/ð /r*   c           
      ó  — t           j        �syddlm} ddlm} t          | j        j        ¦  «                             dd¦  «                             dd¦  «        } || j	        ¦  «        dz  d	z  }| j        j
        o|                     ¦   «         }t          j        | j        j        r-t          | j        j        ¦  «                             dd¦  «        nd
|t          | j        ¦  «        |r3|                     ¦   «         j                             dd¦  «        d         nE|dd…         › d|                     ¦   «                              ¦   «                              d¦  «        › �|rdndt          | j	        ¦  «        ¬¦  «         dS dS )z8Initialize and start wandb project if module is present.r   )Údatetime)ÚPathú/ú-ú Ú_r   z
latest-runÚUltralyticsé   Né@   z%Y%m%d_%H%M%SÚallow)ÚprojectrX   ÚconfigrA   ÚresumeÚdir)r   r9   r\   Úpathlibr]   rV   ÚargsrX   ÚreplaceÚsave_dirrh   ÚexistsÚinitrf   ÚvarsÚresolveÚsplitÚnowÚ
astimezoneÚstrftime)Útrainerr\   r]   rX   Ú
latest_runÚresumings         r(   Úon_pretrain_routine_startry   €   s�  € åŒ6ñ 
Ø%Ð%Ð%Ð%Ð%Ð%Ø Ð Ð Ð Ð Ð å�7”<Ô$Ñ%Ô%×-Ò-¨c°3Ñ7Ô7×?Ò?ÀÀSÑIÔIˆØ�T˜'Ô*Ñ+Ô+¨gÑ5¸ÑDˆ
Ø”<Ô&Ð>¨:×+<Ò+<Ñ+>Ô+>ˆÝ
ŒØCJÄ<ÔCWÐj•C˜œÔ,Ñ-Ô-×5Ò5°c¸3Ñ?Ô?Ð?Ð]jØÝ˜œÑ%Ô%àðXˆz×!Ò!Ñ#Ô#Ô(×.Ò.¨s°AÑ6Ô6°qÔ9Ð9à˜˜"˜”IÐWÐW §¢¡¤× 9Ò 9Ñ ;Ô ;× DÒ DÀ_Ñ UÔ UÐWÐWØ&Ð0�7�7¨DÝ�GÔ$Ñ%Ô%ð		
ñ 		
ô 		
ð 		
ð 		
ð 		
ð
ð 
r*   c                 óh  — t          | j        | j        dz   ¬¦  «         t          | j        j        | j        dz   ¬¦  «         | j        dk    r6t          j                             t          | ¦  «        | j        dz   ¬¦  «         t          j                             | j        | j        dz   d¬¦  «         dS )zBLog training metrics and model information at the end of an epoch.é   rN   r   T)rO   r2   N)	rZ   rW   ÚepochÚ	validatorr   r9   r:   r   Úmetrics©rv   s    r(   Úon_fit_epoch_endr€   •   sœ   € åˆwŒ} 7¤=°1Ñ#4Ð5Ñ5Ô5Ð5ÝˆwÔ Ô&¨W¬]¸QÑ->Ð?Ñ?Ô?Ð?Ø„}˜ÒÐÝ
Œ�
Š
Õ)¨'Ñ2Ô2¸¼ÈÑ9Jˆ
ÑKÔKÐKÝ„F‡J‚JˆwŒ W¤]°QÑ%6¸t€JÑDÔDÐDÐDÐDr*   c                 ó>  — t           j                             |                      | j        d¬¦  «        | j        dz   ¬¦  «         t           j                             | j        | j        dz   ¬¦  «         | j        dk    r t          | j        | j        dz   ¬¦  «         dS dS )z>Log metrics and save images at the end of each training epoch.Útrain)Úprefixr{   rN   N)	r   r9   r:   Úlabel_loss_itemsÚtlossr|   ÚlrrZ   rW   r   s    r(   Úon_train_epoch_endr‡   ž   s�   € å„F‡J‚Jˆw×'Ò'¨¬¸gÐ'ÑFÔFÈWÌ]Ð]^ÑM^€JÑ_Ô_Ð_Ý„F‡J‚JˆwŒz ¤°Ñ 1€JÑ2Ô2Ð2Ø„}˜ÒÐÝ�7”= w¤}°qÑ'8Ð9Ñ9Ô9Ð9Ð9Ð9ð Ðr*   c           
      ó(  — t          | j        j        | j        dz   ¬¦  «         t          | j        | j        dz   ¬¦  «         | j        j        r~| j                             ¦   «         ret          j	        ddt          j
        j        › d�¬¦  «        }|                     | j        ¦  «         t          j
                             |dg¬¦  «         | j        j        rœt          | j        j        d	¦  «        r‚t!          | j        j        j        | j        j        j        ¦  «        D ]S\  }}|\  }}}}t'          ||t)          | j        j        j                             ¦   «         ¦  «        d
|› �|||¬¦  «         ŒTt          j
                             ¦   «          dS )zNSave the best model as an artifact and log final plots at the end of training.r{   rN   ÚmodelÚrun_Ú_model)ÚtyperX   Úbest)ÚaliasesÚcurves_resultszcurves/)r@   rA   r   r#   r$   N)rZ   r}   rW   r|   rk   Úsaver�   rn   r   ÚArtifactr9   rA   Úadd_fileÚlog_artifactÚhasattrr~   r8   Úcurvesr�   rK   r7   r@   ÚvaluesÚfinish)rv   ÚartÚ
curve_nameÚcurve_valuesr   r   r#   r$   s           r(   Úon_train_endr›   ¦   sƒ  € åˆwÔ Ô&¨W¬]¸QÑ->Ð?Ñ?Ô?Ð?ÝˆwŒ} 7¤=°1Ñ#4Ð5Ñ5Ô5Ð5Ø„|Ôð 3˜Wœ\×0Ò0Ñ2Ô2ð 3ÝŒk˜wÐ-EµB´F´IÐ-EÐ-EÐ-EÐFÑFÔFˆØ�Š�W”\Ñ"Ô"Ð"Ý
Œ×Ò˜C¨&¨ÐÑ2Ô2Ð2à„|Ôð �g gÔ&7Ô&?ÐAQÑRÔRð Ý(+¨GÔ,=Ô,EÔ,LÈgÔN_ÔNgÔNvÑ(wÔ(wð 
	ð 
	Ñ$ˆJ˜Ø%1Ñ"ˆAˆq�'˜7ÝØØÝ˜7Ô,Ô4Ô:×AÒAÑCÔCÑDÔDØ)˜ZÐ)Ð)Ø ØØðñ ô ð ð õ „F‡M‚M�O„O€O€O€Or*   )ry   r‡   r€   r›   )r   r	   r
   )Nr+   r   r	   r
   r,   F)Úultralytics.utilsr   r   Úultralytics.utils.torch_utilsr   r   r   r”   rR   ÚImportErrorÚAssertionErrorr)   rK   rZ   ry   r€   r‡   r›   Ú	callbacks© r*   r(   ú<module>r¢      st  ðð 6Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø @Ð @Ð @Ð @Ð @Ð @ð	ØÐÐÐØ�GÔ Ð$Ð$Ð$Ð$ØÐÐÐàˆ7�2�}Ñ%Ô%Ð%Ð%Ð%ØÐÐøà�^Ð$ð ð ð Ø	€B€B€Bðøøøðð ð ð ðJ ØØ
"ØØØ
Øð2bð 2bð 2bð 2bðj/ð /ð /ð.
ð 
ð 
ð*Eð Eð Eð:ð :ð :ðð ð ð> 
ðØ%>Ø0Ø,Ø$ð	ð ð ð 
ð 
€	€	s   �$5 µ	AÁ A