§
    à©ºjM#  ã                   ó~   — d dl Z d dlZddlmZ ddlmZmZmZ ddl	m
Z
  e j        e¦  «        Z G d„ de
¦  «        ZdS )	é    Né   )ÚCOCOeval_fasteré   )Úplot_ced_metricÚplot_f1_confidenceÚplot_pre_rec)Ú	ExtraEvalc                   óö   — e Zd Zdedee         fd„Z	 	 	 ddee         dz  dedz  dedz  fd	„Z	 	 	 ddee         dz  dedz  dedz  fd
„Z	dde
dee         fd„Z	 	 	 ddee         dz  dedz  dedz  fd„ZdS )ÚCurvesÚlabelÚreturnc                 óò  — | j         €
J d¦   «         ‚g }| j        r›t          t          | j         d         j        d         ¦  «        ¦  «        }t          | d¦  «        r-| j        �&| j        j        rt          | j        j        ¦  «        }n1t          | j	        j
                             ¦   «         ¦  «        }ndg}g }|D �]¸}| j        r||         n|}d|› d|› d	�}t          |¦  «        d
k    rd}| j         d         dd…dd…|dd…dd…f                              ¦   «         }t          j        | j        ¦  «                             ¦   «         }	| j         d         dd…dd…|dd…dd…f                              ¦   «         }
t#          t          |	¦  «        t          |¦  «        t          |
¦  «        ¦  «        }|	d|…         }	|d|…         }|
d|…         }
|dk    }t          j        |¦  «        st&                               d|¦  «         �ŒN|	|         }	||         }|
|         }
t+          t-          j        |	|¦  «        d¦  «        }|                     t3          |	||› d|d›�||
||¬¦  «        ¦  «         �Œº|S )aR  Build the curve for a given label.

        Args:
            label (str): The label to build the curve for.

        Returns:
            List[dict]: A list of dictionaries containing
                the curve data for each category.

        Raises:
            AssertionError: If self.eval is None (evaluate() was not called).
        NúRun first self.evaluate()Ú	precisionr   Úparamsr   ú[ú=z] r   Ú Úscoreséÿÿÿÿz8Skipping category %s: precision contains no valid valuesé   zauc: z.3f)Úrecall_listÚprecision_listÚnamer   r   ÚaucÚcategory_id)ÚevalÚuseCatsÚlistÚrangeÚshapeÚhasattrr   ÚcatIdsÚsortedÚcocoGtÚcatsÚkeysÚlenÚravelÚnpÚasarrayÚrecThrsÚminÚanyÚloggerÚwarningÚroundr   Úcalc_aucÚappendÚdict)Úselfr   ÚcurveÚcat_idsÚreal_category_idsÚcategory_indexr   Ú_labelr   r   r   Úpoint_countÚvalidr   s                 úm/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/faster_coco_eval/extra/curves.pyÚbuild_curvezCurves.build_curve   s°  € ð ŒyÐ$Ð$Ð&AÑ$Ô$Ð$àˆàŒ<ð 	#Ý�5 ¤¨;Ô!7Ô!=¸aÔ!@ÑAÔAÑBÔBˆGÝ�t˜XÑ&Ô&ð D¨4¬;Ð+BÀtÄ{ÔGYÐ+BÝ$(¨¬Ô);Ñ$<Ô$<Ð!Ð!å$*¨4¬;Ô+;×+@Ò+@Ñ+BÔ+BÑ$CÔ$CÐ!Ð!à�cˆGØ "Ðà%ð !	ñ !	ˆNØ?C¼|Ð_Ð+¨NÔ;Ð;ÐQ_ˆKØ0˜Ð0Ð0 Ð0Ð0Ð0ˆFÝ�7‰|Œ|˜qÒ Ð Ø�à!œY {Ô3°A°A°A°q°q°q¸.È!È!È!ÈQÈQÈQÐ4NÔO×UÒUÑWÔWˆNÝœ* T¤\Ñ2Ô2×8Ò8Ñ:Ô:ˆKØ”Y˜xÔ(¨¨¨¨A¨A¨A¨~¸q¸q¸qÀ!À!À!Ð)CÔD×JÒJÑLÔLˆFÝ�c +Ñ.Ô.µ°NÑ0CÔ0CÅSÈÁ[Ä[ÑQÔQˆKØ% l { lÔ3ˆKØ+¨L¨[¨LÔ9ˆNØ˜L˜[˜LÔ)ˆFØ" RÒ'ˆEÝ”6˜%‘=”=ð Ý—’ÐYÐ[fÑgÔgÐgÙà% eÔ,ˆKØ+¨EÔ2ˆNØ˜E”]ˆFÝ�Ô0°¸nÑMÔMÈqÑQÔQˆCà�LŠLÝØ +Ø#1Ø"Ð2Ð2¨Ð2Ð2Ð2Ø Ø!ØØ +ðñ ô ñ
