§
    >²¸j°š  ã                  ót  — d dl mZ d dlZd dl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 erd dl
mZ d dlZd dlm
Z d dlmZmZ d d	lmZ d d
lmZ d dlmZmZ d dlm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z, d dl-m.Z. e G d„ de¦  «        ¦   «         Z/d#d„Z0	 d$d%d „Z1 G d!„ d"¦  «        Z2dS )&é    )ÚannotationsN)ÚCallable)ÚThreadPoolExecutor)Úpartial)ÚTYPE_CHECKINGÚAnyÚProtocolÚcastÚruntime_checkable)Ú	TypeGuard)ÚORIENTED_BOX_COORDINATESÚSOURCE_IMAGE_METADATA_FIELD)ÚCompactMask)Ú
Detections)Ú
move_boxesÚmove_oriented_boxes)Úmerge_metadata_lenient)ÚOverlapFilterÚOverlapMetric)Ú
move_masks)Ú	ImageType)Ú
crop_imageÚget_image_resolution_wh)ÚSupervisionWarnings)Úcreate_batchesc                  ó:   — e Zd ZU dZded<   ded<   ded<   dd„ZdS )ÚWindowedRasterDatasetu&  Structural type for a rasterio-style dataset read window-by-window.

    Matched structurally by `_is_windowed_raster` rather than by import so
    `rasterio` stays an optional dependency â€” any object exposing these members
    works. `rasterio.io.DatasetReader` satisfies this protocol.
    ÚintÚwidthÚheightzobject | NoneÚcrsÚwindowr   Úreturnúnpt.NDArray[Any]c                ó   — d S ©N© )Úselfr"   s     ú|/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/detection/tools/inference_slicer.pyÚreadzWindowedRasterDataset.read*   s   € € € ó    N)r"   r   r#   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r*   r'   r+   r)   r   r      sH   € € € € € € ðð ð €J€J�JØ€K€K�KØÐÐÑà8Ð8Ð8Ð8Ð8Ð8r+   r   ÚimageÚobjectr#   ú TypeGuard[WindowedRasterDataset]c                óž   — t          t          | dd¦  «        ¦  «        o/t          | d¦  «        ot          | d¦  «        ot          | d¦  «        S )zâDuck-type check for a rasterio-style dataset that supports windowed reads.

    Avoids importing rasterio so it remains an optional dependency. numpy arrays
    and PIL images do not expose this combination of attributes.
    r*   Nr!   r   r    )ÚcallableÚgetattrÚhasattr)r1   s    r)   Ú_is_windowed_rasterr8   -   sX   € õ 	•˜ ¨Ñ-Ô-Ñ.Ô.ð 	%Ý�E˜5Ñ!Ô!ð	%å�E˜7Ñ#Ô#ð	%õ �E˜8Ñ$Ô$ð	r+   Ú
detectionsr   Úoffsetr$   Úresolution_whútuple[int, int] | Nonec                ó’  — |                       t          d¦  «        ¦  «        } t          | j        |¬¦  «        | _        t          | j        v rVt          t          t          j	        t          j                 | j        t                   ¦  «        |¬¦  «        | j        t          <   | j        �ž|€t          d¦  «        ‚t          | j        t          ¦  «        rW| j                             t#          |d         ¦  «        t#          |d         ¦  «        |d         |d         f¬¦  «        | _        nt%          | j        ||¬¦  «        | _        | S )	aè  Translate detections by a pixel offset, repositioning boxes and masks.

    Args:
        detections: Detections object to be moved. The input is left unchanged;
            a fresh copy is returned.
        offset: An array of shape `(2,)` containing offset values in the
            format `[dx, dy]`.
        resolution_wh: The width and height of the desired mask
            resolution. Required for segmentation detections.

    Returns:
        Repositioned Detections object.
    N)Úxyxyr:   )Úxyxyxyxyr:   z‡Resolution width and height are required for moving segmentation detections. This should be the same as (width, height) of image shape.r   é   )ÚdxÚdyÚnew_image_shape)Úmasksr:   r;   )ÚselectÚslicer   r>   r   Údatar   r
   ÚnptÚNDArrayÚnpÚnumberÚmaskÚ
