§
    ß©ºjz  ã            	      óØ  — U d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m	Z	 ddl
mZ ddlmZmZmZmZmZmZ ddlZdd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( ed         Z)dZ*de+d<   dZ,de+d<   dZ-de+d<   dZ.de+d<    ej/        dd e0 ej1        d¦  «        ¦  «        dz   dej2        ¬¦  «        Z3de+d<    ej/        d d! e0 ej1        d"¦  «        ¦  «        dz   dej2        ¬¦  «        Z4de+d#<   dd$gdd%gd%d&gd&d$ggZ5d'e+d(<   g d)¢Z6d*e+d+<   g d,¢Z7d-e+d.<   dd$gd%d&gd&d$ggZ8d'e+d/<   g d0¢Z9d*e+d1<   d2gZ:d-e+d3<    ej;        g d4¢ej2        ¬5¦  «        d6z  Z<de+d7<    G d8„ d9e¦  «        Z= G d:„ d;¦  «        Z>d<d=d>d?œZ?d@e+dA<   dZ@dBe+dC<   dZAdBe+dD<   dEZBdBe+dF<    G dG„ dH¦  «        ZCeej2                 eDe         z  ZE G dI„ dJe¦  «        ZFdddP„ZGdedV„ZHdfdZ„ZIdgdhd`„ZJdidc„ZKdS )jaY  Pycocotools compatibility surface (bbox / segm / boundary / keypoints).

Implements :class:`PycocotoolsCOCOeval`, a drop-in replacement for
:class:`pycocotools.cocoeval.COCOeval`. Per ADR-0007 this is the
migration tool: downstream eval code that imports
``pycocotools.cocoeval.COCOeval`` runs unchanged once the symbol is
swapped (manually, or via :func:`vernier.adapters.patch_pycocotools`).
The constructor also accepts ``iouType="boundary"`` and a
``dilation_ratio`` kwarg (ADR-0010), mirroring the
``bowenc0221/boundary-iou-api`` oracle's signature, and
``iouType="keypoints"`` (ADR-0012) with ``params.kpt_oks_sigmas``
honored on the params object per pycocotools convention.

The class is named ``PycocotoolsCOCOeval`` so the swap is visible in
tracebacks and ``repr()`` even though it lives behind the ``COCOeval``
alias.

Detections are *held, not copied.* :meth:`PycocotoolsCOCOeval.evaluate`
keeps a reference to the caller's ``cocoDt`` annotation list and hands
it to ADR-0057's list route; the ``json.dumps`` snapshot it replaces is
where the memory this shim used to spend went, so the reference is
deliberate. The consequence is an aliasing window. ``eval`` and
``stats`` are computed during ``evaluate`` / ``accumulate`` and frozen,
but :attr:`~PycocotoolsCOCOeval.evalImgs` and
:attr:`~PycocotoolsCOCOeval.ious` re-ingest the held list on first read
(ADR-0055's lazy widening), so a detection dict mutated in place *after*
``evaluate`` shows up there while ``stats`` still reports the
pre-mutation numbers, and clearing the list yields cells with empty
``dtIds``. The window is asymmetric: under a ``params.catIds`` subset
the shim holds a *new* list of the same dicts, so appending to or
clearing the caller's list no longer propagates, while mutating a dict
it still shares does. Callers that mutate detections between passes
should hand each pass its own copy.
é    )Úannotations)ÚIterableÚMappingÚSequence)ÚSet)Údatetime)Úproduct)ÚAnyÚClassVarÚFinalÚLiteralÚProtocolÚ	TypedDictN)ÚNDArray)ÚDetectionsInput)Údetection_image_sizesÚto_coco_jsonÚwith_mask_image_sizesÚwith_placeholder_image_sizes)ÚAccumulatedÚEvalGridÚevaluate_bbox_gridÚevaluate_boundary_gridÚevaluate_keypoints_gridÚevaluate_segm_grid)ÚDEFAULT_DILATION_RATIOÚPARITY_STRICTÚ
ParityMode)ÚbboxÚsegmÚboundaryÚ	keypointsr   zFinal[IouType]ÚIOU_BBOXr    ÚIOU_SEGMr!   ÚIOU_BOUNDARYr"   ÚIOU_KEYPOINTSg      à?gffffffî?gÿÿÿÿÿÿ!@é   T)ÚendpointÚdtypezFinal[NDArray[np.float64]]Ú_DEFAULT_IOU_THRSg        g      ð?g      Y@Ú_DEFAULT_REC_THRSg    _ Bi   i $  zFinal[list[list[float]]]Ú_DEFAULT_AREA_RNG)ÚallÚsmallÚmediumÚlargezFinal[list[str]]Ú_DEFAULT_AREA_RNG_LBL)r'   é
   éd   zFinal[list[int]]Ú_DEFAULT_MAX_DETSÚ_KP_DEFAULT_AREA_RNG)r-   r/   r0   Ú_KP_DEFAULT_AREA_RNG_LBLé   Ú_KP_DEFAULT_MAX_DETS)g¤p=