ô 
ð 
ñ 
ð ˆó    Nr   FÚcurvesÚ
return_figc                 óR   — |€|                       |¦  «        }t          ||¬¦  «        S )a	  Plot the precision-recall curve.

        Args:
            curves (Optional[List[dict]], optional): List of curves to plot.
                If None, it will build the curves. Defaults to None.
            label (Optional[str], optional): Label for the curves. Defaults to "category_id".
            return_fig (Optional[bool], optional): Return the figure object. Defaults to False.

        Returns:
            plotly.graph_objs._figure.Figure or None: The figure object if return_fig is True, otherwise None.
        N©rA   )r>   r   ©r5   r@   r   rA   s       r=   r   zCurves.plot_pre_recM   s/   € ð" ˆ>Ø×%Ò% eÑ,Ô,ˆFå˜F¨zÐ:Ñ:Ô:Ð:r?   c                 óR   — |€|                       |¦  «        }t          ||¬¦  «        S )a  Plot the F1 confidence curve.

        Args:
            curves (Optional[List[dict]], optional): List of curves to plot.
                If None, it will build the curves. Defaults to None.
            label (Optional[str], optional): Label for the curves. Defaults to "category_id".
            return_fig (Optional[bool], optional): Return the figure object. Defaults to False.

        Returns:
            plotly.graph_objs._figure.Figure or None: The figure object if return_fig is True, otherwise None.
        NrC   )r>   r   rD   s       r=   r   zCurves.plot_f1_confidencec   s/   € ð" ˆ>Ø×%Ò% eÑ,Ô,ˆFå! &°ZÐ@Ñ@Ô@Ð@r?   éè  Ú	mae_countc                 óp  — | j         €
J d¦   «         ‚g }| j        j                             ¦   «         D �]\  }}g i |dœ}| j                             |g¬¦  «        D �]ü}| j        j        |         }|                     dd¦  «        �rÐ|                     dd¦  «        �r¹| j        j        |d                  }| j        dk    �r}t          j
        |d         ¦  «                             d	d
¦  «        }	t          j
        |d         ¦  «                             d	d