ValueErrorÚ
isinstancer   Úwith_offsetr   r   ©r9   r:   r;   s      r)   Úmove_detectionsrQ   ;   s7  € ð$ ×"Ò"¥5¨¡;¤;Ñ/Ô/€JÝ  j¤o¸fÐEÑEÔE€J„OÝ :¤?Ð2Ð2Ý4GÝÝ”�BœIÔ&¨
¬Õ8PÔ(Qñô ð ð	5
ñ 5
ô 5
ˆ
ŒÕ0Ñ1ð „Ð"ØÐ ÝðYñô ð õ �j”o¥{Ñ3Ô3ð 
	à(œo×9Ò9Ý�v˜a”y‘>”>Ý�v˜a”y‘>”>Ø!.¨qÔ!1°=ÀÔ3CÐ Dð :ñ ô ˆJŒOˆOõ )Ø ”o¨fÀMðñ ô ˆJŒOð Ðr+   c                  óà   — e Zd ZdZddej        dej        dddfd6d„Zd7d„Z	d8d„Z
d9d!„Zd:d%„Zd;d'„Zd<d)„Zd=d,„Zd>d/„Zed?d0„¦   «         Zed@d1„¦   «         ZedAd3„¦   «         ZedBd4„¦   «         Zd5S )CÚInferenceSlicerué  
    Perform tiled inference on large images by slicing them into overlapping patches.

    This class divides an input image into overlapping slices of configurable size
    and overlap, runs inference on each slice through a user-provided callback, and
    merges the resulting detections. The slicing process allows efficient processing
    of large images with limited resources while preserving detection accuracy via
    configurable overlap and post-processing of overlaps. Uses multi-threading for
    parallel slice inference.

    Args:
        callback: Inference function called for each slice (or batch of slices).

            When ``batch_size=1`` (default) the function receives a single
            ``np.ndarray`` and must return a single
            :class:`~supervision.detection.core.Detections` â€” the original
            single-image contract, fully backward-compatible.

            When ``batch_size > 1`` the function receives
            ``list[np.ndarray]`` (one array per slice) and must return
            ``list[Detections]`` of the **same length** in the same order.
            A length mismatch or non-list return raises :exc:`ValueError`.

            The two signatures are **not interchangeable**: a callback written
            for ``batch_size=1`` will fail when ``batch_size > 1``, and vice
            versa.
        slice_wh: Size of each slice `(width, height)`. If int, both width and
            height are set to this value.
        overlap_wh: Overlap size `(width, height)` between slices. If int, both
            width and height are set to this value.
        overlap_filter: Strategy to merge overlapping detections
            (`NON_MAX_SUPPRESSION`, `NON_MAX_MERGE`, or `NONE`).
        iou_threshold: IOU threshold used in merging overlap filtering.
        overlap_metric: Metric to compute overlap (`IOU` or `IOS`).
        thread_workers: Number of threads for concurrent slice inference.
            Must be a positive integer. When the first slice returns oriented
            bounding boxes (OBB), Supervision probes additional slices until a
            non-empty result is found, then falls back to sequential processing
            for all remaining slices to avoid thread-safety issues in common OBB
            inference backends. When passing a rasterio-style dataset, tile reads
            are serialized via an internal lock regardless of this setting â€”
            model inference runs in parallel, but ``raster.read()`` is protected.
            Note: the first slice always runs synchronously
            regardless of this setting, so for grids with few slices
            (e.g. two-slice images) effective parallelism is reduced.
        compact_masks: If ``True``, dense ``(N, H, W)`` boolean mask
            arrays returned by the callback are immediately converted to a
            :class:`~supervision.detection.compact_mask.CompactMask`. This
            keeps masks in run-length-encoded form for the entire pipeline â€”
            merge, NMS, and annotation â€” avoiding the large ``(N, H, W)``
            allocations that cause OOM on high-resolution images with many
            objects. IoU and NMS are computed directly on the RLE crops
            without ever materialising a full ``(N, H, W)`` array.
            Defaults to ``False`` for backward compatibility.

            When ``compact_masks=True``, each detection's CompactMask crop spans
            the entire slice tile bbox (not the tight detection bbox). Call
            :meth:`~supervision.detection.compact_mask.CompactMask.repack` on the
            merged result to tighten crops to the detection bounding boxes.
        batch_size: Number of slices passed to the callback per call.
            Defaults to ``1``, which uses the single-image callback contract
            (``np.ndarray`` â†’ :class:`~supervision.detection.core.Detections`).
            Set to ``> 1`` to enable the batch callback contract
            (``list[np.ndarray]`` â†’ ``list[Detections]``).

            For GPU-backed models, prefer ``batch_size > 1`` with
            ``thread_workers=1``. A single batched forward pass is faster than
            concurrent single-image calls that compete for the same CUDA device,
            and avoids multiplying peak VRAM by ``thread_workers * batch_size``.
            Must be a positive integer.

    Raises:
        ValueError: If ``slice_wh``, ``overlap_wh``, or ``thread_workers`` are
            invalid or inconsistent.
        ValueError: If ``batch_size < 1``.
        ValueError: If the callback returns a non-list when ``batch_size > 1``.
        ValueError: If the callback returns a list whose length differs from the
            number of slices passed when ``batch_size > 1``.

    Example:
        ```python
        from supervision import _cv2 as cv2
        import supervision as sv
        from rfdetr import RFDETRMedium

        model = RFDETRMedium()

        def callback(tile):
            return model.predict(tile)

        slicer = sv.InferenceSlicer(callback, slice_wh=640, overlap_wh=100)

        image = cv2.imread("example.png")
        detections = slicer(image)
        ```

        ```python
        import supervision as sv
        from PIL import Image
        from ultralytics import YOLO

        model = YOLO("yolo11m.pt")

        def callback(tile):
            results = model(tile)[0]
            return sv.Detections.from_ultralytics(results)

        slicer = sv.InferenceSlicer(callback, slice_wh=640, overlap_wh=100)

        image = Image.open("example.png")
        detections = slicer(image)
        ```

        ```python
        import rasterio
        import supervision as sv

        def callback(tile):  # tile is (H, W, C); select/convert bands as needed
            ...

        slicer = sv.InferenceSlicer(callback, slice_wh=640, overlap_wh=100)

        with rasterio.open("large_orthomosaic.tif") as dataset:
            detections = slicer(dataset)
        ```

        Passing an open rasterio dataset reads each tile lazily via a windowed
        read, so multi-GB GeoTIFFs never need to be loaded into memory at once.
        `rasterio` is an optional dependency installable via
        `pip install "supervision[geotiff]"`.

        Batch inference â€” pass multiple slices per callback call for GPU models
        that benefit from batched forward passes:

        ```python
        from supervision import _cv2 as cv2
        import numpy as np
        import supervision as sv

        # Batch callback: receives list[np.ndarray], returns list[Detections]
        def batch_callback(tiles: list[np.ndarray]) -> list[sv.Detections]:
            # Run your model on the batch; return one Detections per tile.
            return [sv.Detections.empty() for _ in tiles]

        slicer = sv.InferenceSlicer(
            callback=batch_callback,
            slice_wh=640,
            overlap_wh=100,
            batch_size=8,
            thread_workers=1,  # recommended for GPU: batch not threads
        )

        image = cv2.imread("example.png")
        detections = slicer(image)
        ```
    i€  éd   g      à?r@   FÚcallbackúXCallable[[ImageType], Detections] | Callable[[list[npt.NDArray[Any]]], list[Detections]]Úslice_whúint | tuple[int, int]Ú
overlap_whÚoverlap_filterúOverlapFilter | strÚiou_thresholdÚfloatÚoverlap_metricúOverlapMetric | strÚthread_workersr   Úcompact_masksÚboolÚ
batch_sizec
                ó˜  — |                       |¦  «        }