×£Ð?ç      Ð?r9   çffffffÖ?r:   çHáz®Gé?r;   ç
×£p=
ç?r<   ç×£p=
×ã?r=   ç…ëQ¸ñ?r>   ç×£p=
×ë?r?   ç{®Gázì?r@   ©r)   g      $@Ú_KP_DEFAULT_OKS_SIGMASc                  ó:   — e Zd ZdZed	d„¦   «         Zd
d„Zd
d„ZdS )ÚCocoLikeuv  Structural type for the pycocotools.coco.COCO surface we touch.

    Defined as a Protocol because pycocotools ships no ``py.typed``
    marker; a hard import of the upstream class would force pyright
    into an ``Unknown`` cliff. The drop-in only depends on the four
    members below â€” anything else passes through ``self.cocoGt`` /
    ``self.cocoDt`` as ``Any``.
    ÚreturnúMapping[str, Any]c                ó   — d S ©N© ©Úselfs    ú_/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/vernier/_compat.pyÚdatasetzCocoLike.dataset—   s   € Ø,/¨Có    ú	list[int]c                ó   — d S rH   rI   rJ   s    rL   Ú	getImgIdszCocoLike.getImgIdsš   ó   € € € rN   c                ó   — d S rH   rI   rJ   s    rL   Ú	getCatIdszCocoLike.getCatIds›   rR   rN   N)rE   rF   ©rE   rO   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyrM   rQ   rT   rI   rN   rL   rD   rD   ˆ   sJ   € € € € € ðð ð Ø/Ð/Ð/ñ „XØ/à)Ð)Ð)Ð)Ø)Ð)Ð)Ð)Ð)Ð)rN   rD   c                  ó&   — e Zd ZdZefdd„Zdd„ZdS )Ú_Paramsa­  Mutable params namespace mirroring ``pycocotools.cocoeval.Params``.

    Honors ``maxDets``, ``useCats``, ``iouThrs``, ``recThrs`` and
    ``catIds`` mutations; mutating ``areaRng`` or subsetting ``imgIds``
    raises ``NotImplementedError`` at :meth:`PycocotoolsCOCOeval.evaluate`
    time so the divergence is loud (vs. silently ignored).

    Constructed with the iouType so the area-range / maxDets / sigmas
    defaults branch the same way pycocotools' ``__init__`` dispatches
    between ``setDetParams`` and ``setKpParams``. The keypoints branch
    (ADR-0012) drops the "small" bucket (quirk D5), pins the ladder to
    ``[20]``, and exposes ``kpt_oks_sigmas`` (quirk F1).
    ÚiouTypeÚIouTyperE   ÚNonec                óÌ  — g | _         g | _        t          | _        t          | _        |t          k    rUt          t          ¦  «        | _	        d„ t          D ¦   «         | _        t          t          ¦  «        | _        t          | _        nHt          t           ¦  «        | _	        d„ t"          D ¦   «         | _        t          t$          ¦  «        | _        d| _        d | _        || _        d S )Nc                ó,   — g | ]}t          |¦  «        ‘ŒS rI   ©Úlist©Ú.0Úrs     rL   ú
<listcomp>z$_Params.__init__.<locals>.<listcomp>¸   s   € Ð.UÐ.UÐ.U¸1­t°A©w¬wÐ.UÐ.UÐ.UrN   c                ó,   — g | ]}t          |¦  «        ‘ŒS rI   rb   rd   s     rL   rg   z$_Params.__init__.<locals>.<listcomp>Á   s   € Ð?Ð?Ð?¨�D ™GœGÐ?Ð?Ð?rN   r'   )ÚimgIdsÚcatIdsr*   ÚiouThrsr+   ÚrecThrsr&   rc   r8   ÚmaxDetsr5   ÚareaRngr6   Ú
areaRngLblrB   Úkpt_oks_sigmasr4   r,   r1   ÚuseCatsÚuseSegmr]   )rK   r]   s     rL   Ú__init__z_Params.__init__­   s¾   € Ø!#ˆŒØ!#ˆŒõ
 ->ˆŒÝ,=ˆŒØ•mÒ#Ð#Ý&*Õ+?Ñ&@Ô&@ˆDŒLØ.UÐ.UÕ@TÐ.UÑ.UÔ.UˆDŒLÝ)-Õ.FÑ)GÔ)GˆDŒOõ
 8NˆDÔÐåÕ 1Ñ2Ô2ˆDŒLØ?Ð?Õ->Ð?Ñ?Ô?ˆDŒLÝ"Õ#8Ñ9Ô9ˆDŒOØˆŒØ#'ˆŒØ 'ˆŒˆˆrN   ÚnameÚstrÚvalueÚobjectc                ó–   — |t           v r#t          |›d|› dt           |         ›d�¦  «        ‚t                               | ||¦  «         d S )Nzû belongs on vernier.instance.Evaluator (ADR-0040), not the pycocotools-shaped COCOeval shim. The shim mirrors pycocotools' surface for migration; for custom IoU / recall thresholds or area ranges, use the native Evaluator: `vernier.instance.Evaluator(z=...)`. (Pycocotools-shaped z& on this shim still mutates normally.))Ú_ADR_0040_NATIVE_FIELDSÚAttributeErrorrw   Ú__setattr__)rK   rt   rv   s      rL   r{   z_Params.__setattr__Ç   sw   € ð Õ*Ð*Ð*Ý Øð 1ð 1ð 04ð	1ð 1õ
 (?¸tÔ'Dð1ð 1ð 1ñô ð õ 	×Ò˜4  uÑ-Ô-Ð-Ð-Ð-rN   N)r]   r^   rE   r_   )rt   ru   rv   rw   rE   r_   )rV   rW   rX   rY   r#   rs   r{   rI   rN   rL   r\   r\   ž   sP   € € € € € ðð ð +3ð (ð (ð (ð (ð (ð4.ð .ð .ð .ð .ð .rN   r\   rk   rl   rn   )Úiou_thresholdsÚrecall_thresholdsÚarea_rangeszFinal[dict[str, str]]ry   z
Final[int]Ú_RETAIN_NONEÚ_RETAIN_METAé   Ú_RETAIN_IOUc                  ó  — e Zd ZU dZeZded<   ddeefddœd-d„Z	d.d„Z
ed/d„¦   «         Zej        d0d„¦   «         Zed1d„¦   «         Zej        d2d„¦   «         Zd3d„Zd3d„Zd4d „Zd5d"„Zd5d#„Zd6d%„Zd7d8d(„Zd.d)„Zd.d*„Zd9d,„ZdS ):ÚPycocotoolsCOCOevala?  Drop-in for ``pycocotools.cocoeval.COCOeval`` (bbox / segm / boundary / keypoints).

    Constructed identically to the upstream class. The state machine
    mirrors pycocotools: :meth:`evaluate` populates :attr:`evalImgs`,
    :meth:`accumulate` populates :attr:`eval`, :meth:`summarize`
    populates :attr:`stats`.

    The keyword-only ``parity_mode`` argument is the one extension over
    the upstream signature; it defaults to
    :attr:`DEFAULT_PARITY_MODE` (``"strict"``), which
    :func:`vernier.adapters.patch_pycocotools` rebinds for the patch
    lifetime.
    zClassVar[ParityMode]ÚDEFAULT_PARITY_MODEN)Úparity_modeÚcocoGtúCocoLike | NoneÚcocoDtr]   ru   Údilation_ratioÚfloatr†   úParityMode | NonerE   r_   c               óh  — |t           t          t          t          fvrt	          d|›d�¦  «        ‚|}|| _        || _        t          |¦  «        | _        || _	        |pt          | ¦  «        j        | _        g | _        i | _        i | _        t!          j        dt           j        ¬¦  «        | _        d | _        t*          | _        d| _        d| _        d | _        |�Xt5          |                     ¦   «         ¦  «        | j        _        t5          |                     ¦   «         ¦  «        | j        _        d S d S )NzTvernier.COCOeval supports iouType in ('bbox', 'segm', 'boundary', 'keypoints') (got ú)r   rA   rN   rI   )r#   r$   r%   r&   ÚNotImplementedErrorr‡   r‰   r\   ÚparamsÚ_dilation_ratioÚtyper…   Ú_parity_modeÚ