¦  «        }
g |d<   t          |d         ¦  «        D ]Æ\  }}|d                              t          j        t          j        t          j        |	|dd…f         |
|dd…f         ¦  «        ¦  «        ¦  «        ¦  «         |d                              |¦  «        €dg i|d         |<   |d         |         d                              |d         |         ¦  «         ŒÇt          j        |d         ¦  «        |d<   |d                              |d         ¦  «         �Œät#          d| j        › d�¦  «        ‚�Œþt%          |d         ¦  «        dk    r�ŒAdt&          dt(          dt*          fd„} ||d         |¦  «        }|d         |d         dœ|d         d<   t          |d         ¦  «        D ]Q\  }} ||d         |         d         |¦  «        }|d         |d         |         d<   |d         |d         |         d<   ŒR|                     |¦  «         �Œ|S )añ  Build the CED (Cumulative Error Distribution) curve for all
        categories.

        Args:
            mae_count (int, optional): Number of points to use for the CED curve. Defaults to 1000.

        Returns:
            List[dict]: List of dictionaries containing CED curve data for each category.

        Raises:
            AssertionError: If self.eval is None (evaluate() was not called).
            ValueError: If the iouType is not 'keypoints' (other types are not supported).
        Nr   )Úall_maeÚmaeÚcategory)r7   Ú	keypointsFÚmatchedÚdt_idr   é   Úmae_keypointsr   rJ   rI   znot supported iouType z for CEDr   ÚxÚcountr   c                 ó¤  — t          j        | ¦  «        } t          j        | ¦  «        }t          j        | d¦  «        }dgdgdœ}t	          ||z   |                      ¦   «         ¦  «        }|                      ¦   «         |k     ryt          j        |                      ¦   «         ||¦  «        D ]P}| |k     }|d                              |                     ¦   «         ¦  «         |d                              |¦  «         ŒQ|d                              t          | ¦  «        ¦  «         |d                              |                      ¦   «         ¦  «         |S )a  Create the CED curve data.

                Args:
                    x (list): List of MAE values.
                    count (int): Number of points for the curve.

                Returns:
                    dict: Dictionary containing 'x' and 'y' list for the curve.
                éK   r   ©rQ   ÚyrV   rQ   )
r*   ÚarrayÚmedianÚ
percentiler-   ÚmaxÚlinspacer3   Úsumr(   )rQ   rR   Ú_medianÚ_q3ÚresultÚcurve_limitÚvalÚ_masks           r=   Úcreate_curvez,Curves.build_ced_curve.<locals>.create_curve¯   s!  € õ ”H˜Q‘K”K�Ýœ) A™,œ,�Ý”m A rÑ*Ô*�à˜Ø˜ðð �õ
 " '¨C¡-°·²±´Ñ9Ô9�Ø—5’5‘7”7˜[Ò(Ð(Ý!œ{¨1¯5ª5©7¬7°KÀÑGÔGð 0ð 0˜Ø ! C¢˜Ø˜sœ×*Ò*¨5¯9ª9©;¬;Ñ7Ô7Ð7Ø˜sœ×*Ò*¨3Ñ/Ô/Ð/Ð/à�s”×"Ò"¥3 q¡6¤6Ñ*Ô*Ð*Ø�s”×"Ò" 1§5¢5¡7¤7Ñ+Ô+Ð+Ø�r?   rV   rU   ÚMEAN)r   r%   r&   ÚitemsÚget_ann_idsÚannsÚgetÚcocoDtÚiouTyper*   rW   ÚreshapeÚ	enumerater3   ÚmeanÚabsÚsubtractÚ