|                      |¦  «        }|                      |
|¬¦  «         |dk     rt          d|› �¦  «        ‚|	dk     rt          d|	› �¦  «        ‚|
| _        || _        || _        t          j        |¦  «        | _	        t          j        |¦  «        | _        || _        || _        || _        |	| _        d| _        t#          j        ¦   «         | _        d| _        t#          j        ¦   «         | _        d| _        t#          j        ¦   «         | _        t#          j        ¦   «         | _        d S )N)rW   rY   r@   z7`thread_workers` must be a positive integer. Received: z3`batch_size` must be a positive integer. Received: F)Ú_normalize_slice_whÚ_normalize_overlap_whÚ_validate_overlaprM   rW   rY   r\   r   Ú
from_valuer^   r   rZ   rU   r`   ra   rc   Ú_out_of_slice_bounds_warnedÚ	threadingÚLockÚ_out_of_slice_bounds_lockÚ_obb_thread_workers_warnedÚ_obb_thread_workers_lockÚ_dropped_metadata_warnedÚ_dropped_metadata_lockÚ_raster_read_lock)r(   rU   rW   rY   rZ   r\   r^   r`   ra   rc   Úslice_wh_normÚoverlap_wh_norms               r)   Ú__init__zInferenceSlicer.__init__  sX  € ð ×0Ò0°Ñ:Ô:ˆØ×4Ò4°ZÑ@Ô@ˆà×Ò¨À/ÐÑRÔRÐRà˜AÒÐÝð.Ø+ð.ð .ñô ð ð ˜Š>ˆ>ÝØRÀjÐRÐRñô ð ð &ˆŒØ)ˆŒØ*ˆÔÝ+Ô6°~ÑFÔFˆÔÝ+Ô6°~ÑFÔFˆÔð CKˆŒØ,ˆÔØ*ˆÔØ$ˆŒØ16ˆÔ(Ý)2¬Ñ)9Ô)9ˆÔ&Ø05ˆÔ'Ý(1¬Ñ(8Ô(8ˆÔ%Ø.3ˆÔ%Ý&/¤nÑ&6Ô&6ˆÔ#Ý!*¤Ñ!1Ô!1ˆÔÐÐr+   r1   ú!ImageType | WindowedRasterDatasetr#   r   c           	     ó®  — g }|                       |¦  «        }|                      || j        | j        ¬¦  «        }| j        dk    �r�t          t          || j        ¦  «        ¦  «        }|                      ||d         ¦  «        }|                     |¦  «         t          d„ |D ¦   «         ¦  «        }|rT| j
        dk    rI| j        5  | j        s#d| _        t          j        dt          d¬¦  «         d	d	d	¦  «         n# 1 swxY w Y   |dd	…         }| j
        dk    s|r/|D ]+}	|                     |                      ||	¦  «        ¦  «         Œ,not!          | j
        ¬
¦  «        5 }
|
                     t%          | j        |¦  «        |¦  «        D ]}|                     |¦  «         Œ	 d	d	d	¦  «         n# 1 swxY w Y   |                      ||¦  «        S |d         }|                      ||¦  «        }|                     |¦  «         |dd	…         }t,          |j        v }| j
        dk    p|}d}|s˜t1          |¦  «        dk    r…|t1          |¦  «        k     rr||         }|                      ||¦  «        }|                     |¦  «         |dz  }t,          |j        v rd}d}n't1          |¦  «        dk    rn|t1          |¦  «        k     °r||d	…         }|r…| j
        dk    rK|rI| j        5  | j        s#d| _        t          j        dt          d¬¦  «         d	d	d	¦  «         n# 1 swxY w Y   |D ]+}|                     |                      ||¦  «        ¦  «         Œ,nit!          | j
        ¬