_eval_imgsÚ_iousÚevalÚnpÚemptyÚfloat64ÚstatsÚ_gridr   Ú_grid_levelÚ	_gt_bytesÚ_dt_annsÚ_accumulatedÚsortedrQ   ri   rT   rj   )rK   r‡   r‰   r]   rŠ   r†   Úkinds          rL   rs   zPycocotoolsCOCOeval.__init__  s.  € ð �8¥X­|½]ÐKÐKÐKÝ%ðOØBIðOð Oð Oñô ð ð  ˆØˆŒØˆŒÝ& t™}œ}ˆŒØ-ˆÔØ(3Ð(Uµt¸D±z´zÔ7UˆÔð ?AˆŒØ?AˆŒ
Ø$&ˆŒ	Ý*,¬(°1½B¼JÐ*GÑ*GÔ*GˆŒ
Ø&*ˆŒ
õ !-ˆÔØ #ˆŒð
 (*ˆŒØ04ˆÔØÐÝ!'¨×(8Ò(8Ñ(:Ô(:Ñ!;Ô!;ˆDŒKÔÝ!'¨×(8Ò(8Ñ(:Ô(:Ñ!;Ô!;ˆDŒKÔÐÐð ÐrN   c                óú   — | j         �| j        €t          d¦  «        ‚|                      ¦   «          |                      ¦   «         \  | _        | _        |                      t          ¦  «         d | _	        d | _
        d S )Nz(evaluate requires both cocoGt and cocoDt)r‡   r‰   ÚRuntimeErrorÚ_validate_supported_paramsÚ_prepare_inputsr�   rž   Ú_build_gridr   r”   r•   rJ   s    rL   ÚevaluatezPycocotoolsCOCOeval.evaluate2  st   € ØŒ;Ð $¤+Ð"5ÝÐIÑJÔJÐJØ×'Ò'Ñ)Ô)Ð)Ø(,×(<Ò(<Ñ(>Ô(>Ñ%ˆŒ˜œð 	×Ò�Ñ&Ô&Ð&ØˆŒØˆŒ
ˆ
ˆ
rN   úlist[dict[str, Any] | None]c                ó€   — | j         €1|                      t          ¦  «                             ¦   «         | _         | j         S )a-  Per-image evaluation records, built from the grid on first access.

        Reading this re-runs the per-image pass with per-cell metadata
        retained, once, and caches the result. Nothing else on this
        class needs the metadata, so the cost lands only on callers
        that ask.
        )r”   Ú	_grid_forr€   Ú	eval_imgsrJ   s    rL   ÚevalImgszPycocotoolsCOCOeval.evalImgsA  s3   € ð Œ?Ð"Ø"Ÿnšn­\Ñ:Ô:×DÒDÑFÔFˆDŒOØŒÐrN   rv   c                ó   — || _         d S rH   )r”   ©rK   rv   s     rL   r¬   zPycocotoolsCOCOeval.evalImgsN  s   € àˆŒˆˆrN   ú!dict[tuple[int, int], _IouMatrix]c                ó   ‡‡— | j         €|                      t          ¦  «                             ¦   «         }g Št	          d„ | j        j        D ¦   «         |                      ¦   «         ¦  «        }|j        Šˆˆfd„|D ¦   «         | _         | j         S )uX  ``{(imgId, catId): similarity matrix}``, built on first access.

        Mirrors ``pycocotools.cocoeval.COCOeval.ious``: one entry per
        ``(image, category)`` pair in ``params.imgIds x params.catIds``
        (``catId`` is ``-1`` when ``params.useCats`` is falsy), holding a
        ``(D, G)`` array of detections-by-ground-truths with detections
        score-descending and truncated to ``max(params.maxDets)``.

        Per quirk **F5**, a pair with no detections *or* no ground truths
        is a bare ``[]`` rather than an empty array, which is what
        ``maskUtils.iou`` and ``computeOks`` both return.

        Reading this re-runs the per-image pass with the similarity
        matrices retained, once, and caches the result â€” they are
        O(G x D) per cell and neither ``accumulate`` nor ``summarize``
        reads them.
        Nc                ó,   — g | ]}t          |¦  «        ‘ŒS rI   ©Úint)re   Úimage_ids     rL   rg   z,PycocotoolsCOCOeval.ious.<locals>.<listcomp>p  s   € ÐBÐBÐB 8•�X‘”ÐBÐBÐBrN   c                ó*   •— i | ]}| ‰|‰¦  «        “ŒS rI   rI   )re   Úkeyr˜   Úretained_gets     €€rL   ú
