§
    eznij  ã                   óî   — 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 ‚d dlZ	d dl
Z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                 óÆ   — t          j        ||| dœ¦  «                             d¦  «        }ddddœ}|||dœ}t          j        dt          j        |¬	¦  «        ||¬
¦  «        S )a±  
    Create and log a custom metric visualization to wandb.plot.pr_curve.

    This function crafts a custom metric visualization that mimics the behavior of wandb's default 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; defaults to 'Precision Recall Curve'.
        x_title (str, optional): Label for the x-axis; defaults to 'Recall'.
        y_title (str, optional): Label for the y-axis; defaults to 'Precision'.

    Returns:
        (wandb.Object): A wandb object suitable for logging, showcasing the crafted metric visualization.
    )ÚclassÚyÚxé   r   r   r   )r   r   r   )Útitlezx-axis-titlezy-axis-titlezwandb/area-under-curve/v0)Ú	dataframe)ÚfieldsÚstring_fields)ÚpdÚ	DataFrameÚroundÚwbÚ
plot_tableÚTable)	r   r   Úclassesr   Úx_titleÚy_titleÚdfr   r   s	            ú~/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/utils/callbacks/wb.pyÚ_custom_tabler      s{   € õ$ 
Œ ¨a°aÐ8Ð8Ñ	9Ô	9×	?Ò	?ÀÑ	BÔ	B€BØ˜S¨7Ð3Ð3€FØ#°WÈgÐVÐV€MÝŒ=Ð4Ýœ¨BÐ/Ñ/Ô/Ø &Ø'4ð6ñ 6ô 6ð 6ó    úprecision-recalléd   Fc	                 ó¨  — |€g }t          j        | d         | d         |¦  «                             d¦  «        }	|	                     ¦   «         }
t          j        |	| t          j        |d¬¦  «        ¦  «                             d¦  «                             ¦   «         }|rwt          j        t          t          |
|¦  «        ¦  «        ||g¬¦  «        }t          j
                             |t          j                             ||||¬¦  «        i¦  «         dS d	gt          |
¦  «        z  }t          |¦  «        D ]o\  }}|
                     |	¦  «         |                     t          j        |	| |¦  «        ¦  «         |                     ||         gt          |	¦  «        z  ¦  «         Œpt          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 CxN, where C represents the number of classes.
        names (list, optional): Names of the classes corresponding to the y-axis data; length C. Defaults to an empty list.
        id (str, optional): Unique identifier for the logged data in wandb. Defaults to 'precision-recall'.
        title (str, optional): Title for the visualization plot. Defaults to 'Precision Recall Curve'.
        x_title (str, optional): Label for the x-axis. Defaults to 'Recall'.
        y_title (str, optional): Label for the y-axis. Defaults to 'Precision'.
        num_x (int, optional): Number of interpolated data points for visualization. Defaults to 100.
        only_mean (bool, optional): Flag to indicate if only the mean curve should be plotted. Defaults to True.

    Note:
        The function leverages the '_custom_table' function to generate the actual visualization.
    Nr   éÿÿÿÿé   )Úaxisr   )ÚdataÚcolumns)r   ÚmeanF)Úcommit)ÚnpÚlinspacer   ÚtolistÚinterpr)   r   r   ÚlistÚzipÚrunÚlogÚplotÚlineÚlenÚ	enumerateÚextendr   )r   r   ÚnamesÚidr   r   r   Únum_xÚ	only_meanÚx_newÚx_logÚy_logÚtabler   ÚiÚyis                   r   Ú_plot_curverB   1   s¡  € ð< €}ØˆÝŒK˜˜!œ˜a œe UÑ+Ô+×1Ò1°!Ñ4Ô4€Eð �LŠL‰NŒN€EÝŒI�e˜Q¥¤¨°Ð 2Ñ 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           	      ó(  — |                       ¦   «         D ]|\  }}|d         }t                               |¦  «        |k    rQt          j                             |j        t          j        t          |¦  «        ¦  «        i|¬¦  «         |t          |<   Œ}dS )z_Logs plots from the input dictionary if they haven't been logged already at the specified step.Ú	timestamp©ÚstepN)	ÚitemsÚ_processed_plotsÚgetr   r1   r2   ÚstemÚImageÚstr)ÚplotsrF   ÚnameÚparamsrD   s        r   Ú