¦  «        5 }
|                     |
                     t%          | j        |¦  «        |¦  «        ¦  «         d	d	d	¦  «         n# 1 swxY w Y   |                      ||¦  «        S )uD  
        Perform tiled inference on the full image and return merged detections.

        The first slice always runs synchronously so the output type can be
        inspected before committing to a threading strategy. Detections are
        merged in a deterministic order: the first slice is always at index 0,
        followed by any probe slices, then the remaining slices in source order.
        If oriented bounding boxes are detected, all remaining slices are
        processed sequentially and a ``SupervisionWarnings`` warning is emitted
        once per slicer instance.

        Per-slice ``metadata`` is merged leniently: a key survives only when
        every slice carries it with an equal value; otherwise it is dropped and
        a ``SupervisionWarnings`` warning is emitted once per slicer instance,
        naming the dropped keys â€” a key meant to be global (``video_name``,
        ``camera_id``, â€¦) would otherwise vanish silently. The merged
        ``metadata`` dict returned is always freshly built, never the same
        dict object as any slice's own metadata.

        ``source_image`` is the one metadata key handled specially: it is
        removed from every slice before the lenient merge, then reattached
        afterward as a reference to ``image`` itself â€” not a copy, and not the
        per-slice tile â€” for in-memory input (array or PIL image); a windowed
        raster dataset has no full in-memory image to give back, so its result
        carries no ``source_image``. Because the stored value is a reference,
        mutating the returned ``metadata["source_image"]`` mutates the caller's
        own ``image``, and every ``Detections`` derived from the result via
        ``select()``, ``__getitem__``, or ``with_nms()`` shares that same
        reference â€” a long-lived derived result (e.g. held across a video
        processing loop) keeps the full input frame alive.

        Args:
            image: The full image to run inference on. In addition to in-memory
                images (NumPy arrays or PIL images), this also accepts an open
                rasterio-style dataset. When a dataset is provided, each tile is
                read lazily via a windowed read instead of loading the whole image
                into memory, enabling tiled inference on multi-GB GeoTIFFs. Tiles
                read from a dataset preserve the source dtype (e.g. ``uint16`` for
                16-bit sensors) and keep every band; convert or select bands to
                the dtype/channels your model expects inside the callback.

        Returns:
            Merged detections across all slices.

        Raises:
            ValueError: If ``image`` is a rasterio-style dataset whose CRS is
                geographic (non-projected). Reproject to a projected CRS
                (e.g. with ``gdalwarp``) before calling.
        )r;   rW   rY   r@   r   c              3  ó2   K  — | ]}t           |j        v V — Œd S r&   )r   rG   )Ú.0Údets     r)   ú	<genexpr>z+InferenceSlicer.__call__.<locals>.<genexpr>y  s;   è è € ð ð Ø9<Õ(¨C¬HÐ4ðð ð ð ð ð r+   TzßInferenceSlicer detected oriented bounding boxes while `thread_workers > 1`. Remaining batches will be processed sequentially because many OBB inference backends are not thread-safe and can crash when shared across threads.é   ©ÚcategoryÚ
stacklevelN)Úmax_workerszÞInferenceSlicer detected oriented bounding boxes while `thread_workers > 1`. Remaining slices will be processed sequentially because many OBB inference backends are not thread-safe and can crash when shared across threads.)Ú_get_resolution_whÚ_generate_offsetrW   rY   rc   Úlistr   Ú_run_callback_batchÚextendÚanyr`   rn   rm   ÚwarningsÚwarnr   r   Úmapr   Ú_merge_and_filterÚ_run_callbackÚappendr   rG   Úlen)r(   r1   Údetections_listr;   ÚoffsetsÚbatchedÚfirst_batch_resultsÚobb_detectedÚremaining_batchesÚoffset_batchÚexecutorÚbatch_detectionsÚfirst_offsetÚfirst_detectionsÚremaining_offsetsÚshould_run_sequentiallyÚprobe_indexÚprobe_offsetÚprobe_detectionsr:   s                       r)   Ú__call__zInferenceSlicer.__call__9  sž  € ðd -/ˆØ×/Ò/°Ñ6Ô6ˆà×'Ò'Ø'Ø”]Ø”ð (ñ 
ô 
ˆð Œ?˜QÒÑÝ�>¨'°4´?ÑCÔCÑDÔDˆGà"&×":Ò":¸5À'È!Ä*Ñ"MÔ"MÐØ×"Ò"Ð#6Ñ7Ô7Ð7Ýð ð Ø@Sðñ ô ñ ô ˆLð ð  Ô 3°aÒ 7Ð 7ØÔ2ð 
ð 
ØÔ:ð 	Ø:>˜Ô7Ý œðTõ &9Ø'(ðñ ô ð ð
ð 
ð 
ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
øøøð 
ð 
ð 
ð 
ð !(¨¨¨¤ÐØÔ" aÒ'Ð'¨<Ð'Ø$5ð ð �LØ#×*Ò*Ø×0Ò0°¸ÑEÔEñô ð ð ðõ
 (°DÔ4GÐHÑHÔHð AÈHð -5¯LªLÝ Ô 8¸%Ñ@Ô@ÐBSñ-ô -ð Að AÐ(ð (×.Ò.Ð/?Ñ@Ô@Ð@Ð@ðAðAð Að Añ Aô Að Að Að Að Að Að Aøøøð Að Að Að Að ×)Ò)¨/¸5ÑAÔAÐAà˜q”zˆØ×-Ò-¨e°\ÑBÔBÐØ×ÒÐ/Ñ0Ô0Ð0à# A B BœKÐÝ/Ð3CÔ3HÐHˆØ"&Ô"5¸Ò":Ð"J¸lÐàˆØ&ð 	­3Ð/?Ñ+@Ô+@ÀAÒ+EÐ+EØ¥Ð$5Ñ 6Ô 6Ò6Ð6Ø0°Ô=�Ø#'×#5Ò#5°e¸\Ñ#JÔ#JÐ Ø×&Ò&Ð'7Ñ8Ô8Ð8Ø˜qÑ �å+Ð/?Ô/DÐDÐDØ#'�LØ.2Ð+ØåÐ'Ñ(Ô(¨1Ò,Ð,Øð ¥Ð$5Ñ 6Ô 6Ò6Ð6ð .¨k¨l¨lÔ;Ðà"ð 	ØÔ" QÒ&Ð&¨<Ð&ØÔ2ð 
ð 
ØÔ:ð 	Ø:>˜Ô7Ý œðTõ &9Ø'(ðñ ô ð ð
ð 
ð 
ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
øøøð 
ð 
ð 
ð 
ð ,ð Jð J�Ø×&Ò& t×'9Ò'9¸%ÀÑ'HÔ'HÑIÔIÐIÐIðJõ $°Ô0CÐDÑDÔDð Èð  ×&Ò&Ø—L’L¥¨Ô);¸UÑ!CÔ!CÐEVÑWÔWñô ð ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ×%Ò% o°uÑ=Ô=Ð=sI   Ã+C=Ã=DÄDÅ#AF2Æ2F6Æ9F6Ë'+LÌL"Ì%L"Í-=N6Î6N:Î=N:r�   úlist[Detections]c                ó„   — |                       ||¦  «        \  }}|                      |¦  «        }|r||j        t          <   |S )u�  Merge per-slice detections, apply the overlap filter, restore the source.

        The source image is attached only after filtering. Overlap filters propagate
        ``metadata`` forward untouched, so the output is identical either way â€” but
        ``NON_MAX_MERGE`` compares metadata values per merge group, and a whole
        ``(H, W, C)`` array compared once per group dominates the filter's runtime.

        Args:
            detections_list: Per-slice detections in full-image coordinates.
            image: The full image the slices were cut from.

        Returns:
            The merged, overlap-filtered detections.
        )Ú_merge_slice_detectionsÚ_apply_overlap_filterÚmetadatar   )r(   r�   r1   ÚmergedÚhad_source_imageÚfiltereds         r)   r‰   z!InferenceSlicer._merge_and_filterÌ  sO   € ð& $(×#?Ò#?ÀÐQVÑ#WÔ#WÑ ˆÐ Ø×-Ò-¨fÑ5Ô5ˆØð 	CØ=BˆHÔÕ9Ñ:Øˆr+   útuple[Detections, bool]c                ó@  — d„ |D ¦   «         }t          |¦  «         }d}|r"|D ]}t          |j        v r|j        t          = d}Œ t          d„ |D ¦   «         ¦  «        \  }}|D ]	}i |_        Œ
t	          j        |¬¦  «        }	||	_        |                      |¦  «         |	|fS )uu  Merge per-slice detections, reconciling their metadata leniently.

        Metadata keys that disagree across slices, or that only some slices carry,
        are dropped rather than raising â€” slices legitimately differ in per-tile
        metadata. The source image is the one such key worth recovering: when any
        slice carried it, the caller restores the full input image â€” array or PIL
        alike, but not a windowed raster, which has no full in-memory image to hand
        back. Any other key lost this way is reported once per slicer instance,
        since a key the user meant to be global (``video_name``, ``camera_id``, â€¦)
        would otherwise vanish silently.

        Because the source image is restored wholesale, it is removed from every
        slice up front: leaving it in would make the lenient merge â€” and every
        downstream merge group of ``NON_MAX_MERGE`` â€” compare whole image arrays
        only to overwrite the result afterwards. Slices of a windowed raster keep
        the key, since nothing restores it for them.

        Args:
            detections_list: Per-slice detections in full-image coordinates.
            image: The full image the slices were cut from.

        Returns:
            The merged detections before overlap filtering, and whether any slice
            carried a source image that the caller should restore.
        c                ó:   — g | ]}|                      ¦   «         °|‘ŒS r'   )Úis_empty©rx   Úds     r)   ú
<listcomp>z;InferenceSlicer._merge_slice_detections.<locals>.<listcomp>  s%   € ÐDÐDÐD˜1°q·z²z±|´|ÐD�QÐDÐDÐDr+   FTc                ó   — g | ]	}|j         ‘Œ
S r'   )r¢   rª   s     r)   r¬   z;InferenceSlicer._merge_slice_detections.<locals>.<listcomp>  s   € Ð+Ð+Ð+˜AˆQŒZÐ+Ð+Ð+r+   )r�   )r8   r   r¢   r   r   ÚmergeÚ_warn_dropped_metadata)
r(   r�   r1   Ú	non_emptyÚ
restorabler¤   r«   Úmerged_metadataÚdropped_keysr£   s
             r)   r    z'InferenceSlicer._merge_slice_detectionså  sÝ   € ð< EÐD ÐDÑDÔDˆ	å,¨UÑ3Ô3Ð3ˆ
Ø ÐØð 	,Øð ,ð ,�Ý.°!´*Ð<Ð<Øœ
Õ#>Ð?Ø'+Ð$øå(>Ø+Ð+ Ð+Ñ+Ô+ñ)
ô )
Ñ%ˆ˜ð ð 	ð 	ˆAØˆAŒJˆJÝÔ!°/ÐBÑBÔBˆØ)ˆŒà×#Ò# LÑ1Ô1Ð1àÐ'Ð'Ð'r+   r³   úset[str]ÚNonec                ó  — |r| j         rdS | j        5  | j         r	 ddd¦  «         dS d| _         d                     t          |¦  «        ¦  «        }t	          j        d|› d�t          d¬¦  «         ddd¦  «         dS # 1 swxY w Y   dS )zEWarn once per slicer instance about metadata keys lost while merging.NTz, zQInferenceSlicer dropped metadata keys that were not identical across all slices: z§. Metadata must agree on every slice to survive merging. If the value is genuinely per-detection, store it in `Detections.data` instead, which is merged per detection.r{   r|   )ro   rp   ÚjoinÚsortedr†   r‡   r   )r(   r³   Úkeyss      r)   r¯   z&InferenceSlicer._warn_dropped_metadata  s  € àð 	˜tÔ<ð 	ØˆFØÔ(ð 	ð 	àÔ,ð Øð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð -1ˆDÔ)Ø—9’9�V LÑ1Ô1Ñ2Ô2ˆDÝŒMðOØ&*ðOð Oð Oõ -Øðñ ô ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   “	A?©A	A?Á?BÂBútuple[int, int]c                ó´   — t          |¦  «        r;|j        }|�$t          |dd¦  «        st          d|› d�¦  «        ‚|j        |j        fS t          |¦  «        S )zEReturn ``(width, height)`` for the image, validating CRS for rasters.NÚis_projectedTz¢InferenceSlicer requires a projected coordinate reference system for pixel-space tiled inference on a raster dataset. The provided dataset uses a geographic CRS (zI). Reproject it to a projected CRS (e.g. with `gdalwarp`) before slicing.)r8   r!   r6   rM   r   r    r   )r(   r1   r!   s      r)   r€   z"InferenceSlicer._get_resolution_wh/  s|   € õ ˜uÑ%Ô%ð 		/Ø”)ˆCØˆ¥w¨s°NÀDÑ'IÔ'IˆÝ ðSàCFðSð Sð Sñô ð ð ”K ¤Ð.Ð.Ý& uÑ-Ô-Ð-r+   r£   c                óR  — | j         t          j        k    r|S | j         t          j        k    r!|                     | j        | j        ¬¦  «        S | j         t          j        k    r!|                     | j        | j        ¬¦  «        S t          j
        d| j         › �t          ¬¦  «         |S )zBApply the configured overlap filter strategy to merged detections.)Ú	thresholdr^   z!Invalid overlap filter strategy: )r}   )rZ   r   ÚNONEÚNON_MAX_SUPPRESSIONÚwith_nmsr\   r^   ÚNON_MAX_MERGEÚwith_nmmr†   r‡   r   )r(   r£   s     r)   r¡   z%InferenceSlicer._apply_overlap_filter?  s½   € àÔ¥-Ô"4Ò4Ð4ØˆMØÔ¥-Ô"CÒCÐCØ—?’?ØÔ,Ø#Ô2ð #ñ ô ð ð Ô¥-Ô"=Ò=Ð=Ø—?’?ØÔ,Ø#Ô2ð #ñ ô ð õ 	ŒØE°Ô0CÐEÐEÝ(ð	
ñ 	
ô 	
ð 	
ð ˆr+   r:   r$   c           	     ó¾  — t          |¦  «        r„d„ |D ¦   «         \  }}}}||f||ff}| j        5  |                     |¬¦  «        }ddd¦  «         n# 1 swxY w Y   t          j        t          j        |d¦  «        ¦  «        }	|j        |j        f}
n t          ||¬¦  «        }	t          |¦  «        }
|  
                    |	¦  «        }| j        r¨|j        �¡t          |j        t          j        ¦  «        r‚t          |	¦  «        \  }}t          j        t          j        dd|dz
  |dz
  ggt          j        ¬¦  «        t%          |¦  «        df¦  «        }t'          j        |j        |||f¬	¦  «        |_        | j         ot%          |¦  «        dk    }|�r-| j        5  | j        �st%          |¦  «        dk    ró|d
         |d         z
  }|d         |d         z
  }t          j        |j        dd…dd
gf         |k    ¦  «        }t          j        |j        dd…ddgf         |k    ¦  «        }t          j        |j        dd…dd
gf         dk     ¦  «        }t          j        |j        dd…ddgf         dk     ¦  «        }|s|s|s|r%d| _        d}t3          j        |t6          d
¬¦  «         ddd¦  «         n# 1 swxY w Y   t9          ||dd
…         |
¬¦  «        }|S )aT  
        Run detection callback on a sliced portion of the image and adjust coordinates.

        Args:
            image: The full image.
            offset: Coordinates `(x_min, y_min, x_max, y_max)` defining
                the slice region.

        Returns:
            Detections adjusted to the full image coordinate system.
        c              3  ó4   K  — | ]}t          |¦  «        V — Œd S r&   ©r   ©rx   Úvs     r)   rz   z0InferenceSlicer._run_callback.<locals>.<genexpr>b  s(   è è € Ð)AÐ)A°Q­#¨a©&¬&Ð)AÐ)AÐ)AÐ)AÐ)AÐ)Ar+   ©r"   N©r@   r{   r   ©r1   r>   r   r@   ©Údtype©Úimage_shaper{   é   Tá  Detections returned by the callback have coordinates outside the slice bounds. This may be caused by the callback running inference on the full image instead of the provided image slice. Ensure your callback uses the input slice for inference, not the original full-resolution image.r|   rP   )r8   rq   r*   rJ   ÚascontiguousarrayÚ	transposer   r    r   r   rU   ra   rL   rN   ÚndarrayÚtileÚarrayÚfloat64rŒ   r   Ú
from_denseri   rl   r…   r>   r†   r‡   r   rQ   )r(   r1   r:   Úx_minÚy_minÚx_maxÚy_maxr"   ÚbandsÚimage_slicer;   r9   Úslice_wÚslice_hÚfull_slice_xyxyÚneeds_warning_checkÚslice_widthÚslice_heightÚ	x_exceedsÚ	y_exceedsÚ
x_negativeÚ
y_negativeÚmsgs                          r)   rŠ   zInferenceSlicer._run_callbackS  sº  € õ ˜uÑ%Ô%ð 	;Ø)AÐ)A¸&Ð)AÑ)AÔ)AÑ&ˆE�5˜% à˜e�n u¨e nÐ5ˆFØÔ'ð 2ð 2ØŸ
š
¨&˜
Ñ1Ô1�ð2ð 2ð 2ñ 2ô 2ð 2ð 2ð 2ð 2ð 2ð 2øøøð 2ð 2ð 2ð 2åÔ.Ý”˜U IÑ.Ô.ñô ˆKð #œ[¨%¬,Ð7ˆMˆMå$¨5°vÐ>Ñ>Ô>ˆKÝ3°EÑ:Ô:ˆMà—]’] ;Ñ/Ô/ˆ
ð Ôð	à”Ð+Ý˜:œ?­B¬JÑ7Ô7ð ,õ  7°{ÑCÔCÑˆG�WÝ œgÝ”˜1˜a ¨1¡¨g¸©kÐ:Ð;Å2Ä:ÐNÑNÔNÝ�Z‘” !Ð$ñô ˆOõ *Ô4Ø”ØØ$ gÐ.ðñ ô ˆJŒOð Ô0Ð0ÐHµS¸±_´_ÀqÒ5Hð 	ð ñ 	WØÔ/ð Wð WàÔ7ñ W½CÀ
¹O¼OÈaÒ<OÐ<OØ"(¨¤)¨f°Q¬iÑ"7�KØ#)¨!¤9¨v°a¬yÑ#8�LÝ "¤ z¤°q°q°q¸1¸a¸&°yÔ'AÀKÒ'OÑ PÔ P�IÝ "¤ z¤°q°q°q¸1¸a¸&°yÔ'AÀLÒ'PÑ QÔ Q�IÝ!#¤¨
¬¸¸¸¸A¸q¸6¸	Ô(BÀQÒ(FÑ!GÔ!G�JÝ!#¤¨
¬¸¸¸¸A¸q¸6¸	Ô(BÀQÒ(FÑ!GÔ!G�JØ ð 
W Ið 
W°ð 
W¸zð 
WØ;?˜Ô8ð5ð õ !œ cÕ4GÐTUÐVÑVÔVÐVð'Wð Wð Wñ Wô Wð Wð Wð Wð Wð Wð Wøøøð Wð Wð Wð Wõ( %Ø!Ø˜"˜1˜"”:Ø'ð
ñ 
ô 
ˆ
ð
 Ðs$   °AÁAÁAÆDJ8Ê8J<Ê?J<rŽ   úlist[npt.NDArray[Any]]c           
     óì  ‡‡— t          ‰¦  «        ržg }|D ]Š}d„ |D ¦   «         \  }}}}||f||ff}	| j        5  ‰                     |	¬¦  «        }
ddd¦  «         n# 1 swxY w Y   |                     t	          j        t	          j        |
d¦  «        ¦  «        ¦  «         Œ‹‰j        ‰j        fŠnˆfd„|D ¦   «         }t          ‰¦  «        Št          t          t          t          j        t                            gt          t                    f         | j        ¦  «        } ||¦  «        }t%          |t          ¦  «        st'          dt)          |¦  «        › �¦  «        ‚t+          |¦  «        t+          |¦  «        k    r0t'          dt+          |¦  «        › dt+          |¦  «        › d	�¦  «        ‚| j        r¾t/          ||¦  «        D ]­\  }}|j        �¡t%          |j        t          j        ¦  «        r‚t          |¦  «        \  }}t	          j        t	          j        d
d
|dz
  |dz
  ggt          j        ¬¦  «        t+          |¦  «        df¦  «        }t;          j        |j        |||f¬¦  «        |_        Œ®| j        �s^t/          ||¦  «        D �]L\  }}| j        st+          |¦  «        d
k    rŒ!| j         5  | j        �st+          |¦  «        d
k    rñ|d         |d
         z
  }|d         |d         z
  }t	          j!        |j"        dd…d
dgf         |k    ¦  «        }t	          j!        |j"        dd…ddgf         |k    ¦  «        }t	          j!        |j"        dd…d
dgf         d
k     ¦  «        }t	          j!        |j"        dd…ddgf         d
k     ¦  «        }|s|s|s|r#d| _        tG          j$        dtJ          d¬¦  «         ddd¦  «         n# 1 swxY w Y   �ŒNˆfd„t/          ||¦  «        D ¦   «         S )a+  Run batch inference callback on multiple slices.

        Args:
            image: The full image or rasterio dataset.
            offsets: List of slice coordinates `(x_min, y_min, x_max, y_max)`.

        Returns:
            Detections adjusted to full-image coordinates, one per offset.
        c              3  ó4   K  — | ]}t          |¦  «        V — Œd S r&   rÆ   rÇ   s     r)   rz   z6InferenceSlicer._run_callback_batch.<locals>.<genexpr>´  s(   è è € Ð-EÐ-E¸­c°!©f¬fÐ-EÐ-EÐ-EÐ-EÐ-EÐ-Er+   rÉ   NrÊ   c                ó2   •— g | ]}t          ‰|¬ ¦  «        ‘ŒS )rË   )r   )rx   r:   r1   s     €r)   r¬   z7InferenceSlicer._run_callback_batch.<locals>.<listcomp>»  s&   ø€ ÐQÐQÐQ¸v•j u°6Ð:Ñ:Ô:ÐQÐQÐQr+   zDCallback must return `list[Detections]` when `batch_size > 1`. Got: zCallback returned z Detections for z slices. Lengths must match.r   r@   rÌ   rÎ   r{   rÐ   TrÑ   r|   c                óJ   •— g | ]\  }}t          ||d d…         ‰¬¦  «        ‘Œ S )Nr{   rP   )rQ   )rx   ry   r:   r;   s      €r)   r¬   z7InferenceSlicer._run_callback_batch.<locals>.<listcomp>ô  sM   ø€ ð 
ð 
ð 
ñ ��Võ Ø v¨b¨q¨b¤zÀðñ ô ð
ð 
ð 
r+   )&r8   rq   r*   r‹   rJ   rÒ   rÓ   r   r    r   r
   r   r‚   rH   rI   r   r   rU   rN   rM   ÚtyperŒ   ra   ÚziprL   rÔ   rÕ   rÖ   r×   r   rØ   ri   rl   r…   r>   r†   r‡   r   )r(   r1   rŽ   Úslicesr:   rÙ   rÚ   rÛ   rÜ   r"   rÝ   Úbatch_callbackÚdetections_in_slicesry   rÞ   rß   rà   rá   rã   rä   rå   ræ   rç   rè   r;   s    `                      @r)   rƒ   z#InferenceSlicer._run_callback_batch£  sæ  øø€ õ ˜uÑ%Ô%ð 	;ØˆFØ!ð Tð T�Ø-EÐ-E¸fÐ-EÑ-EÔ-EÑ*��u˜e UØ  %˜.¨5°%¨.Ð9�ØÔ+ð 6ð 6Ø!ŸJšJ¨f˜JÑ5Ô5�Eð6ð 6ð 6ñ 6ô 6ð 6ð 6ð 6ð 6ð 6ð 6øøøð 6ð 6ð 6ð 6à—’�bÔ2µ2´<ÀÀyÑ3QÔ3QÑRÔRÑSÔSÐSÐSØ"œ[¨%¬,Ð7ˆMˆMàQÐQÐQÐQÈÐQÑQÔQˆFÝ3°EÑ:Ô:ˆMåÝ•d�3œ;¥sÔ+Ô,Ð-­tµJÔ/?Ð?Ô@À$Ä-ñ