<dictcomp>z,PycocotoolsCOCOeval.ious.<locals>.<dictcomp>t  s'   ø€ ÐHÐHÐH¸C˜#˜|˜|¨C°Ñ7Ô7ÐHÐHÐHrN   )	r•   rª   r‚   Úiousr	   r�   ri   Ú_axis_category_idsÚget)rK   ÚretainedÚkeysr˜   r·   s      @@rL   r¹   zPycocotoolsCOCOeval.iousR  s•   øø€ ð& Œ:ÐØ—~’~¥kÑ2Ô2×7Ò7Ñ9Ô9ˆHØ "ˆEõ ØBÐB¨t¬{Ô/AÐBÑBÔBØ×'Ò'Ñ)Ô)ñô ˆDð $œ<ˆLØHÐHÐHÐHÐHÀ4ÐHÑHÔHˆDŒJØŒzÐrN   c                ó   — || _         d S rH   )r•   r®   s     rL   r¹   zPycocotoolsCOCOeval.iousw  s   € àˆŒ
ˆ
ˆ
rN   Úlevelr³   r   c                ó|   — | j         €t          d¦  «        ‚| j        |k    r| j         S |                      |¦  «        S )aX  The evaluated grid, re-evaluated if it was built below ``level``.

        The retention level only ever widens: asking for ``ious`` after
        ``evalImgs`` rebuilds once at the ``iou`` level, so a caller
        that reads both attributes pays for at most two extra passes
        over the lifetime of the object, not one per read.
        NúPlease run evaluate() first)r›   r£   rœ   r¦   )rK   r¿   s     rL   rª   zPycocotoolsCOCOeval._grid_for{  sE   € ð Œ:ÐÝÐ<Ñ=Ô=Ð=ØÔ˜uÒ$Ð$Ø”:ÐØ×Ò Ñ&Ô&Ð&rN   c                ó6  — | j         }t          | j        j        ¦  «        }t	          | j        j        ¦  «        }t          | j        j        t          ¦  «        t          | j        j	        t          ¦  «        d|t          k    |t          k    dœ}| j        j        t          k    rt          | j        |f| j        ||dœ|¤Ž}nË| j        j        t$          k    rt'          | j        |f| j        ||dœ|¤Ž}n™| j        j        t(          k    r#t+          | j        |f| j        ||| j        dœ|¤Ž}na| j        j        t.          k    r0t1          | j        |f| j        |||                      ¦   «         dœ|¤Ž}nt5          d| j        j        ›�¦  «        ‚|| _        || _        |S )uÕ  Evaluate the grid at retention ``level`` and record it as current.

        The level is recorded here, next to the build it describes, so
        ``self._grid_level`` cannot disagree with what ``self._grid``
        actually holds.

        The detections go in as the caller's own list of result dicts â€”
        ADR-0057's list route â€” and that is the point of this method.
        The `json.dumps` round trip it replaces rebuilt, first as text
        and then as Rust values, the objects Python was already holding,
        and had to hold both at once. No shape is lost by not
        serializing: the list route takes every segmentation form a
        results *file* carries (polygons, either `counts` encoding, a
        bitmask), reads the supplied `area` quirk **J3** needs, and
        converges on the same `Vec<DetectionInput>` the JSON parser
        produces â€” so there is no second parity surface and no reason
        to keep a bytes path in reserve.
        Úsupplied)r|   r}   Údt_areaÚretain_metaÚ