ValueErrorr(   r   Úintr4   )r5   rG   r@   r   rK   Ú_curveÚann_idÚgt_annÚdt_annÚgt_xyvÚdt_xyvÚ_idÚkp_namerc   Ú
all_resultÚ_results                   r=   Úbuild_ced_curvezCurves.build_ced_curvey   st  € ð ŒyÐ$Ð$Ð&AÑ$Ô$Ð$àˆØ%)¤[Ô%5×%;Ò%;Ñ%=Ô%=ð M	"ñ M	"Ñ!ˆK˜àØØ$ðð ˆFð
 œ+×1Ò1¸;¸-Ð1ÑHÔHð Zñ Z�ØœÔ)¨&Ô1�Ø—:’:˜k¨5Ñ1Ô1ñ Z°f·j²jÀÈEÑ6RÔ6Rñ ZØ!œ[Ô-¨f°W¬oÔ>�Fà”| {Ò2Ñ2Ý!#¤¨&°Ô*=Ñ!>Ô!>×!FÒ!FÀrÈ1Ñ!MÔ!M˜Ý!#¤¨&°Ô*=Ñ!>Ô!>×!FÒ!FÀrÈ1Ñ!MÔ!M˜à24˜˜Ñ/Ý,5°h¸{Ô6KÑ,LÔ,Lð 
cð 
c™L˜C Ø" ?Ô3×:Ò:Ý "¤­¬­r¬{¸6À#ÀrÈÀrÀ'¼?ÈFÐSVÐXZÐYZÐXZÐSZÌOÑ/\Ô/\Ñ(]Ô(]Ñ ^Ô ^ñô ð ð  & eœ}×0Ò0°Ñ9Ô9ÐAà$-¨rð:"  u¤¨gÑ 6ð # 5œM¨'Ô2°9Ô=×DÒDÀVÈOÔE\Ð]`ÔEaÑbÔbÐbÐbå(*¬°°Ô0GÑ(HÔ(H˜˜u™Ø˜yÔ)×0Ò0°¸´Ñ?Ô?Ð?Ñ?õ )Ð)XÀ$Ä,Ð)XÐ)XÐ)XÑYÔYÐYùå�6˜)Ô$Ñ%Ô%¨Ò*Ð*Ùð¥ð ­Sð µTð ð ð ð ð: &˜ f¨YÔ&7¸ÑCÔCˆJà ”_Ø ”_ð%ð %ˆF�5ŒM˜&Ñ!õ
 !*¨(°;Ô*?Ñ @Ô @ð ;ð ;‘��WØ&˜, v¨e¤}°WÔ'=¸iÔ'HÈ)ÑTÔT�Ø.5°c¬l��u”˜gÔ& sÑ+Ø.5°c¬l��u”˜gÔ& sÑ+Ð+à�MŠM˜&Ñ!Ô!Ð!Ñ!Øˆr?   TÚ	normalizec                 óR   — |€|                       ¦   «         }t          |||¬¦  «        S )a  Plot the CED metric curve.

        Args:
            curves (Optional[List[dict]], optional): List of curves to plot.
                If None, will build the curves. Defaults to None.
            normalize (Optional[bool], optional): Whether to normalize the curve. Defaults to True.
            return_fig (Optional[bool], optional): Return the figure object. Defaults to False.

        Returns:
            plotly.graph_objs._figure.Figure or None: The figure object if return_fig is True, otherwise None.
        N)r}   rA   )r|   r   )r5   r@   r}   rA   s       r=   r   zCurves.plot_ced_metricÚ   s/   € ð" ˆ>Ø×)Ò)Ñ+Ô+ˆFå˜v°ÀzÐRÑRÔRÐRr?   )Nr   F)rF   )NTF)Ú__name__Ú
__module__Ú__qualname__Ústrr   r4   r>   Úboolr   r   rq   r|   r   © r?   r=   r   r      ss  € € € € € ð> ð >¨¨d¬ð >ð >ð >ð >ðD %)Ø)Ø"'ð	;ð ;à�T”
˜TÑ!ð;ð �T‰zð;ð ˜4‘Kð	;ð ;ð ;ð ;ð0 %)Ø)Ø"'ð	Að Aà�T”
˜TÑ!ðAð �T‰zðAð ˜4‘Kð	Að Að Að Að,_ð _¨ð _¸¸T¼
ð _ð _ð _ð _ðF %)Ø!%Ø"'ð	Sð Sà�T”
˜TÑ!ðSð ˜$‘;ðSð ˜4‘Kð	Sð Sð Sð Sð Sð Sr?   r   )ÚloggingÚnumpyr*   Úcorer   Údrawr   r   r   Úextrar	   Ú	getLoggerr   r/   r   r„   r?   r=   ú<module>r‹      s¶   ðØ €€€à Ð Ð Ð à "Ð "Ð "Ð "Ð "Ð "Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ Ð Ð Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ðbSð bSð bSð bSð bSˆYñ bSô bSð bSð bSð bSr?   