ô 
ˆð  .˜~¨fÑ5Ô5ÐÝÐ.µÑ5Ô5ð 	Ýð5ÝÐ1Ñ2Ô2ð5ð 5ñô ð õ Ð#Ñ$Ô$­¨G©¬Ò4Ð4ÝðB¥SÐ)=Ñ%>Ô%>ð Bð BÝ˜7‘|”|ðBð Bð Bñô ð ð
 Ôð 	Ý$'Ð(<¸fÑ$EÔ$Eð ð Ñ ��[Ø”8Ð'­J°s´xÅÄÑ,LÔ,LÐ'Ý'>¸{Ñ'KÔ'KÑ$�G˜WÝ&(¤gÝœ 1 a¨°1©°gÀ±kÐ"BÐ!CÍ2Ì:ÐVÑVÔVÝ˜S™œ 1˜ñ'ô '�Oõ  +Ô5ØœØ'Ø%,¨gÐ$6ð ñ  ô  �C”Høð Ô/ñ 	Ý"Ð#7¸ÑAÔAð ñ ‘��VØÔ3ð µs¸3±x´xÀ1²}°}ØØÔ3ð ð ØÔ;ñ ÅÀCÁÄÈ1ÂÀØ&,¨Q¤i°&¸´)Ñ&;˜Ø'-¨a¤y°6¸!´9Ñ'<˜Ý$&¤F¨3¬8°A°A°A¸¸1°v°IÔ+>ÀÒ+LÑ$MÔ$M˜	Ý$&¤F¨3¬8°A°A°A¸¸1°v°IÔ+>ÀÒ+MÑ$NÔ$N˜	Ý%'¤V¨C¬H°Q°Q°Q¸¸A¸°YÔ,?À!Ò,CÑ%DÔ%D˜
Ý%'¤V¨C¬H°Q°Q°Q¸¸A¸°YÔ,?À!Ò,CÑ%DÔ%D˜
Ø$ð ¨	ð °Zð À:ð Ø?C˜DÔ<Ý$œMð!9õ *=Ø+,ð	ñ 	ô 	ð 	ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ùð*
ð 
ð 
ð 
õ  #Ð#7¸ÑAÔAð	
ñ 
ô 
ð 	
s$   ¸AÁA	Á"A	Ê4DOÏO	ÏO	c                ó&  — t          | t          ¦  «        r| dk    rt          d| › �¦  «        ‚| | fS t          | t          ¦  «        r:t	          | ¦  «        dk    r'| \  }}|dk    s|dk    rt          d| › �¦  «        ‚||fS t          d| › �¦  «        ‚)Nr   z1`slice_wh` must be a positive integer. Received: r{   z.`slice_wh` values must be positive. Received: z\`slice_wh` must be an int or a tuple of two positive integers (slice_w, slice_h). Received: ©rN   r   rM   ÚtuplerŒ   )rW   r   r    s      r)   re   z#InferenceSlicer._normalize_slice_whû  sÒ   € õ �h¥Ñ$Ô$ð 	&Ø˜1Š}ˆ}Ý ØRÈÐRÐRñô ð ð ˜XÐ%Ð%å�h¥Ñ&Ô&ð 	!­3¨x©=¬=¸AÒ+=Ð+=Ø$‰MˆE�6Ø˜Šzˆz˜V qš[˜[Ý ØOÀXÐOÐOñô ð ð ˜&�=Ð åð$à!ð$ð $ñ
ô 
ð 	
r+   c                ó&  — t          | t          ¦  «        r| dk     rt          d| › �¦  «        ‚| | fS t          | t          ¦  «        r:t	          | ¦  «        dk    r'| \  }}|dk     s|dk     rt          d| › �¦  «        ‚||fS t          d| › �¦  «        ‚)Nr   z7`overlap_wh` must be a non negative integer. Received: r{   z4`overlap_wh` values must be non negative. Received: zf`overlap_wh` must be an int or a tuple of two non negative integers (overlap_w, overlap_h). Received: rõ   )rY   Ú	overlap_wÚ	overlap_hs      r)   rf   z%InferenceSlicer._normalize_overlap_wh  sÛ   € õ �j¥#Ñ&Ô&ð 	*Ø˜AŠ~ˆ~Ý ð.Ø!+ð.ð .ñô ð ð ˜zÐ)Ð)å�j¥%Ñ(Ô(ð 	(­S°©_¬_ÀÒ-AÐ-AØ#-Ñ ˆI�yØ˜1Š}ˆ} 	¨A¢ Ý ØWÈ:ÐWÐWñô ð ð ˜iÐ'Ð'åð&à#ð&ð &ñ
ô 
ð 	
r+   r;   c                óh  — |\  }}| \  }}|\  }}||z
  }	||z
  }