retain_iou)r†   Úmax_dets_per_imageÚuse_cats)r†   rÇ   rÈ   rŠ   )r†   rÇ   rÈ   Úsigmaszunsupported iouType )rž   Úmaxr�   rm   Úboolrq   Ú_custom_ladderrk   r*   rl   r+   r€   r‚   r]   r#   r   r�   r“   r$   r   r%   r   r‘   r&   r   Ú_resolve_kp_sigmasr�   r›   rœ   )rK   r¿   ÚdtÚmax_det_toprÈ   Úgrid_optionsÚgrids          rL   r¦   zPycocotoolsCOCOeval._build_grid‰  só  € ð& #œmˆÝ˜$œ+Ô-Ñ.Ô.ˆÝ˜œÔ+Ñ,Ô,ˆå,¨T¬[Ô-@ÕBSÑTÔTÝ!/°´Ô0CÕEVÑ!WÔ!Wð "ð !¥LÒ0Ø¥;Ò.ð
&
ð 
&
ˆð Œ;Ô¥(Ò*Ð*Ý%Ø”Øðð !Ô-Ø#.Ø!ðð ð ðð ˆDˆDð Œ[Ô ¥HÒ,Ð,Ý%Ø”Øðð !Ô-Ø#.Ø!ðð ð ðð ˆDˆDð Œ[Ô ¥LÒ0Ð0Ý)Ø”Øðð !Ô-Ø#.Ø!Ø#Ô3ðð ð ðð ˆDˆDð Œ[Ô ¥MÒ1Ð1Ý*Ø”Øðð !Ô-Ø#.Ø!Ø×.Ò.Ñ0Ô0ðð ð ðð ˆDˆDõ &Ð&T¸T¼[Ô=PÐ&TÐ&TÑUÔUÐUØˆŒ
Ø ˆÔØˆrN   útuple[bytes, Sequence[Any]]c                ó¸  — | j         €J ‚| j        €J ‚| j         j        }| j        j        }|                     dg ¦  «        }|                      ¦   «         }|�-t          ||¦  «        }t          |t          |¦  «        ¦  «        }| j        j	        t          t          fv rt          |¦  «        }nt          |t          |¦  «        ¦  «        }t          |¦  «        |fS )u§  GT dataset as JSON bytes, DT annotations as the caller's list.

        Applies, in pycocotools' own order, the two normalizations
        ``COCOeval._prepare`` performs before any kernel runs: the
        ``params.catIds`` filter, then the image-size resolution that
        ``annToRLE`` implies.

        The DT side comes back as a list of result dicts rather than
        JSON: a ``params.catIds`` subset is a list comprehension over
        the caller's own dicts, not a filter-then-re-serialize. The GT
        side is still JSON â€” the dataset carries `images` and
        `categories` alongside the annotations, and ADR-0057's routes
        are detection-only.
        Nr   )r‡   r‰   rM   r»   Ú_selected_category_idsÚ_with_categoriesÚ_anns_in_categoriesÚsetr�   r]   r#   r&   r   r   r   r   )rK   Ú
gt_datasetÚ
dt_datasetÚdt_annsÚselecteds        rL   r¥   z#PycocotoolsCOCOeval._prepare_inputsÖ  sÒ   € ð Œ{Ð&Ð&Ð&ØŒ{Ð&Ð&Ð&Ø(,¬Ô(;ˆ
Ø(,¬Ô(;ˆ
Ø!+§¢°¸rÑ!BÔ!BˆØ×.Ò.Ñ0Ô0ˆØÐÝ)¨*°hÑ?Ô?ˆJÝ)¨'µ3°x±=´=ÑAÔAˆGØŒ;Ô¥8­]Ð";Ð;Ð;Ý5°jÑAÔAˆJˆJå.¨zÕ;PÐQ[Ñ;\Ô;\Ñ]Ô]ˆJÝ˜JÑ'Ô'¨Ð0Ð0rN   rO   c                óH   — t          d„ | j        j        D ¦   «         ¦  «        S )a  ``params.catIds`` deduplicated, coerced to ``int`` and sorted.

        The one place the raw ``params.catIds`` is normalized; both the
        :attr:`ious` key axis and the ``_prepare``-time category filter
        read it through here so they cannot disagree.
        c                ó,   — h | ]}t          |¦  «        ’ŒS rI   r²   )re   Úcats     rL   ú	<setcomp>z>PycocotoolsCOCOeval._requested_category_ids.<locals>.<setcomp>û  s   € Ð>Ð>Ð> C•s˜3‘x”xÐ>Ð>Ð>rN   )r    r�   rj   rJ   s    rL   Ú_requested_category_idsz+PycocotoolsCOCOeval._requested_category_idsô  s&   € õ Ð>Ð>¨4¬;Ô+=Ð>Ñ>Ô>Ñ?Ô?Ð?rN   c                óH   — | j         j        sdgS |                      ¦   «         S )zýThe ``catId`` axis of :attr:`ious`, as pycocotools keys it.

        ``cocoeval.py:522`` reads ``catIds = p.catIds if p.useCats else
        [-1]``, so a collapsed evaluation keys every pair on the single
        ``-1`` sentinel (quirk **L4**).
        éÿÿÿÿ)r�   rq   rà   rJ   s    rL   rº   z&PycocotoolsCOCOeval._axis_category_idsý  s*   € ð Œ{Ô"ð 	Ø�4ˆKØ×+Ò+Ñ-Ô-Ð-rN   úlist[int] | Nonec                ó˜   — | j         €J ‚|                      ¦   «         }|t          | j                              ¦   «         ¦  «        k    rdS |S )zñ``params.catIds`` in axis order, or ``None`` if it is everything.

        ``None`` means "no filtering needed" and keeps the whole-dataset
        path allocation-free; it is the case every caller but a
        per-class loop hits.
        N)r‡   rà   r    rT   )rK   Ú	requesteds     rL   rÔ   z*PycocotoolsCOCOeval._selected_category_ids  sO   € ð Œ{Ð&Ð&Ð&Ø×0Ò0Ñ2Ô2ˆ	Ø�˜tœ{×4Ò4Ñ6Ô6Ñ7Ô7Ò7Ð7Ø�4ØÐrN   Úpr
   c                ó  — | j         €t          d¦  «        ‚t          | j        j        ¦  «        | j        _        t          | j        j        ¦  «        }| j                              |¦  «        }|| _        |€| j        n|t          |j        ¦  «        t          j
        ¦   «                              d¦  «        t          j        |j        ¦  «        t          j        |j        ¦  «        t          j        |j        ¦  «        dœ| _        d S )NrÁ   z%Y-%m-%d %H:%M:%S)r�   ÚcountsÚdateÚ	precisionÚrecallÚscores)r›   r£   r    r�   rm   rc   Ú
