§
    à©ºjŸ"  ã                  ód   — d Z ddlmZ ddlmZ ddlZddlmZ dZ	e G d„ d	¦  «        ¦   «         Z
dS )
z;PlotData: validated data extraction from a COCOeval object.é    )Úannotations)Ú	dataclassNé   )Ú_mask_invalid_precg�íµ ÷Æ°>c                  ó  — e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d3d!„Zd4d$„Zd5d'„Zd6d)„Zd7d-„Z	e
d.d/œd8d1„¦   «         Zd2S )9ÚPlotDataz·Extracted, validated data from a COCOeval object.

    Built via :meth:`from_coco_eval`. All plot functions consume this
    instead of reaching into COCOeval internals directly.
    ÚstrÚ	eval_modeÚiou_typeÚ
provenanceÚboolÚis_benchmark_standardz	list[str]Ú
deviationsúlist[float]Úiou_thresholdsÚarea_labelszdict[str, tuple[float, float]]Úarea_rangesú	list[int]Úmax_detszdict[str, float]Úmetricszdict[str, float] | NoneÚ	per_classú
np.ndarrayÚ	precisionÚ
recall_ptsÚcat_idszdict[int, str]Ú	cat_namesz
list[dict]Úmetric_defsÚversionÚlabelÚreturnÚintc                óL   — || j         v r| j                              |¦  «        ndS )z>Return the area-range axis index for *label*, defaulting to 0.r   )r   Úindex)Úselfr   s     úa/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/hotcoco/plot/data.pyÚarea_idxzPlotData.area_idx2   s+   € à05¸Ô9IÐ0IÐ0IˆtÔ×%Ò% eÑ,Ô,Ð,ÈqÐPó    Úmax_detú
int | Nonec                ó¤   — |�#|| j         v r| j                              |¦  «        S | j                              t          | j         ¦  «        ¦  «        S )u^  Return the max-det axis index, defaulting to the per-image cap.

        The default mirrors ``Params::max_det()`` in Rust â€” the *maximum* entry,
        not the last one. The two agree on the sorted default ``[1, 10, 100]``
        and diverge on unsorted params, where taking the last would plot the
        AR1 slice under the AP label.
        )r   r#   Úmax)r$   r(   s     r%   Úmax_det_idxzPlotData.max_det_idx6   sL   € ð Ð 7¨d¬mÐ#;Ð#;Ø”=×&Ò& wÑ/Ô/Ð/ØŒ}×"Ò"¥3 t¤}Ñ#5Ô#5Ñ6Ô6Ð6r'   ÚtargetÚfloatc                ón   ‡ ‡— t          t          t          ‰ j        ¦  «        ¦  «        ˆ ˆfd„¬¦  «        S )a)  Return the IoU-threshold index closest to *target*, always succeeding.

        The lenient sibling of :meth:`iou_indices`. Use it when any nearby
        threshold answers the question; use ``iou_indices`` when the caller
        named specific thresholds and a near-miss would be a lie.
        c                ó>   •— t          ‰j        |          ‰z
  ¦  «        S ©N)Úabsr   )Úir$   r-   s    €€r%   ú<lambda>z*PlotData.nearest_iou_idx.<locals>.<lambda>I   s   ø€ Å#ÀdÔFYÐZ[ÔF\Ð_eÑFeÑBfÔBf€ r'   )Úkey)ÚminÚrangeÚlenr   )r$   r-   s   ``r%   Únearest_iou_idxzPlotData.nearest_iou_idxB   s9   øø€ õ •5�˜TÔ0Ñ1Ô1Ñ2Ô2Ð8fÐ8fÐ8fÐ8fÐ8fÐgÑgÔgÐgr'   Útargetsc                ó   ‡ — ˆ fd„|D ¦   «         }d„ |                      ¦   «         D ¦   «         }|r%t          d|› dd„ ‰ j        D ¦   «         › d�¦  «        ‚t          d„ |                     ¦   «         D ¦   «         ¦  «        S )a¾  Return grid indices for *targets*, in grid order, or raise.

        Matched within ``_IOU_TOL`` rather than by equality: the grid is built by
        arithmetic and stores 0.90 as 0.8999999999999999, so ``t in targets``
        silently drops a threshold the caller explicitly asked for and draws an
        empty axes. Grid order, not caller order, because callers give the first
        index the primary line's weight and annotation.
        c           	     óp   •‡— i | ]1Š‰t          ˆfd „t          ‰j        ¦  «        D ¦   «         d¦  «        “Œ2S )c              3  óX   •K  — | ]$\  }}t          |‰z
  ¦  «        t          k     ¯ |V — Œ%d S r1   )r2   Ú_IOU_TOL)Ú.0r3   ÚtÚwants      €r%   ú	<genexpr>z2PlotData.iou_indices.<locals>.<dictcomp>.<genexpr>U   s=   øè è € ÐaÐa™d˜a ÍÈAÐPTÉHÉÌÕX`ÒH`ÐH`˜ÐH`ÐH`ÐH`ÐH`ÐaÐar'   N)ÚnextÚ	enumerater   )r?   rA   r$   s    @€r%   ú
<dictcomp>z(PlotData.iou_indices.<locals>.<dictcomp>T   sW   øø€ ð 
ð 
ð 
àð •$ÐaÐaÐaÐa¥i°Ô0CÑ&DÔ&DÐaÑaÔaÐcgÑhÔhð
ð 
ð 
r'   c                ó   — g | ]	\  }}|­|‘Œ
S r1   © )r?   Úwr3   s      r%   ú
<listcomp>z(PlotData.iou_indices.<locals>.<listcomp>X   s   € Ð>Ð>Ð>™˜˜A°A°I�1°I°I°Ir'   zIoU threshold(s) z# are not in this evaluation's grid c                ó.   — g | ]}t          |d ¦  «        ‘ŒS )é   )Úround)r?   r@   s     r%   rI   z(PlotData.iou_indices.<locals>.<listcomp>\   s    € Ð=Ð=Ð= A•E˜!˜Q‘K”KÐ=Ð=Ð=r'   zZ. Pass a threshold the run was accumulated at, or re-run with params.iou_thrs covering it.c              3  ó   K  — | ]}|®|V — Œ	d S r1   rG   )r?   r3   s     r%   rB   z'PlotData.iou_indices.<locals>.<genexpr>_   s"   è è € ÐCÐC˜A°Q°]�a°]°]°]°]ÐCÐCr'   )ÚitemsÚ
ValueErrorr   ÚsortedÚvalues)r$   r:   ÚmatchedÚmissings   `   r%   Úiou_indiceszPlotData.iou_indicesK   sÅ   ø€ ð
ð 
ð 
ð 
àð
ñ 
ô 
ˆð ?Ð> §¢¡¤Ð>Ñ>Ô>ˆØð 	ÝðS Gð Sð SØ=Ð=¨Ô)<Ð=Ñ=Ô=ðSð Sð Sñô ð õ
 ÐCÐC §¢Ñ!1Ô!1ÐCÑCÔCÑCÔCÐCr'   Út_idxÚa_idxÚm_idxc           
     óp   — t          j        t          | j        |dd…dd…||f         ¦  «        d¬¦  «        S )aÅ  Mean precision over categories for one (IoU, area, maxDets) slice.

        Returns one value per recall threshold, length R. The ``-1`` sentinel
        ("not computed for this configuration") is excluded from the mean rather
        than averaged in as a low score, and a recall threshold no category
        reached comes back as NaN.

        The single owner of this reduction on the Python side: `report()`'s
        ``curves`` is the same aggregate computed in Rust, so a chart that is
        parameterized over area or maxDets calls this, and a chart that draws
        the standard slice reads ``curves``. Anything spelling the nanmean
        itself is a third answer to the same question.
        Nr   )Úaxis)ÚnpÚnanmeanr   r   )r$   rU   rV   rW   s       r%   Úmean_precisionzPlotData.mean_precisione   s>   € õ ŒzÕ,¨T¬^¸EÀ1À1À1ÀaÀaÀaÈÐPUÐ<UÔ-VÑWÔWÐ^_Ð`Ñ`Ô`Ð`r'   F©r   ú