dd„} ||||	¬¦  «        } ||||
¬¦  «        }t          j        ||¦  «        \  }}t          j        ||z   d	|¦  «        }t          j        ||z   d	|¦  «        }t          j        ||||gd
¬¦  «                             d
d¦  «        }|S )aÉ  
        Generate bounding boxes defining the coordinates of image slices with overlap.

        Args:
            resolution_wh: Image resolution `(width, height)`.
            slice_wh: Size of each slice `(width, height)`.
            overlap_wh: Overlap size between slices `(width, height)`.

        Returns:
            Array of shape `(num_slices, 4)` with each row as
                `(x_min, y_min, x_max, y_max)` coordinates for a slice.
        Ú
image_sizer   Ú
slice_sizeÚstrider#   ú	list[int]c                óH  — | |k    rdgS ||k    r5t          t          j        d| |¦  «                             ¦   «         ¦  «        S | |z
  }t          t          j        d||¦  «                             ¦   «         ¦  «        }|r|d         |k    r|                     |¦  «         |S )Nr   éÿÿÿÿ)r‚   rJ   ÚarangeÚtolistr‹   )rû   rü   rý   Ú
last_startÚstartss        r)   Ú_compute_axis_startsz>InferenceSlicer._generate_offset.<locals>._compute_axis_startsG  s§   € ð
 ˜ZÒ'Ð'Ø�s�
à˜Ò#Ð#Ý�BœI a¨°VÑ<Ô<×CÒCÑEÔEÑFÔFÐFà# jÑ0ˆJÝ $¥R¤Y¨q°*¸fÑ%EÔ%E×%LÒ%LÑ%NÔ%NÑ OÔ OˆFØð *˜V BœZ¨:Ò5Ð5Ø—’˜jÑ)Ô)Ð)ØˆMr+   )rû   rü   rý   r   r   )Úaxisé   )rû   r   rü   r   rý   r   r#   rþ   )rJ   ÚmeshgridÚclipÚstackÚreshape)r;   rW   rY   rã   rä   Úimage_widthÚimage_heightÚoverlap_widthÚoverlap_heightÚstride_xÚstride_yr  Úx_startsÚy_startsrÙ   rÚ   rÛ   rÜ   rŽ   s                      r)   r�   z InferenceSlicer._generate_offset.  s  € ð$ %-Ñ!ˆ�\Ø$1Ñ!ˆ�\Ø(2Ñ%ˆ�~à Ñ.ˆØ .Ñ0ˆð	ð 	ð 	ð 	ð" (Ð'Ø"Ø"Øð
ñ 
ô 
ˆð
 (Ð'Ø#Ø#Øð
ñ 
ô 
ˆõ ”{ 8¨XÑ6Ô6‰ˆˆuÝ”˜ Ñ+¨Q°Ñ<Ô<ˆÝ”˜ Ñ,¨a°Ñ>Ô>ˆå$&¤HØ�E˜5 %Ð(Øð%
ñ %
ô %
÷ Š'�"�a‰.Œ.ð 	ð
 ˆr+   c                óš   — |\  }}| \  }}|dk     s|dk     rt          d|› �¦  «        ‚||k    s||k    rt          d|› d| › d�¦  «        ‚d S )Nr   z=Overlap values must be greater than or equal to 0. Received: zo`overlap_wh` must be smaller than `slice_wh` in both dimensions to keep a positive stride. Received overlap_wh=z, slice_wh=ú.)rM   )rW   rY   rø   rù   rß   rà   s         r)   rg   z!InferenceSlicer._validate_overlapn  s¢   € ð
  *Ñˆ	�9Ø#Ñˆ�à�qŠ=ˆ=˜I¨šM˜MÝð*Ø'ð*ð *ñô ð ð
 ˜ÒÐ 9°Ò#7Ð#7Ýð(ØBLð(ð (à$ð(ð (ð (ñô ð ð $8Ð#7r+   N)rU   rV   rW   rX   rY   rX   rZ   r[   r\   r]   r^   r_   r`   r   ra   rb   rc   r   )r1   ru   r#   r   )r�   rž   r1   ru   r#   r   )r�   rž   r1   ru   r#   r¦   )r³   r´   r#   rµ   )r1   ru   r#   rº   )r£   r   r#   r   )r1   ru   r:   r$   r#   r   )r1   ru   rŽ   rê   r#   rž   )rW   rX   r#   rº   )rY   rX   r#   rº   )r;   rº   rW   rº   rY   rº   r#   r$   )rW   rº   rY   rº   r#   rµ   )r,   r-   r.   r/   r   rÀ   r   ÚIOUrt   r�   r‰   r    r¯   r€   r¡   rŠ   rƒ   Ústaticmethodre   rf   r�   rg   r'   r+   r)   rS   rS   j   sŒ  € € € € € ð[ð [ðF +.Ø,/Ø.;Ô.OØ"Ø.;Ô.?ØØ#Øð/2ð /2ð /2ð /2ð /2ðbQ>ð Q>ð Q>ð Q>ðfð ð ð ð25(ð 5(ð 5(ð 5(ðnð ð ð ð&.ð .ð .ð .ð ð ð ð ð(Nð Nð Nð Nð`V