accumulaterŸ   rè   r   ÚnowÚstrftimer—   Úasarrayrê   rë   rì   r–   )rK   ræ   Úmax_detsÚaccs       rL   rí   zPycocotoolsCOCOeval.accumulate  sÒ   € ØŒ:ÐÝÐ<Ñ=Ô=Ð=õ % T¤[Ô%8Ñ9Ô9ˆŒÔÝ˜œÔ+Ñ,Ô,ˆØŒj×#Ò# HÑ-Ô-ˆØˆÔà%& Y�d”k�k°AÝ˜3œ:Ñ&Ô&Ý”L‘N”N×+Ò+Ð,?Ñ@Ô@Ýœ C¤MÑ2Ô2Ý”j ¤Ñ,Ô,Ý”j ¤Ñ,Ô,ð
ð 
ˆŒ	ˆ	ˆ	rN   c                ó6  — | j         r| j        €t          d¦  «        ‚| j                             ¦   «         }t	          j        |j        t          j        ¬¦  «        | _        | j        t          k    r&| 
                    ¦   «         D ]}t          |¦  «         Œd S d S )NzPlease run accumulate() firstrA   )r–   rŸ   r£   Ú	summarizer—   rð   rš   r™   r“   r   Úpretty_linesÚprint)rK   ÚsummaryÚlines      rL   rô   zPycocotoolsCOCOeval.summarize*  sž   € ØŒyð 	@˜DÔ-Ð5ÝÐ>Ñ?Ô?Ð?ð Ô#×-Ò-Ñ/Ô/ˆÝ”Z ¤µR´ZÐ@Ñ@Ô@ˆŒ
ð Ô¥Ò-Ð-Ø×,Ò,Ñ.Ô.ð ð �Ý�d‘”��ð .Ð-ðð rN   c                óœ  — | j         €J ‚t          | j        j        ¦  «         | j        j        t
          k    rt          nt          }d„ | j        j        D ¦   «         d„ |D ¦   «         k    rt          d¦  «         t          | j        j        ¦  «        t          | j                              ¦   «         ¦  «        k    rt          dd¦  «         d S d S )Nc                ó,   — g | ]}t          |¦  «        ‘ŒS rI   rb   rd   s     rL   rg   zBPycocotoolsCOCOeval._validate_supported_params.<locals>.<listcomp>L  s   € Ð1Ð1Ð1˜�D�‰GŒGÐ1Ð1Ð1rN   c                ó,   — g | ]}t          |¦  «        ‘ŒS rI   rb   rd   s     rL   rg   zBPycocotoolsCOCOeval._validate_supported_params.<locals>.<listcomp>L  s   € Ð5VÐ5VÐ5VÀ!µd¸1±g´gÐ5VÐ5VÐ5VrN   rn   ri   z%subsetting; evaluate the full dataset)r‡   Ú_reject_use_segmr�   rr   r]   r&   r5   r,   rn   Ú_raise_unsupportedr    ri   rQ   )rK   Úcanonical_areas     rL   r¤   z.PycocotoolsCOCOeval._validate_supported_paramsC  sÎ   € ØŒ{Ð&Ð&Ð&Ý˜œÔ,Ñ-Ô-Ð-ð
 %)¤KÔ$7½=Ò$HÐ$HÕ Ð ÕN_ð 	ð 2Ð1˜Tœ[Ô0Ð1Ñ1Ô1Ð5VÐ5VÀ~Ð5VÑ5VÔ5VÒVÐVÝ˜yÑ)Ô)Ð)Ý�$”+Ô$Ñ%Ô%­°´×0EÒ0EÑ0GÔ0GÑ)HÔ)HÒHÐHÝ˜xÐ)PÑQÔQÐQÐQÐQð IÐHrN   údict[int, list[float]]c                ó>  ‡— | j         j        }|t          u ri S t          j        |t          ¦  «        ri S | j        €J ‚d„ t          j        |t          j        ¬¦  «                             ¦   «         D ¦   «         Šˆfd„| j         	                    ¦   «         D ¦   «         S )ud  Translate ``params.kpt_oks_sigmas`` into the FFI's per-cat shape.

        Pycocotools stores a single 17-tuple on the params object that
        applies to every category; vernier's Rust core takes
        ``dict[int, list[float]]``. If the user has not mutated the
        sigma array the identity check short-circuits to an empty dict
        â€” the Rust core's ``OksSimilarity`` falls back to the COCO-person
        defaults, keeping output byte-identical to pycocotools on the
        common path. If the array has been replaced, fan it out across
        every ``cocoGt`` category id (quirk F1).
        Nc                ó,   — g | ]}t          |¦  «        ‘ŒS rI   ©r‹   ©re   Úvs     rL   rg   z:PycocotoolsCOCOeval._resolve_kp_sigmas.<locals>.<listcomp>g  s   € ÐQÐQÐQ˜q•%˜‘(”(ÐQÐQÐQrN   rA   c                óJ   •— i | ]}t          |¦  «        t          ‰¦  «        “Œ S rI   )r³   rc   )re   rÞ   Úcustoms     €rL   r¸   z:PycocotoolsCOCOeval._resolve_kp_sigmas.<locals>.<dictcomp>h  s'   ø€ ÐJÐJÐJ¨3•�C‘”�$˜v™,œ,ÐJÐJÐJrN   )
