§
    ß©ºjÀ  ã                  óæ   — U d Z ddlmZ ddlZddlmZ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 ddlmZ ddlmZmZmZmZ dd	lmZ dad
ed<   g Zded<   ddd„Zej        ddd„¦   «         Z g d¢Z!dS )aÑ  Framework adapters for vernier.

This subpackage holds optional integrations with external frameworks
(PyTorch tensors via DLPack, etc.) and migration helpers. Each adapter
is importable without its underlying framework being installed; gate
framework-specific imports behind ``try``/``except ImportError``.

The pycocotools migration helper (:func:`patch_pycocotools`) is the
sanctioned entry point for swapping
``pycocotools.cocoeval.COCOeval`` with vernier's drop-in. Policy and
rationale are in ADR-0007.

The ingest route turns a training loop's state into vernier's
evaluation inputs, reading any array type through DLPack without
importing its framework. It has two spellings of one conversion:
:func:`coco_inputs` for per-image records and
:func:`coco_inputs_from_columns` for state that is already
concatenated, which is what a TorchMetrics-shaped metric holds. Both
land on one builder, so they cannot drift. :func:`coco_metrics` is the
convenience wrapper for the AP case and :func:`gt_image_sizes` resolves
the image sizes a columnar ground truth needs. ADR-0063 is the record.

The COCO-JSON normalizers (:func:`with_placeholder_image_sizes`,
:func:`with_mask_image_sizes`, :func:`detection_image_sizes`,
:func:`coco_json_default`, :func:`to_coco_json`) are the same
conversions the drop-in applies, published for callers that assemble a
pycocotools-shaped COCO dictionary and drive a vernier grid directly.
ADR-0055 is the record. This module is their canonical import path.
é    )ÚannotationsN)ÚCallableÚ	Generator)ÚDetectionColumnsÚ
PredictionÚTargetÚTargetColumns)Úcoco_json_defaultÚdetection_image_sizesÚto_coco_jsonÚwith_mask_image_sizesÚwith_placeholder_image_sizes)ÚPycocotoolsCOCOeval)Úcoco_inputsÚcoco_inputs_from_columnsÚcoco_metricsÚgt_image_sizes)Ú
ParityModeztype | NoneÚ_original_cocoevalzlist[ParityMode]Ú_parity_mode_stackÚstrictÚparity_moder   ÚreturnúCallable[[], None]c                ó  ‡‡— 	 ddl mŠ n"# t          $ r}t          d¦  «        |‚d}~ww xY wt          €‰j        at
                               t          j        ¦  «         | t          _        t          ‰_        dŠdˆˆfd„}|S )	uœ  Replace ``pycocotools.cocoeval.COCOeval`` with vernier's drop-in.

    Returns an idempotent unpatch callable. The outermost unpatch
    restores the original pycocotools class; intermediate unpatches
    pop the parity-mode stack so nested
    :func:`patched_pycocotools` exits restore the surrounding patch
    state. Per ADR-0007:

    - Default ``parity_mode`` is ``"strict"`` because migration intent
      is bit-exactness with pycocotools.
    - Raises :class:`ImportError` if pycocotools is not installed â€”
      silent fallthrough would let downstream test setups think the
      patch took effect when it did not.
    - Calling ``patch_pycocotools`` repeatedly without unpatching
      stacks the parity-mode state but never overwrites the saved
      original class, so the final unpatch always restores the real
      pycocotools class.

    Not thread-safe â€” call once at process or test setup, unwind at
    teardown. The patch must fire before any module that imports
    ``pycocotools.cocoeval`` â€” see ``docs/migrate/from-pycocotools.md``
    Â§"Troubleshooting" for the import-order pitfall and the
    session-scoped pytest fixture that side-steps it.
    r   Nz˜patch_pycocotools requires pycocotools to be installed; install it with `pip install pycocotools`, or use `vernier.COCOeval` directly without the patch.Fr   ÚNonec                 ó¨   •— ‰rd S dŠt           r#t                                ¦   «         t          _        t           st          �t          ‰ _        d ad S d S d S )NT)r   Úpopr   ÚDEFAULT_PARITY_MODEr   ÚCOCOeval)Úcocoeval_modÚ	unpatcheds   €€úi/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/vernier/adapters/__init__.pyÚunpatchz"patch_pycocotools.<locals>.unpatchn   sg   ø€ ð ð 	ØˆFØˆ	Ýð 	OÝ6H×6LÒ6LÑ6NÔ6NÕÔ3Ý!ð 	&Õ&8Ð&DÝ$6ˆLÔ!Ø!%ÐÐÐð	&ð 	&Ð&DÐ&Dó    )r   r   )	Úpycocotools.cocoevalÚcocoevalÚImportErrorr   r    r   Úappendr   r   )r   Úexcr$   r!   r"   s      @@r#   Úpatch_pycocotoolsr+   A   sÂ   øø€ ð6Ø3Ð3Ð3Ð3Ð3Ð3Ð3øÝð ð ð Ýð=ñ
ô 
ð ð		øøøøðøøøõ Ð!Ø)Ô2Ðå×ÒÕ1ÔEÑFÔFÐFØ.9ÕÔ+Ý/€LÔà€Ið
&ð 
&ð 
&ð 
&ð 
&ð 
&ð 
&ð €Ns   „ ‹
*•%¥*úGenerator[None, None, None]c              #  ód   K  — t          | ¦  «        }	 dV —  |¦   «          dS #  |¦   «          w xY w)u  Context-manager variant of :func:`patch_pycocotools`.

    Nests correctly: an outer ``with`` followed by an inner ``with``
    restores the outer-patch state on inner exit and the original
    pycocotools class on outer exit (per ADR-0007 Â§"Reentrancy").
    N)r+   )r   r$   s     r#   Úpatched_pycocotoolsr.   }   sB   è è € õ   Ñ,Ô,€GðØˆˆˆàˆ‰	Œ	ˆ	ˆ	ˆ	øˆˆ‰	Œ	ˆ	ˆ	øøøs   “# £/)r   r   r   r	   r   r   r
   r   r   r   r+   r.   r   r   r   )r   )r   r   r   r   )r   r   r   r,   )"Ú__doc__Ú
__future__r   Ú
contextlibÚcollections.abcr   r   Úvernier._array_typesr   r   r   r	   Úvernier._coco_jsonr
   r   r   r   r   Úvernier._compatr   Úvernier._samplesr   r   r   r   Úvernier._typesr   r   Ú__annotations__r   r+   Úcontextmanagerr.   Ú__all__© r%   r#   ú<module>r<      sš  ððð ð ð< #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /à TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tðð ð ð ð ð ð ð ð ð ð ð ð ð ð 0Ð /Ð /Ð /Ð /Ð /ðð ð ð ð ð ð ð ð ð ð ð ð &Ð %Ð %Ð %Ð %Ð %ð
 #'Ð Ð &Ð &Ð &Ñ &ð (*Ð Ð )Ð )Ð )Ñ )ð9ð 9ð 9ð 9ð 9ðx Ôðð ð ð ñ Ôððð ð €€€r%   