ð V
ð V
ð V
ðp ð
ð 
ð 
ñ „\ð
ð0 ð
ð 
ð 
ñ „\ð
ð2 ð=ð =ð =ñ „\ð=ð~ ðð ð ñ „\ðð ð r+   rS   )r1   r2   r#   r3   r&   )r9   r   r:   r$   r;   r<   r#   r   )3Ú
__future__r   rj   r†   Úcollections.abcr   Úconcurrent.futuresr   Ú	functoolsr   Útypingr   r   r	   r
   r   r   ÚnumpyrJ   Únumpy.typingrH   Úsupervision.configr   r   Ú"supervision.detection.compact_maskr   Úsupervision.detection.corer   Ú!supervision.detection.utils.boxesr   r   Ú$supervision.detection.utils.internalr   Ú'supervision.detection.utils.iou_and_nmsr   r   Ú!supervision.detection.utils.masksr   Úsupervision.draw.baser   Úsupervision.utils.imager   r   Úsupervision.utils.internalr   Úsupervision.utils.iterablesr   r   r8   rQ   rS   r'   r+   r)   ú<module>r*     sH  ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø Ð Ð Ð Ð Ð Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ Hàð !Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð à TÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ :Ð :Ð :Ð :Ð :Ð :Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ GÐ GÐ GÐ GÐ GÐ GØ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PØ 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø +Ð +Ð +Ð +Ð +Ð +Ø GÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ :Ð :Ð :Ð :Ð :Ð :Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6ð ð9ð 9ð 9ð 9ð 9˜Hñ 9ô 9ñ Ôð9ðð ð ð ð" -1ð,ð ,ð ,ð ,ð ,ð^Wð Wð Wð Wð Wñ Wô Wð Wð Wð Wr+   