r�   rp   rB   r—   Úarray_equalr‡   rð   r™   ÚravelrT   )rK   rÉ   r  s     @rL   rÍ   z&PycocotoolsCOCOeval._resolve_kp_sigmasU  s    ø€ ð ”Ô+ˆØÕ+Ð+Ð+ØˆIÝŒ>˜&Õ"8Ñ9Ô9ð 	ØˆIØŒ{Ð&Ð&Ð&ØQÐQ¥B¤J¨v½R¼ZÐ$HÑ$HÔ$H×$NÒ$NÑ$PÔ$PÐQÑQÔQˆØJÐJÐJÐJ°$´+×2GÒ2GÑ2IÔ2IÐJÑJÔJÐJrN   )r‡   rˆ   r‰   rˆ   r]   ru   rŠ   r‹   r†   rŒ   rE   r_   )rE   r_   )rE   r¨   )rv   r¨   rE   r_   )rE   r¯   )rv   r¯   rE   r_   )r¿   r³   rE   r   )rE   rÒ   rU   )rE   rã   rH   )ræ   r
   rE   r_   )rE   rÿ   )rV   rW   rX   rY   r   r…   Ú__annotations__r$   r   rs   r§   rZ   r¬   Úsetterr¹   rª   r¦   r¥   rà   rº   rÔ   rí   rô   r¤   rÍ   rI   rN   rL   r„   r„   ð   sä  € € € € € € ðð ð 1>ÐÐ=Ð=Ð=Ñ=ð #'Ø"&ØØ 6ð/<ð *.ð/<ð /<ð /<ð /<ð /<ð /<ðbð ð ð ð ð