'PlotData'c          	     óÈ  — |j         }|€t          d¦  «        ‚|                     |¬¦  «        }|d         }h d£}|d         |vrt          d|d         ›�¦  «        ‚t          j        |d         ¦  «        }|j        d	k    rt          d
|j        › �¦  «        ‚t          |j        j	        ¦  «        }t          |j        j
        ¦  «        }	t          j        |j        j        t          ¬¦  «        }
|
j        d         |j        d         k    r,t          d|
j        d         › d|j        d         › d�¦  «        ‚	 |j                             |	¦  «        }d„ |D ¦   «         }n# t          $ r d„ |	D ¦   «         }Y nw xY w | d$i d|d         “d|d         “d|d         “d|                     ¦   «         “dt          |                     ¦   «         ¦  «        “d|d         “d|“dd„ |d                              ¦   «         D ¦   «         “d|d         “d|d         “d|                     d¦  «        “d|“d|
“d|	“d |“d!t          |                     ¦   «         ¦  «        “d"|d#         “ŽS )%a×  Extract and validate plot data from a COCOeval object.

        Parameters
        ----------
        coco_eval : COCOeval
            Must have ``run()`` called first.
        per_class : bool
            Whether to include per-category AP values. Default False.

        Raises
        ------
        ValueError
            If ``run()`` has not been called, the eval mode is unrecognized,
            or the precision array does not have the expected 5D shape.
        Nz%Call coco_eval.run() before plotting.r]   Úparams>   ÚcocoÚlvisÚ