_log_plotsrP   c   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        pAt          j        | j        j        pd| j        j        t          | j        ¦  «        ¬¦  «         dS  dS )z0Initiate and start project if module is present.ÚYOLOv8)ÚprojectrN   ÚconfigN)r   r1   ÚinitÚargsrS   rN   Úvars©Útrainers    r   Úon_pretrain_routine_startrZ   l   sK   € å„FÐr�bŒg˜gœlÔ2Ð>°hÀWÄ\ÔEVÕ_cÐdkÔdpÑ_qÔ_qÐrÑrÔrÐrÐrÐrÐrÐrÐrr    c                 ój  — t           j                             | j        | j        dz   ¬¦  «         t          | j        | j        dz   ¬¦  «         t          | j        j        | j        dz   ¬¦  «         | j        dk    r8t           j                             t          | ¦  «        | j        dz   ¬¦  «         dS dS )zCLogs training metrics and model information at the end of an epoch.é   rE   r   N)	r   r1   r2   ÚmetricsÚepochrP   rM   Ú	validatorr   rX   s    r   Úon_fit_epoch_endr`   q   s¢   € å„F‡J‚JˆwŒ W¤]°QÑ%6€JÑ7Ô7Ð7ÝˆwŒ} 7¤=°1Ñ#4Ð5Ñ5Ô5Ð5ÝˆwÔ Ô&¨W¬]¸QÑ->Ð?Ñ?Ô?Ð?Ø„}˜ÒÐÝ
Œ�
Š
Õ)¨'Ñ2Ô2¸¼ÈÑ9Jˆ
ÑKÔKÐKÐKÐKð Ðr    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\   rE   N)	r   r1   r2   Úlabel_loss_itemsÚtlossr^   ÚlrrP   rM   rX   s    r   Úon_train_epoch_endrg   z   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   ¬¦  «         t	          j        ddt          j        j        › d�¬¦  «        }| j         	                    ¦   «         r<| 
                    | j        ¦  «         t          j                             |dg¬¦  «         t          | j        j        j        | j        j        j        ¦  «        D ]S\  }}|\  }}}}t!          ||t#          | j        j        j                             ¦   «         ¦  «        d	|› �|||¬
¦  «         ŒTt          j                             ¦   «          dS )z6Save the best model as an artifact at end of training.r\   rE   ÚmodelÚrun_Ú_model)ÚtyperN   Úbest)Úaliaseszcurves/)r8   r9   r   r   r   N)rP   r_   rM   r^   r   ÚArtifactr1   r9   rm   ÚexistsÚadd_fileÚlog_artifactr0   r]   ÚcurvesÚcurves_resultsrB   r/   r8   ÚvaluesÚfinish)rY   ÚartÚ
curve_nameÚcurve_valuesr   r   r   r   s           r   Úon_train_endrz   ‚   sR  € åˆwÔ Ô&¨W¬]¸QÑ->Ð?Ñ?Ô?Ð?ÝˆwŒ} 7¤=°1Ñ#4Ð5Ñ5Ô5Ð5Ý
Œ+˜7Ð)Aµ´´	Ð)AÐ)AÐ)AÐ
BÑ
BÔ
B€CØ„|×ÒÑÔð 3Ø�Š�W”\Ñ"Ô"Ð"Ý
Œ×Ò˜C¨&¨ÐÑ2Ô2Ð2Ý$'¨Ô(9Ô(AÔ(HÈ'ÔJ[ÔJcÔJrÑ$sÔ$sð 

ð 

Ñ ˆ
�LØ!-Ñˆˆ1ˆg�wÝØØÝ�wÔ(Ô0Ô6×=Ò=Ñ?Ô?Ñ@Ô@Ø%˜Ð%Ð%ØØØð	
ñ 	
ô 	
ð 	
ð 	
õ „F‡M‚M�O„O€O€O€Or    )rZ   rg   r`   rz   )r   r	   r
   )Nr!   r   r	   r
   r"   F)Úultralytics.utilsr   r   Úultralytics.utils.torch_utilsr   r   r   ÚhasattrÚnumpyr+   Úpandasr   rH   ÚImportErrorÚAssertionErrorr   rB   rP   rZ   r`   rg   rz   Ú	callbacks© r    r   ú<module>r„      sŽ  ðð 6Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø @Ð @Ð @Ð @Ð @Ð @ðØÐÐÐØ�GÔ Ð$Ð$Ð$Ð$ØÐÐÐàˆ7�2�}Ñ%Ô%Ð%Ð%Ð%àÐÐÐØÐÐÐàÐÐøà�^Ð$ð ð ð Ø	€B€B€Bðøøøð6ð 6ð 6ð 6ð: Ø%Ø.Ø Ø#ØØð/bð /bð /bð /bðd/ð /ð /ðsð sð sð
Lð Lð Lð:ð :ð :ðð ð ð4 &(ð	0Ø!:Ø,Ø(Ø ð	"ð "ð "ð .0ð	 
€	€	s   �,= ½	A	ÁA	