ð 
ð 
ñ „Xð
ð „_ð ð  ð  ñ „_ð ð ð"ð "ð "ñ „Xð"ðH 
„[ðð ð ñ „[ðð'ð 'ð 'ð 'ðKð Kð Kð KðZ1ð 1ð 1ð 1ð<@ð @ð @ð @ð	.ð 	.ð 	.ð 	.ðð ð ð ð
ð 
ð 
ð 
ð 
ð*ð ð ð ð2Rð Rð Rð Rð$Kð Kð Kð Kð Kð KrN   r„   c                  óB   — e Zd ZU ded<   ded<   ded<   ded<   ded<   d	S )
Ú_GridOptionsúlist[float] | Noner|   r}   zLiteral['bbox', 'supplied']rÄ   rË   rÅ   rÆ   N)rV   rW   rX   r	  rI   rN   rL   r  r  p  sN   € € € € € € Ø&Ð&Ð&Ñ&Ø)Ð)Ð)Ñ)Ø(Ð(Ð(Ñ(ØÐÐÑØÐÐÑÐÐrN   r  ÚactualúNDArray[np.float64]ÚdefaultrE   r  c                ó†   — | |u rd S d„ t          j        | t           j        ¬¦  «                             ¦   «         D ¦   «         S )Nc                ó,   — g | ]}t          |¦  «        ‘ŒS rI   r  r  s     rL   rg   z"_custom_ladder.<locals>.<listcomp>~  s   € ÐKÐKÐK˜�E�!‰HŒHÐKÐKÐKrN   rA   )r—   rð   r™   r  )r  r  s     rL   rÌ   rÌ   x  sE   € ð �ÐÐØˆtØKÐK�bœj¨µr´zÐBÑBÔB×HÒHÑJÔJÐKÑKÔKÐKrN   ÚannsúIterable[Any]rÛ   úAbstractSet[int]ú	list[Any]c                ó    ‡— ˆfd„| D ¦   «         S )Nc                óB   •— g | ]}t          |d          ¦  «        ‰v ¯|‘ŒS )Úcategory_idr²   )re   ÚannrÛ   s     €rL   rg   z'_anns_in_categories.<locals>.<listcomp>†  s0   ø€ ÐGÐGÐG�C¥3 s¨=Ô'9Ñ#:Ô#:¸hÐ#FÐ#FˆCÐ#FÐ#FÐ#FrN   rI   )r  rÛ   s    `rL   rÖ   rÖ   �  s    ø€ ð
 HÐGÐGÐG˜4ÐGÑGÔGÐGrN   rM   rF   úSequence[int]c                óÌ   ‡— d„ |                       dg ¦  «        D ¦   «         Ši | ¥ˆfd„|D ¦   «         t          |                       dg ¦  «        t          |¦  «        ¦  «        dœ¥S )Nc                ó:   — i | ]}t          |d          ¦  «        |“ŒS )Úidr²   )re   Úcategorys     rL   r¸   z$_with_categories.<locals>.<dictcomp>–  s&   € Ð\Ð\Ð\°(•�H˜T”NÑ#Ô# XÐ\Ð\Ð\rN   Ú
categoriesc           	     ó\   •— g | ](}‰                      ||t          |¦  «        d œ¦  «        ‘Œ)S ))r  rt   )r»   ru   )re   rÞ   Údeclareds     €rL   rg   z$_with_categories.<locals>.<listcomp>™  s5   ø€ Ð\Ð\Ð\ÈC�x—|’| C°½SÀ¹X¼XÐ)FÐ)FÑGÔGÐ\Ð\Ð\rN   r   )r   r   )r»   rÖ   r×   )rM   rÛ   r"  s     @rL   rÕ   rÕ   ‰  s‚   ø€ ð ]Ð\¸g¿kºkÈ,ÐXZÑ>[Ô>[Ð\Ñ\Ô\€HðØ
ðà\Ð\Ð\Ð\ÐS[Ð\Ñ\Ô\Ý*¨7¯;ª;°}ÀbÑ+IÔ+IÍ3ÈxÉ=Ì=ÑYÔYðð ð ð rN   Ú rt   ru   Údetailr_   c                ó<   — |rd|› �nd}t          d| › |› �¦  «        ‚)Nz; r#  z4vernier.COCOeval does not yet support custom params.©r�   )rt   r$  Úsuffixs      rL   rý   rý   ž  s4   € Ø$Ð,ˆ]�&ˆ]ˆ]ˆ]¨"€FÝ
ÐcÐUYÐcÐ[aÐcÐcÑ
dÔ
dÐdrN   rv   ú
int | Nonec                ó(   — | �t          d¦  «        ‚d S )Nz params.useSegm was deprecated by pycocotools years ago and is not honored by vernier (quirk L3). Pass iouType='bbox' or iouType='segm' to COCOeval(...) instead.r&  )rv   s    rL   rü   rü   £  s)   € ð ÐÝ!ð(ñ
ô 
ð 	
ð ÐrN   )r  r  r  r  rE   r  )r  r  rÛ   r  rE   r  )rM   rF   rÛ   r  rE   rF   )r#  )rt   ru   r$  ru   rE   r_   )rv   r(  rE   r_   )LrY   Ú
__future__r   Úcollections.abcr   r   r   r   ÚAbstractSetr   Ú	itertoolsr	   Útypingr
   r   r   r   r   r   Únumpyr—   Únumpy.typingr   Úvernier._array_typesr   Úvernier._coco_jsonr   r   r   r   Úvernier._corer   r   r   r   r   r   Úvernier._typesr   r   r   r^   r#   r	  r$   r%   r&   Úlinspacer³   Úroundr™   r*   r+   r,   r1   r4   r5   r6   r8   ÚarrayrB   rD   r\   ry   r   r€   r‚   r„   rc   Ú
_IouMatrixr  rÌ   rÖ   rÕ   rý   rü   rI   rN   rL   ú<module>r9     sh  ðð!ð !ð !ðF #Ð "Ð "Ð "Ð "Ð "à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ Eà Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  à 0Ð 0Ð 0Ð 0Ð 0Ð 0ðð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð Ð9Ô
:€à!€Ð !Ð !Ð !Ñ !Ø!€Ð !Ð !Ð !Ñ !Ø)€Ð )Ð )Ð )Ñ )Ø +€Ð +Ð +Ð +Ñ +ð 1<°´Øˆˆsˆs�8�2”8Ð/Ñ0Ô0Ñ1Ô1°AÑ5ÀÈBÌJð1ñ 1ô 1Ð ð ð ð ñ ð 1<°´Øˆˆcˆc�(�"”(Ð-Ñ.Ô.Ñ/Ô/°!Ñ3¸dÈ"Ì*ð1ñ 1ô 1Ð ð ð ð ñ ð ˆ€IØˆ€JØ
ˆE€NØ
ˆD€Mð	/Ð ð ð ð ñ ð +NÐ*MÐ*MÐ Ð MÐ MÐ MÑ MØ&2 l lÐ Ð 2Ð 2Ð 2Ñ 2ð ˆ€KØ
ˆE€NØ
ˆF€Oð2Ð ð ð ð ñ ð
 .HÐ-GÐ-GÐ Ð GÐ GÐ GÑ GØ*,¨Ð Ð -Ð -Ð -Ñ -ð €B„Hð	
ð 	
ð 	
ð& Œjð)ñ ô ð, ñ-ð ð ð ð ñ ð6*ð *ð *ð *ð *ˆxñ *ô *ð *ð,:.ð :.ð :.ð :.ð :.ñ :.ô :.ð :.ðD  Ø"Øð2ð 2Ð ð ð ð ñ ð €Ð Ð Ð Ñ Ø€Ð Ð Ð Ñ Ø€Ð Ð Ð Ñ ðxKð xKð xKð xKð xKñ xKô xKð xKðz �R”ZÔ  4¨¤9Ñ,€
ðð ð ð ð �9ñ ô ð ðLð Lð Lð LðHð Hð Hð Hðð ð ð ð*eð eð eð eð eð

ð 
ð 
ð 
ð 
ð 
rN   