openimagesr
   zUnknown eval_mode: r   é   z2Expected 5-dimensional precision array, got shape )Údtyper   r   zparams.rec_thrs has z! points but precision axis 1 has u6    â€” accumulate() ran against a different recall grid.c                ó,   — i | ]}|d          |d         “ŒS )ÚidÚnamerG   )r?   Úcs     r%   rE   z+PlotData.from_coco_eval.<locals>.<dictcomp>¨   s"   € Ð:Ð:Ð:°˜˜4œ ! F¤)Ð:Ð:Ð:r'   c                ó.   — i | ]}|t          |¦  «        “ŒS rG   )r	   )r?   Úcids     r%   rE   z+PlotData.from_coco_eval.<locals>.<dictcomp>ª   s    € Ð:Ð:Ð:¨3˜�c #™hœhÐ:Ð:Ð:r'   r   r   r   r   r   r   r   c                ó4   — i | ]\  }}|t          |¦  «        “ŒS rG   )Útuple)r?   ÚkÚvs      r%   rE   z+PlotData.from_coco_eval.<locals>.<dictcomp>¸   s$   € ÐTÐTÐT©¨¨A˜�E !™HœHÐTÐTÐTr'   r   r   r   r   r   r   r   r   Úhotcoco_versionrG   )ÚevalrO   ÚresultsrZ   ÚasarrayÚndimÚshapeÚlistr`   Úarea_rng_lblr   Úrec_thrsr.   Úcoco_gtÚ	load_catsÚ	Exceptionr   Úreference_deviationsrN   Úgetr   )ÚclsÚ	coco_evalr   Ú	eval_dictÚrÚparams_dictÚvalid_modesr   r   r   r   Úcatsr   s                r%   Úfrom_coco_evalzPlotData.from_coco_evaly   s*  € ð" ”Nˆ	ØÐÝÐDÑEÔEÐEà×Ò¨	ÐÑ2Ô2ˆØ˜”kˆà4Ð4Ð4ˆØ�{Ô#¨;Ð6Ð6ÝÐO°;¸{Ô3KÐOÐOÑPÔPÐPå”J˜y¨Ô5Ñ6Ô6ˆ	ØŒ>˜QÒÐÝÐcÐR[ÔRaÐcÐcÑdÔdÐdå˜9Ô+Ô8Ñ9Ô9ˆÝ�yÔ'Ô/Ñ0Ô0ˆõ
 ”Z 	Ô 0Ô 9ÅÐGÑGÔGˆ
ØÔ˜AÔ )¤/°!Ô"4Ò4Ð4Ýð^ zÔ'7¸Ô':ð ^ð ^Ø”? 1Ô%ð^ð ^ð ^ñô ð ð
	;ØÔ$×.Ò.¨wÑ7Ô7ˆDØ:Ð:°TÐ:Ñ:Ô:ˆIˆIøÝð 	;ð 	;ð 	;Ø:Ð:°'Ð:Ñ:Ô:ˆIˆIˆIð	;øøøð ˆsð 
ð 
ð 
Ø! +Ô.Ð.ð
à  Ô,Ð,ð
ð ˜”�ð
ð #,×"AÒ"AÑ"CÔ"CÐ"Cð
õ ˜I×:Ò:Ñ<Ô<Ñ=Ô=Ð=ð
ð 'Ð'7Ô8Ð8ð
ð $˜ð
ð UÐT°¸]Ô1K×1QÒ1QÑ1SÔ1SÐTÑTÔTÐTð
ð ! Ô,Ð,ð
ð �i”L�Lð
ð —e’e˜KÑ(Ô(Ð(ð
ð   �ið!
ð" "�zð#
ð$ �Gð%
ð&  �ið'
õ( ˜Y×2Ò2Ñ4Ô4Ñ5Ô5Ð5ð)
ð* Ð'Ô(Ð(ð+
ð 	
s   Ä9&E  Å E9Å8E9N)r   r	   r    r!   )r(   r)   r    r!   )r-   r.   r    r!   )r:   r   r    r   )rU   r!   rV   r!   rW   r!   r    r   )r   r   r    r^   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r&   r,   r9   rT   r\   Úclassmethodr…   rG   r'   r%   r   r      s�  € € € € € € ðð ð €N€N�NØ€M€M�MØ€O€O�OØÐÐÑØÐÐÑØÐÐÑØÐÐÑØ/Ð/Ð/Ñ/ØÐÐÑØÐÐÑØ&Ð&Ð&Ñ&ØÐÐÑØÐÐÑØÐÐÑØÐÐÑð ÐÐÑØ€L€L�LðQð Qð Qð Qð
7ð 
7ð 
7ð 
7ðhð hð hð hðDð Dð Dð Dð4að að að að( Ø<Að H
ð H
ð H
ð H
ð H
ñ „[ðH
ð H
ð H
r'   r   )r‰   Ú
__future__r   Údataclassesr   ÚnumpyrZ   Úcorer   r>   r   rG   r'   r%   ú<module>r�      sœ   ðØ AÐ Aà "Ð "Ð "Ð "Ð "Ð "à !Ð !Ð !Ð !Ð !Ð !à Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $ð
 €ð ðp
ð p
ð p
ð p
ð p
ñ p
ô p
ñ „ðp
ð p
ð p
r'   