§
    >²¸jRñ  ã                  ó&  — d dl m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 d dlZd dlm	Z d dlmZ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 d dlm Z  d dl!m"Z" e
rd dl#m$Z$ dEd„Z%dFd„Z&de j'        fdGd!„Z(e j'        fdHd%„Z)e j'        fdId*„Z*dJd.„Z+dKd2„Z,dLd5„Z-e j'        fdMd8„Z. ee)d9d:¬;¦  «        dNd<„¦   «         Z/e G d=„ d>¦  «        ¦   «         Z0 eej1        d?d@¬;¦  «         edA¬B¦  «         G dC„ dD¦  «        ¦   «         ¦   «         Z2dS )Oé    )ÚannotationsN)ÚCallable)Ú	dataclass)ÚPath)ÚTYPE_CHECKINGÚAnyÚcast)Ú
TargetModeÚ
deprecatedÚdeprecated_classÚvoid)ÚORIENTED_BOX_COORDINATES)ÚDetectionDataset)Ú
Detections)Úbox_iou_batchÚoriented_box_iou_batch)ÚMetricTarget)Ú_greedy_match)ÚFigureÚmetric_targetr   ÚreturnÚNonec                óD   — | t           j        k    rt          d¦  «        ‚d S )NzBMetricTarget.MASKS is not currently supported for ConfusionMatrix.)r   ÚMASKSÚ
ValueError©r   s    úm/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/metrics/detection.pyÚ_assert_supported_targetr       s-   € Ø�Ô*Ò*Ð*ÝØPñ
ô 
ð 	
ð +Ð*ó    Úvaluesúnpt.NDArray[np.float32]Únum_classesÚintÚroleÚstrúnpt.NDArray[np.int64]c                ó  — | j         dk    r t          j        | t          j        ¬¦  «        S t          j        | ¦  «        }| t          j        | ¦  «        k    }t          j        ||z  ¦  «        st          |› d�¦  «        ‚|                      t          j        ¦  «        }|dk     ||k    z  }t          j	        |¦  «        rGt          j
        ||         ¦  «                             ¦   «         }t          |› d|dz
  › d|› d�¦  «        ‚|S )zBReturn class ids that are safe to use as confusion-matrix indexes.r   ©Údtypez# class ids must be finite integers.z class ids must be in [0, é   z], got ú.)ÚsizeÚnpÚasarrayÚint64ÚisfiniteÚfloorÚallr   ÚastypeÚanyÚuniqueÚtolist)r    r"   r$   ÚfiniteÚintegralÚ	class_idsÚinvalidÚinvalid_valuess           r   Ú_validated_class_idsr<   '   s
  € ð „{�aÒÐÝŒz˜&­¬Ð1Ñ1Ô1Ð1åŒ[˜Ñ Ô €FØ�œ &Ñ)Ô)Ò)€HÝŒ6�&˜8Ñ#Ñ$Ô$ð GÝ˜DÐEÐEÐEÑFÔFÐFà—’�bœhÑ'Ô'€IØ˜1Š} ¨kÒ!9Ñ:€GÝ	„vˆg�„ð 
Ýœ 9¨WÔ#5Ñ6Ô6×=Ò=Ñ?Ô?ˆÝØÐXÐX¨{¸Q©ÐXÐXÀ~ÐXÐXÐXñ
ô 
ð 	
ð Ðr   FÚ
detectionsr   Úwith_confidenceÚboolc                óP  — t          |¦  «         | j        €t          d¦  «        ‚|t          j        k    �r6| j                             t          ¦  «        }|€Lt          | ¦  «        dk    rt          dt          › d�¦  «        ‚t          j
        dt          j        ¬¦  «        }nît          j        |t          j        ¬¦  «        }|j        dk    r)|j        d	d…         d
k    r|                     dd¦  «        }|j        t          | ¦  «        dz  k    rCt          dt          › dt          | ¦  «        dz  › dt          | ¦  «        › d|j        › d�	¦  «        ‚|                     dd¦  «        }n%t          j        | j        t          j        ¬¦  «        }|t          j        | j                             t          j        ¦  «        d	¦  «        g}|rC| j        €t          d¦  «        ‚|                     t          j        | j        d	¦  «        ¦  «         t          j        |d	¬¦  «        }|S )a©
  
    Convert Supervision Detections to a numpy tensor for metric computation.

    Args:
        detections: Detections/Targets in the format of sv.Detections.
        with_confidence: Whether to include confidence as the last column.
        metric_target: The type of detection data to use.
            Supports `MetricTarget.BOXES` and
            `MetricTarget.ORIENTED_BOUNDING_BOXES`.

    Returns:
        Detections as a float32 numpy array. Shape depends on `metric_target`
        and `with_confidence`:

        | `metric_target`                        | `with_confidence` | shape     |
        |----------------------------------------|-------------------|-----------|
        | `MetricTarget.BOXES`                   | `False`           | `(N, 5)`  |
        | `MetricTarget.BOXES`                   | `True`            | `(N, 6)`  |
        | `MetricTarget.ORIENTED_BOUNDING_BOXES` | `False`           | `(N, 9)`  |
        | `MetricTarget.ORIENTED_BOUNDING_BOXES` | `True`            | `(N, 10)` |

        Column layout:

        - `BOXES`: ``[x_min, y_min, x_max, y_max, class_id [, confidence]]``
        - `ORIENTED_BOUNDING_BOXES`:
          ``[x1, y1, x2, y2, x3, y3, x4, y4, class_id [, confidence]]``

    Raises:
        ValueError: If `metric_target` is `MetricTarget.MASKS`.
        ValueError: If `detections.class_id` is `None`.
        ValueError: If `with_confidence=True` and `detections.confidence` is `None`.
        ValueError: If `metric_target` is `MetricTarget.ORIENTED_BOUNDING_BOXES`
            and `detections.data` does not contain `ORIENTED_BOX_COORDINATES`,
            or if the stored array does not have exactly `N * 8` elements.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> from supervision.metrics.core import MetricTarget
        >>> from supervision.config import ORIENTED_BOX_COORDINATES
        >>> detections = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
        ...     class_id=np.array([0]),
        ...     confidence=np.array([0.9]),
        ... )
        >>> tensor = detections_to_tensor(detections, with_confidence=True)
        >>> tensor.shape
        (1, 6)
        >>> obb_coords = np.array([[0, 0, 10, 0, 10, 10, 0, 10]], dtype=np.float32)
        >>> det_obb = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
        ...     class_id=np.array([0]),
        ...     data={ORIENTED_BOX_COORDINATES: obb_coords},
        ... )
        >>> tensor_obb = detections_to_tensor(
        ...     det_obb, metric_target=MetricTarget.ORIENTED_BOUNDING_BOXES
        ... )
        >>> tensor_obb.shape
        (1, 9)

        ```
    NzCConfusionMatrix can only be calculated for Detections with class_idr   z'ORIENTED_BOUNDING_BOXES requested, but z  is missing from detections.data)r   é   r(   é   r*   )é   é   éÿÿÿÿrA   z	Expected z to contain z elements (N=z& detections x 8 coordinates), but got z>. Each OBB must be stored as [x1, y1, x2, y2, x3, y3, x4, y4].zEConfusionMatrix can only be calculated for Detections with confidence©Úaxis)r   Úclass_idr   r   ÚORIENTED_BOUNDING_BOXESÚdataÚgetr   Úlenr-   ÚemptyÚfloat32r.   ÚndimÚshapeÚreshaper,   ÚxyxyÚexpand_dimsr3   Ú
confidenceÚappendÚconcatenate)r=   r>   r   ÚobbÚbox_dataÚobb_arrÚarrays_to_concatÚresults           r   Údetections_to_tensorr\   ?   sL  € õH ˜]Ñ+Ô+Ð+àÔÐ"ÝØQñ
ô 
ð 	
ð
 �Ô<Ò<Ñ<ØŒo×!Ò!Õ":Ñ;Ô;ˆØˆ;Ý�:‰Œ Ò"Ð"Ý ðRÝ/ðRð Rð Rñô ð õ ”x ­b¬jÐ9Ñ9Ô9ˆHˆHå”j ­B¬JÐ7Ñ7Ô7ˆGàŒ|˜qÒ Ð  W¤]°1°2°2Ô%6¸&Ò%@Ð%@Ø!Ÿ/š/¨"¨aÑ0Ô0�ØŒ|�s :™œ°Ñ2Ò2Ð2Ý ðSÕ 8ð Sð SÝ˜:‘”¨Ñ*ðSð Så˜j™/œ/ðSð Sð  'œ|ðSð Sð Sñô ð ð —’ r¨1Ñ-Ô-ˆHˆHå”:˜jœoµR´ZÐ@Ñ@Ô@ˆð 	Ý
Œ�zÔ*×1Ò1µ"´*Ñ=Ô=¸qÑAÔAðÐð
 ð JØÔ Ð(ÝØWñô ð ð 	×Ò¥¤¨zÔ/DÀaÑ HÔ HÑIÔIÐIå&(¤nÐ5EÈAÐ&NÑ&NÔ&N€FØ€Mr   Úpredictionsúlist[npt.NDArray[np.float32]]Útargetsc           	     óú  — t          | ¦  «        t          |¦  «        k    r0t          dt          | ¦  «        › dt          |¦  «        › d�¦  «        ‚t          | ¦  «        dk    �rt          | d         t          j        ¦  «        r t          |d         t          j        ¦  «        s<t          dt          | d         ¦  «        › dt          |d         ¦  «        › d�¦  «        ‚|t          j        k    rdnd	}|t          j        k    rd
nd}| d         j        d         |k    r!t          d|› d| d         j        › d�¦  «        ‚|d         j        d         |k    r#t          d|› d|d         j        › d�¦  «        ‚dS dS )z8
    Checks for shape consistency of input tensors.
    zNumber of predictions (z) andtargets (z) must be equal.r   z;Predictions and targets must be lists of numpy arrays. Got z and ú	 instead.é
   é   é	   é   r*   z Predictions must have shape (N, ú). Got úTargets must have shape (N, N)	rL   r   Ú
isinstancer-   ÚndarrayÚtyper   rI   rP   )r]   r_   r   Úexpected_pred_colsÚexpected_target_colss        r   Ú_validate_input_tensorsrm   µ   só  € õ ˆ;ÑÔ�3˜w™<œ<Ò'Ð'Ýð7¥c¨+Ñ&6Ô&6ð 7ð 7Ý˜G™œð7ð 7ð 7ñ
ô 
ð 	
õ ˆ;ÑÔ˜!ÒÑÝ˜+ aœ.­"¬*Ñ5Ô5ð 	½ZØ�AŒJ�œ
ñ>
ô >
ð 	õ ðNÝ˜K¨œNÑ+Ô+ðNð NÝ26°w¸q´zÑ2BÔ2BðNð Nð Nñô ð ð  ¥<Ô#GÒGÐGˆBˆBÈQð 	ð ¥,Ô"FÒFÐFˆAˆAÈAð 	ð �qŒ>Ô Ô"Ð&8Ò8Ð8Ýð7Ð3Eð 7ð 7Ø" 1”~Ô+ð7ð 7ð 7ñô ð ð �1Œ:Ô˜AÔÐ"6Ò6Ð6Ýð3Ð/Cð 3ð 3Ø˜q”zÔ'ð3ð 3ð 3ñô ð ð- Ðð* 7Ð6r   Úconf_thresholdÚfloatÚiou_thresholdú)tuple[Detections, Detections, Detections]c                óÖ  — | j         €t          d¦  «        ‚|j         €t          d¦  «        ‚|j         }| j        €| }n>t          j        | j        t          j        ¬¦  «        }|                      ||k    ¦  «        }|j         }|€t          d¦  «        ‚t          |¦  «        }	t          |¦  «        }
g }g }g }|	dk    rZt          t          |
¦  «        ¦  «        }|                     |¦  «        |                     |¦  «        |                     |¦  «        fS |
dk    rZt          t          |	¦  «        ¦  «        }|                     |¦  «        |                     |¦  «        |                     |¦  «        fS |t          j        k    r°t          t          j        |j        t                   t          j        ¬¦  «                             t          |¦  «        d¦  «        t          j        |j        t                   t          j        ¬¦  «                             t          |¦  «        d¦  «        ¬¦  «        }nt!          |j        |j        ¬¦  «        }t          j        ||k    ¦  «        \  }}t          j        |	t(          ¬¦  «        }t          j        |
t(          ¬¦  «        }g }g }t          |¦  «        dk    rÔ|||f         }||         ||         k    }t          j        | | f¦  «        }|D ]�}t-          ||         ¦  «        }t-          ||         ¦  «        }||         s||         rŒ=d||<   d||<   ||         }||         }||k    r|                     |¦  «         Œs|                     |¦  «         |                     |¦  «         Œž|                     t          j        | ¦  «                             ¦   «         ¦  «         |                     t          j        | ¦  «                             ¦   «         ¦  «         |                     |¦  «         |                     |¦  «         |                     |¦  «        |                     |¦  «        |                     |¦  «        fS )	ar  
    Split detections into true positives, false positives, and false negatives.

    Matching follows the same attribution logic as
    ``ConfusionMatrix.evaluate_detection_batch``:
    - matches are computed globally across classes
    - same-class matches are prioritized
    - higher-IoU matches are preferred
    - each prediction and target can be matched at most once

    Cross-class spatial matches are treated as:
    - false positives for the prediction
    - false negatives for the target

    Args:
        predictions: Predicted detections for a single image.
        targets: Ground-truth detections for a single image.
        conf_threshold: Confidence threshold; predictions below this are excluded.
        iou_threshold: IoU threshold; candidate pairs below this are not matched.
        metric_target: Coordinate representation to use for IoU computation.
            Use ``MetricTarget.ORIENTED_BOUNDING_BOXES`` for rotated-box datasets.

    Returns:
        A 3-tuple ``(true_positives, false_positives, false_negatives)`` where
        each element is a ``Detections`` instance sliced from the input arrays.
    Nz)Predictions must contain class_id values.z%Targets must contain class_id values.r(   r   rA   ©Ú
boxes_trueÚboxes_detectionT)rH   r   rT   r-   r.   rN   ÚselectrL   ÚlistÚranger   rI   r   rJ   r   rQ   r   rR   ÚwhereÚzerosr?   Úlexsortr#   rU   ÚextendÚflatnonzeror6   )r]   r_   rn   rp   r   Útarget_class_idsÚfiltered_predictionsÚprediction_confidenceÚfiltered_prediction_class_idsÚprediction_countÚtarget_countÚ
tp_indicesÚ
fp_indicesÚ
fn_indicesÚ
iou_matrixÚtarget_candidate_indicesÚprediction_candidate_indicesÚmatched_predictionsÚmatched_targetsÚcross_class_prediction_indicesÚcross_class_target_indicesÚcandidate_iousÚsame_class_candidatesÚcandidate_orderÚcandidate_indexÚtarget_indexÚprediction_indexÚprediction_classÚtarget_classs                                r   Ú_split_detections_by_outcomer–   Þ   s   € ðD ÔÐ#ÝÐDÑEÔEÐEàÔÐÝÐ@ÑAÔAÐAàÔ'ÐàÔÐ%Ø*ÐÐå "¤
¨;Ô+AÍÌÐ TÑ TÔ TÐØ*×1Ò1Ø! ^Ò3ñ 
ô  
Ðð %9Ô$AÐ!Ø$Ð,ÝÐDÑEÔEÐEåÐ/Ñ0Ô0ÐÝ�w‘<”<€Là€JØ€JØ€Jà˜1ÒÐÝ�% Ñ-Ô-Ñ.Ô.ˆ
à ×'Ò'¨
Ñ3Ô3Ø ×'Ò'¨
Ñ3Ô3Ø�NŠN˜:Ñ&Ô&ð
ð 	
ð �qÒÐÝ�%Ð 0Ñ1Ô1Ñ2Ô2ˆ
à ×'Ò'¨
Ñ3Ô3Ø ×'Ò'¨
Ñ3Ô3Ø�NŠN˜:Ñ&Ô&ð
ð 	
ð �Ô<Ò<Ð<Ý+Ý”zØ”Õ5Ô6½b¼jðñ ô çŠg•c˜'‘l”l AÑ&Ô&ÝœJØ$Ô)Õ*BÔCÍ2Ì:ðñ ô çŠg•cÐ.Ñ/Ô/°Ñ3Ô3ð
ñ 
ô 
ˆ
ˆ
õ #Ø”|Ø0Ô5ð
ñ 
ô 
ˆ
õ
 >@¼XØ�]Ò"ñ>ô >Ñ:ÐÐ:õ 24´Ð:JÕRVÐ1WÑ1WÔ1WÐÝ-/¬X°lÍ$Ð-OÑ-OÔ-O€Oà02Ð"Ø,.Ðå
Ð#Ñ$Ô$ qÒ(Ð(Ø#Ø$Ø(ð*ô
ˆð Ð5Ô6Ø,Ð-IÔJòKð 	õ
 œ*à�Ø&Ð&ðñ
ô 
ˆð  /ð 	@ð 	@ˆOÝÐ7¸ÔHÑIÔIˆLÝ"Ð#?ÀÔ#PÑQÔQÐà"Ð#3Ô4ð ¸ÈÔ8Uð Øà48ÐÐ 0Ñ1Ø,0ˆO˜LÑ)à<Ð=MÔNÐØ+¨LÔ9ˆLà <Ò/Ð/Ø×!Ò!Ð"2Ñ3Ô3Ð3Ð3à.×5Ò5Ð6FÑGÔGÐGØ*×1Ò1°,Ñ?Ô?Ð?Ð?à×Ò•b”nÐ&9Ð%9Ñ:Ô:×AÒAÑCÔCÑDÔDÐDØ×Ò•b”n oÐ%5Ñ6Ô6×=Ò=Ñ?Ô?Ñ@Ô@Ð@à×ÒÐ4Ñ5Ô5Ð5Ø×ÒÐ0Ñ1Ô1Ð1ð 	×#Ò# JÑ/Ô/Ø×#Ò# JÑ/Ô/Ø�Š�zÑ"Ô"ðð r   Úclass_namesúlist[str] | Noneú	list[str]c                ó”  — | j         €dgt          | ¦  «        z  S g }t          | j         ¦  «        D ]–\  }}|�@dt          |¦  «        cxk    rt          |¦  «        k     rn n|t          |¦  «                 }nt	          t          |¦  «        ¦  «        }d}| j        �d| j        |         d›�}|                     |› |› �¦  «         Œ—|S )aè  Build per-detection label strings for annotation panels.

    Produces labels like ``"cat 0.95"`` (class name + confidence when available)
    or numeric class-id strings when ``class_names`` is ``None``.

    Args:
        detections: Detections whose labels to build.
        class_names: Optional list mapping class integer ids to name strings.

    Returns:
        List of label strings, one per detection. Returns empty strings when
        ``detections.class_id`` is ``None``.
    NÚ r   ú ú.2f)rH   rL   Ú	enumerater#   r%   rT   rU   )r=   r—   ÚlabelsÚindexrH   Úclass_labelrT   s          r   Ú_build_error_labelsr¢   w  sè   € ð" ÔÐ"Øˆt•c˜*‘o”oÑ%Ð%à€FÝ$ ZÔ%8Ñ9Ô9ð 
4ð 
4‰ˆˆxØÐ" q­C°©M¬MÐ'LÐ'LÒ'LÐ'L½CÀÑ<LÔ<LÒ'LÐ'LÐ'LÐ'LÐ'LØ%¥c¨(¡m¤mÔ4ˆKˆKå�c (™mœmÑ,Ô,ˆKàˆ
ØÔ Ð,Ø?˜ZÔ2°5Ô9Ð?Ð?Ð?ˆJà�Š˜Ð2 jÐ2Ð2Ñ3Ô3Ð3Ð3à€Mr   Úsceneúnpt.NDArray[np.uint8]ú tuple[int, float, int, int, int]c                óº  — | j         dd…         \  }}t          t          ||¦  «        d¦  «        }d}t          dt          |d|z  z  ¦  «        ¦  «        }t          dt          |dz  ¦  «        ¦  «        }t	          t          d|dz  ¦  «        ¦  «        }t          dt          |d	z  ¦  «        ¦  «        }t          d
t          |dz  ¦  «        ¦  «        }	||||	|fS )aA  Compute adaptive annotation parameters scaled to the panel size.

    Args:
        scene: The image panel for which to compute parameters.

    Returns:
        A 5-tuple ``(box_thickness, text_scale, text_thickness, text_padding,
        font_size)`` where all values are ``int`` except ``text_scale`` (``float``).
    NrD   r*   é   é   re   ç      ð?g      4@g      .@rc   rB   )rP   ÚmaxÚminÚroundro   )
r£   ÚheightÚwidthÚ
panel_sizeÚgrid_factorÚ	font_sizeÚbox_thicknessÚ
text_scaleÚtext_thicknessÚtext_paddings
             r   Ú_get_annotation_parametersr¶   ›  sÕ   € ð ”K   ”O�M€FˆEÝ•S˜ Ñ'Ô'¨Ñ+Ô+€JØ€Kå�B�˜j¨B°Ñ,<Ñ=Ñ>Ô>Ñ?Ô?€IÝ˜�5 ¨Q¡Ñ/Ô/Ñ0Ô0€MÝ•s˜3 	¨DÑ 0Ñ1Ô1Ñ2Ô2€JÝ˜�E )¨dÑ"2Ñ3Ô3Ñ4Ô4€NÝ�q�% 	¨A¡Ñ.Ô.Ñ/Ô/€Là˜* n°lÀIÐMÐMr   ÚtitleÚannotation_parametersc           
     óâ  — ddl m} ddlm}m} ddlm} ddlm}	 |  	                    ¦   «         }
|\  }}}}}t          |¦  «        dk    r« ||	j        |j        |¬¦  «        } ||	j        |j        |||¬¦  «        }t          ||¦  «        }|                     |
|¦  «        }
t          t           j        t$          j                 |                     t          t(          |
¦  «        ||¬¦  «        ¦  «        }
t+          t-          d	|d
z  ¦  «        ¦  «        }t-          dt/          |dz  ¦  «        ¦  «        }|
j        dd…         \  }}|                     ||j        ||¦  «        \  \  }}}t-          dt7          |||z
  dz
  ¦  «        ¦  «        }t-          ||z   d¦  «        }t7          |t-          ||z
  dz
  d¦  «        ¦  «        }|                     |
|||f|j        |d||j        ¦  «         |
}|S )a  Render detections onto a copy of ``scene`` with a title overlay.

    Args:
        scene: Source image panel (not mutated).
        detections: Detections to annotate on the panel.
        title: Text label rendered in the top-left corner of the panel.
        class_names: Optional list mapping class integer ids to name strings.
        annotation_parameters: Pre-computed parameters from
            ``_get_annotation_parameters``.

    Returns:
        Annotated copy of ``scene`` as a ``np.uint8`` array.
    r   ©Ú_cv2)ÚBoxAnnotatorÚLabelAnnotator)ÚColorLookup)ÚColorPalette)ÚcolorÚcolor_lookupÚ	thickness)rÀ   rÁ   r³   r´   rµ   ©rŸ   r©   g      2@rD   rA   Nr*   )éð   rÄ   rÄ   )Úsupervisionr»   Úsupervision.annotators.corer¼   r½   Úsupervision.annotators.utilsr¾   Úsupervision.draw.colorr¿   ÚcopyrL   ÚDEFAULTÚCLASSr¢   Úannotater	   ÚnptÚNDArrayr-   Úuint8r   ro   rª   r¬   rP   ÚgetTextSizeÚFONT_HERSHEY_SIMPLEXr«   ÚputTextÚLINE_AA)r£   r=   r·   r—   r¸   Úcv2r¼   r½   r¾   r¿   Úpanelr²   r³   r´   rµ   r±   Úbox_annotatorÚlabel_annotatorrŸ   Útitle_scaleÚtitle_thicknessÚpanel_heightÚpanel_widthÚtitle_widthÚtitle_heightÚtitle_baselineÚtitle_xÚtitle_yÚpanel_arrays                                r   Ú_annotate_detection_panelrâ   ´  sc  € ð(ð ð ð ð ð ð IÐHÐHÐHÐHÐHÐHÐHØ8Ð8Ð8Ð8Ð8Ð8Ø3Ð3Ð3Ð3Ð3Ð3à�JŠJ‰LŒL€Eð 	ñ G€M�:˜~¨|¸Yõ ˆ:�„˜ÒÐØ$˜ØÔ&Ø$Ô*Ø#ð
ñ 
ô 
ˆð
 )˜.ØÔ&Ø$Ô*Ø!Ø)Ø%ð
ñ 
ô 
ˆõ % Z°Ñ=Ô=ˆØ×&Ò& u¨jÑ9Ô9ˆÝÝŒK�œÔ!Ø×$Ò$¥T­#¨uÑ%5Ô%5°zÈ&Ð$ÑQÔQñ
ô 
ˆõ
 �˜C ¨TÑ!1Ñ2Ô2Ñ3Ô3€KÝ˜!�U 9¨q¡=Ñ1Ô1Ñ2Ô2€OØ %¤¨B¨Q¨B¤Ñ€L�+Ø25·/²/ØØÔ ØØñ	3ô 3Ñ/Ñ€[�, õ �!•S˜ {°[Ñ'@À1Ñ'DÑEÔEÑFÔF€GÝ�, Ñ-¨qÑ1Ô1€GÝ�'�3˜|¨nÑ<¸qÑ@À!ÑDÔDÑEÔE€Gà‡K‚KØØØ	�'ÐØÔ ØØØØŒñ	ô 	ð 	ð */€KØÐr   Ú	save_pathr   c           
     ó  — ddl m} t          |||||¬¦  «        \  }	}
}t          | ¦  «        }t	          | |d||¬¦  «        }t	          | |	d||¬¦  «        }t	          | |
d||¬¦  «        }t	          | |d||¬¦  «        }t          j        ||fd	¬
¦  «        }t          j        ||fd	¬
¦  «        }t          j        ||fd¬
¦  «        }|j        d         dz  }|j        d	         dz  }t          d	t          dt          ||¦  «        dz  ¦  «        ¦  «        }| 
                    |d|j        d	         d	z
  |j        d         d	z
  fd|¬¦  «         |j        d	         dz  }|j        d         dz  }|                     ||df||j        d         d	z
  fd|¦  «         |                     |d|f|j        d	         d	z
  |fd|¦  «         |                     t          |¦  «        |¦  «        }|s"t          j        d|› d�t           d¬¦  «         dS dS )a>  Build and save a 2x2 GT/TP/FP/FN mosaic for one image.

    Splits ``predictions`` into true-positive, false-positive, and false-negative
    groups using the same matching logic as
    ``ConfusionMatrix.evaluate_detection_batch``, renders four annotation panels,
    concatenates them into a 2x2 grid, and writes the result to ``save_path``.

    A ``UserWarning`` is emitted if ``cv2.imwrite`` fails (e.g. unsupported
    extension or permission error); the benchmark loop continues regardless.

    Args:
        scene: The original image for this dataset entry.
        predictions: Raw model predictions for ``scene``.
        targets: Ground-truth annotations for ``scene``.
        save_path: Destination file path for the mosaic image.
        conf_threshold: Confidence threshold forwarded to
            ``_split_detections_by_outcome``.
        iou_threshold: IoU threshold forwarded to ``_split_detections_by_outcome``.
        class_names: Optional list mapping class integer ids to name strings.
        metric_target: Coordinate representation used for IoU matching.
    r   rº   )r]   r_   rn   rp   r   zGround Truth)r£   r=   r·   r—   r¸   zTrue PositiveszFalse PositiveszFalse Negativesr*   rF   rD   rA   é    )r   r   )éÿ   ræ   ræ   )rÂ   z%Failed to write validation image to 'z'.©Ú
stacklevelN)rÅ   r»   r–   r¶   râ   r-   rV   rP   rª   r«   Ú	rectangleÚlineÚimwriter%   ÚwarningsÚwarnÚUserWarning)r£   r]   r_   rã   rn   rp   r—   r   rÔ   Útp_predictionsÚfp_predictionsÚ
fn_targetsr¸   Úgt_panelÚtp_panelÚfp_panelÚfn_panelÚtop_rowÚ
bottom_rowr[   rÚ   rÛ   Údivider_thicknessÚcenter_xÚcenter_yÚwrite_successs                             r   Ú(_save_detection_validation_visualizationrü     sÄ  € ð>ð ð ð ð ð õ 2NØØØ%Ø#Ø#ð2ñ 2ô 2Ñ.€N�N Jõ 7°uÑ=Ô=Ðå(ØØØØØ3ðñ ô €Hõ )ØØ!ØØØ3ðñ ô €Hõ )ØØ!ØØØ3ðñ ô €Hõ )ØØØØØ3ðñ ô €Hõ Œn˜h¨Ð1¸Ð:Ñ:Ô:€GÝ” ¨8Ð 4¸1Ð=Ñ=Ô=€JÝŒ^˜W jÐ1¸Ð:Ñ:Ô:€Fà”< ”? aÑ'€LØ”,˜q”/ QÑ&€KÝ˜A�s 1¥c¨,¸Ñ&DÔ&DÈÑ&JÑKÔKÑLÔLÐà‡M‚MØØØ	Œ�aŒ˜1Ñ	˜fœl¨1œo°Ñ1Ð2ØØ#ð ñ ô ð ð Œ|˜AŒ !Ñ#€HØŒ|˜AŒ !Ñ#€HØ‡H‚HØØ	�1ˆØ	�6”< ”? QÑ&Ð'ØØñô ð ð ‡H‚HØØ	
ˆHˆØ	Œ�aŒ˜1Ñ	˜hÐ'ØØñô ð ð —K’K¥ I¡¤°Ñ7Ô7€MØð 
ÝŒØA°IÐAÐAÐAÝØð	
ñ 	
ô 	
ð 	
ð 	
ð 	
ð
ð 
r   z0.29.0z0.32.0)ÚtargetÚdeprecated_inÚ	remove_inc                ó&   — t          | |¦  «         d S ©N)r   ©r]   r_   s     r   Úvalidate_input_tensorsr  x  s   € õ 	ˆ�gÑÔÐÐÐr   c                  ó6  — e Zd ZU dZded<   ded<   ded<   ded<   ej        Zd	ed
<   d2d„ZdZ	e
ddej        fd3d„¦   «         Ze
ddej        fd4d„¦   «         Zeej        fd5d„¦   «         Zed6d„¦   «         Ze
ddej        fddœd7d&„¦   «         Z	 	 	 	 	 d8d9d1„ZdS ):ÚConfusionMatrixu¯  
    Confusion matrix for object detection tasks.

    Attributes:
        matrix: An 2D `np.ndarray` of shape `(len(classes) + 1, len(classes) + 1)`
            containing the number of `TP`, `FP`, `FN` and `TN` for each class.
        classes: Model class names.
        conf_threshold: Detection confidence threshold between `0` and `1`.
            Detections with lower confidence will be excluded from the matrix.
        iou_threshold: Detection IoU threshold between `0` and `1`.
            Detections with lower IoU will be classified as `FP`.
        metric_target: The type of detection data used for IoU computation.
            Informational metadata set by `from_detections` and `from_tensors`.
            Excluded from `__eq__` comparisons â€” two `ConfusionMatrix` instances
            with identical `matrix`, `classes`, `conf_threshold`, and
            `iou_threshold` compare as equal regardless of `metric_target`.
    únpt.NDArray[np.int32]Úmatrixr™   Úclassesro   rn   rp   r   r   ÚotherÚobjectr   r?   c                óØ   — t          |t          ¦  «        st          S t          j        | j        |j        ¦  «        o/| j        |j        k    o| j        |j        k    o| j        |j        k    S r  )	rh   r  ÚNotImplementedr-   Úarray_equalr  r  rn   rp   )Úselfr	  s     r   Ú__eq__zConfusionMatrix.__eq__ž  sk   € Ý˜%¥Ñ1Ô1ð 	"Ý!Ð!åŒN˜4œ;¨¬Ñ5Ô5ð :Ø” ¤Ò-ð:àÔ# uÔ';Ò;ð:ð Ô" eÔ&9Ò9ð		
r   Ng333333Ó?ç      à?r]   úlist[Detections]r_   c                ó   — g }g }t          ||¦  «        D ]O\  }	}
|                     t          |	d|¬¦  «        ¦  «         |                     t          |
d|¬¦  «        ¦  «         ŒP|                      ||||||¬¦  «        S )a™  
        Calculate confusion matrix based on predicted and ground-truth detections.

        Args:
            targets: Detections objects from ground-truth.
            predictions: Detections objects predicted by the model.
            classes: Model class names.
            conf_threshold: Detection confidence threshold between `0` and `1`.
                Detections with lower confidence will be excluded.
            iou_threshold: Detection IoU threshold between `0` and `1`.
                Detections with lower IoU will be classified as `FP`.
            metric_target: The type of detection data to use.
                Supports `MetricTarget.BOXES` (default) and
                `MetricTarget.ORIENTED_BOUNDING_BOXES`. When using
                `MetricTarget.ORIENTED_BOUNDING_BOXES`, each `Detections`
                object must include OBB coordinates in
                `detections.data[ORIENTED_BOX_COORDINATES]` as a float32
                array of shape `(N, 8)` (flat) or `(N, 4, 2)` (as stored by
                `from_ultralytics`); both are normalised to `(N, 8)` internally.
                `MetricTarget.MASKS` is not supported.

        Returns:
            New instance of ConfusionMatrix.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> targets = [
            ...     sv.Detections(
            ...         xyxy=np.array([[0, 0, 10, 10], [50, 50, 60, 60]]),
            ...         class_id=np.array([0, 0])
            ...     )
            ... ]
            >>> predictions = [
            ...     sv.Detections(
            ...         xyxy=np.array([[0, 0, 10, 10], [100, 100, 110, 110]]),
            ...         class_id=np.array([0, 0]),
            ...         confidence=np.array([0.9, 0.8])
            ...     )
            ... ]
            >>> confusion_matrix = sv.ConfusionMatrix.from_detections(
            ...     predictions=predictions,
            ...     targets=targets,
            ...     classes=['person']
            ... )
            >>> confusion_matrix.matrix
            array([[1, 1],
                   [1, 0]], dtype=int32)

            ```
        T)r>   r   F©r]   r_   r  rn   rp   r   ©ÚziprU   r\   Úfrom_tensors)Úclsr]   r_   r  rn   rp   r   Úprediction_tensorsÚtarget_tensorsÚ
predictionrý   s              r   Úfrom_detectionszConfusionMatrix.from_detectionsª  sÈ   € ð|  ÐØˆÝ"% k°7Ñ";Ô";ð 
	ð 
	ÑˆJ˜Ø×%Ò%Ý$Ø°ÀMðñ ô ñô ð ð
 ×!Ò!Ý$Ø¨EÀðñ ô ñô ð ð ð
 ×ÒØ*Ø"ØØ)Ø'Ø'ð  ñ 
ô 
ð 	
r   r^   c           
     ó:  — t          |¦  «         t          |||¬¦  «         t          |¦  «        }t          j        |dz   |dz   ft          j        ¬¦  «        }t          ||¦  «        D ]#\  }	}
||                      |
|	||||¬¦  «        z  }Œ$ | |||||¬¦  «        S )a$
  
        Calculate confusion matrix based on predicted and ground-truth detections.

        Args:
            predictions: Each element of the list describes a single
                image and has `shape = (M, 6)` or `shape = (M, 10)` depending on
                `metric_target`.
                If `MetricTarget.BOXES`, each row is in
                `(x_min, y_min, x_max, y_max, class, conf)` format.
                If `MetricTarget.ORIENTED_BOUNDING_BOXES`, each row is in
                `(x1, y1, x2, y2, x3, y3, x4, y4, class, conf)` format.
            targets: Each element of the list describes a single
                image and has `shape = (N, 5)` or `shape = (N, 9)` depending on
                `metric_target`.
                If `MetricTarget.BOXES`, each row is in
                `(x_min, y_min, x_max, y_max, class)` format.
                If `MetricTarget.ORIENTED_BOUNDING_BOXES`, each row is in
                `(x1, y1, x2, y2, x3, y3, x4, y4, class)` format.
            classes: Model class names.
            conf_threshold: Detection confidence threshold between `0` and `1`.
                Detections with lower confidence will be excluded.
            iou_threshold: Detection iou threshold between `0` and `1`.
                Detections with lower iou will be classified as `FP`.
            metric_target: The type of detection data to use.
                Determines expected tensor shapes (see Args above for column
                layouts). `MetricTarget.MASKS` is not supported.

        Returns:
            New instance of ConfusionMatrix.

        Examples:
            ```pycon
            >>> import supervision as sv
            >>> import numpy as np
            >>> targets = [
            ...     np.array([
            ...         [0.0, 0.0, 3.0, 3.0, 0],
            ...         [2.0, 2.0, 5.0, 5.0, 0],
            ...         [6.0, 1.0, 8.0, 3.0, 1],
            ...     ])
            ... ]
            >>> predictions = [
            ...     np.array([
            ...         [0.0, 0.0, 3.0, 3.0, 0, 0.9],
            ...         [0.1, 0.1, 3.0, 3.0, 0, 0.9],
            ...         [6.0, 1.0, 8.0, 3.0, 1, 0.8],
            ...     ])
            ... ]
            >>> confusion_matrix = sv.ConfusionMatrix.from_tensors(
            ...     predictions=predictions,
            ...     targets=targets,
            ...     classes=['person', 'dog']
            ... )
            >>> confusion_matrix.matrix
            array([[1, 0, 1],
                   [0, 1, 0],
                   [1, 0, 0]], dtype=int32)

            ```
        r   r*   r(   )r]   r_   r"   rn   rp   r   )r  r  rn   rp   r   )r   rm   rL   r-   rz   Úint32r  Úevaluate_detection_batch)r  r]   r_   r  rn   rp   r   r"   r  Ú
true_batchÚdetection_batchs              r   r  zConfusionMatrix.from_tensorsþ  sÜ   € õL 	! Ñ/Ô/Ð/Ý ¨WÀMÐRÑRÔRÐRå˜'‘l”lˆÝ(*¬Ø˜1‰_˜k¨A™oÐ.µb´hð)
ñ )
ô )
ˆõ ,/¨w¸Ñ+DÔ+Dð 	ð 	Ñ'ˆJ˜Ø�c×2Ò2Ø+Ø"Ø'Ø-Ø+Ø+ð 3ñ ô ñ ˆFˆFð ˆsØØØ)Ø'Ø'ð
ñ 
ô 
ð 	
r   r!   r"   r#   c                ó¼  ‡ ‡!‡"‡#— t          |¦  «         |t          j        k    rdnd}|t          j        k    rdnd}| j        dk    s| j        d         |k    rt          d|› d| j        › d	�¦  «        ‚|j        dk    s|j        d         |k    rt          d
|› d|j        › d	�¦  «        ‚t          j        |dz   |dz   ft          j        ¬¦  «        }|t          j        k    rdnd}	|	}
|	dz   }| dd…|f         }| ||k             }t          |¦  «        dk    r4t          |dd…|
f         |d¦  «        }|D ]}|||fxx         dz  cc<   Œ|S t          |¦  «        dk    r4t          |dd…|
f         |d¦  «        }|D ]}|||fxx         dz  cc<   Œ|S t          |dd…|
f         |d¦  «        }t          |dd…|
f         |d¦  «        }|dd…d|	…f         }|dd…d|	…f         }|t          j        k    rt          ||¬¦  «        }nt          ||¬¦  «        }||k    }t          j        |¦  «        \  Š"Š!‰"j        dk    rg }nI|‰"‰!f         Š#|‰"         }|‰!         }||k    Š t          j        ‰# ‰  f¦  «        }ˆ ˆ!ˆ"ˆ#fd„|D ¦   «         }t!          ¦   «         }t!          ¦   «         }|D ][\  }}}}||vrP||vrL||         }||         }|||fxx         dz  cc<   |                     |¦  «         |                     |¦  «         Œ\t%          |¦  «        D ]\  }}||vr|||fxx         dz  cc<   Œt%          |¦  «        D ]\  }}||vr|||fxx         dz  cc<   Œ|S )ad  
        Calculate confusion matrix for a batch of detections for a single image.

        Args:
            predictions: Batch prediction. Describes a single image and
                has `shape = (M, 6)` or `shape = (M, 10)` depending on
                `metric_target`.
                If `MetricTarget.BOXES`, each row is in
                `(x_min, y_min, x_max, y_max, class, conf)` format.
                If `MetricTarget.ORIENTED_BOUNDING_BOXES`, each row is in
                `(x1, y1, x2, y2, x3, y3, x4, y4, class, conf)` format.
            targets: Batch target labels. Describes a single image and
                has `shape = (N, 5)` or `shape = (N, 9)` depending on
                `metric_target`.
                If `MetricTarget.BOXES`, each row is in
                `(x_min, y_min, x_max, y_max, class)` format.
                If `MetricTarget.ORIENTED_BOUNDING_BOXES`, each row is in
                `(x1, y1, x2, y2, x3, y3, x4, y4, class)` format.
            num_classes: Number of classes.
            conf_threshold: Detection confidence threshold between `0` and `1`.
                Detections with lower confidence will be excluded.
            iou_threshold: Detection iou threshold between `0` and `1`.
                Detections with lower iou will be classified as `FP`.
            metric_target: The type of detection data to use.
                Determines IoU function (`box_iou_batch` vs
                `oriented_box_iou_batch`) and coordinate column count.
                `MetricTarget.MASKS` is not supported.

        Returns:
            Confusion matrix based on a single image.
        rb   rc   rd   re   rD   r*   z Predictions must have shape (M, rf   ra   rg   r(   rA   rC   Nr   ÚTargetÚ
Predictionrs   c           	     ó´   •— g | ]T}t          ‰|         ¦  «        t          ‰|         ¦  «        t          ‰|         ¦  «        t          ‰|         ¦  «        f‘ŒUS © )r#   ro   r?   )Ú.0ÚidxÚclass_matchesÚdet_indicesÚ
gt_indicesÚiouss     €€€€r   ú
<listcomp>z<ConfusionMatrix.evaluate_detection_batch.<locals>.<listcomp>Þ  sk   ø€ ð ð ð ð õ ˜
 3œÑ(Ô(Ý˜ CÔ(Ñ)Ô)Ý˜$˜sœ)Ñ$Ô$Ý˜ sÔ+Ñ,Ô,ð	ðð ð r   )r   r   rI   rO   rP   r   r-   rz   r  rL   r<   r   r   Únonzeror,   r{   ÚsetÚaddrž   )$r]   r_   r"   rn   rp   r   rk   rl   Úresult_matrixÚ
coords_dimÚclass_id_idxÚconf_idxrT   Údetection_batch_filteredÚtrue_classesÚgt_classÚdetection_classesÚ	det_classÚ
true_boxesÚdetection_boxesÚ	iou_batchÚiou_maskÚvalid_matchesÚgt_match_classesÚdet_match_classesÚsort_indicesÚmatched_gt_idxÚmatched_det_idxÚgt_idxÚdet_idxÚiouÚclass_matchr(  r)  r*  r+  s$                                   @@@@r   r  z(ConfusionMatrix.evaluate_detection_batch\  s  øøøø€ õP 	! Ñ/Ô/Ð/ð  ¥<Ô#GÒGÐGˆBˆBÈQð 	ð ¥,Ô"FÒFÐFˆAˆAÈAð 	ð Ô˜qÒ Ð  KÔ$5°aÔ$8Ð<NÒ$NÐ$NÝð4Ð3Eð 4ð 4Ø"Ô(ð4ð 4ð 4ñô ð ð Œ<˜1ÒÐ ¤¨aÔ 0Ð4HÒ HÐ HÝð0Ð/Cð 0ð 0Ø”}ð0ð 0ð 0ñô ð õ
 02¬xØ˜1‰_˜k¨A™oÐ.µb´hð0
ñ 0
ô 0
ˆð
 (­<Ô+OÒOÐO�Q�QÐUVˆ
Ø!ˆØ ‘>ˆà     H Ô-ˆ
Ø#.¨z¸^Ò/KÔ#LÐ åÐ'Ñ(Ô(¨AÒ-Ð-Ý/Ø˜˜˜˜<˜Ô(¨+°xñô ˆLð )ð :ð :�Ø˜h¨Ð3Ð4Ð4Ô4¸Ñ9Ð4Ð4Ñ4Ð4Ø Ð åˆw‰<Œ<˜1ÒÐÝ 4Ø(¨¨¨¨L¨Ô9¸;Èñ!ô !Ðð /ð ;ð ;�	Ø˜k¨9Ð4Ð5Ð5Ô5¸Ñ:Ð5Ð5Ñ5Ð5Ø Ð å+Ø�A�A�A�|�OÔ$ k°8ñ
ô 
ˆõ 1Ø$ Q Q Q¨ _Ô5°{ÀLñ
ô 
Ðð ˜Q˜Q˜Q   ˜^Ô,ˆ
Ø2°1°1°1°k°z°k°>ÔBˆð �LÔ@Ò@Ð@Ý.Ø%°ðñ ô ˆIˆIõ &Ø%°ðñ ô ˆIð ˜}Ò,ˆÝ"$¤*¨XÑ"6Ô"6Ñˆ
�Kð Œ?˜aÒÐØˆMˆMà˜Z¨Ð4Ô5ˆDØ+¨JÔ7ÐØ 1°+Ô >ÐØ,Ð0AÒAˆMõ œ:¨ u¨}¨nÐ&=Ñ>Ô>ˆLðð ð ð ð ð ð ð (ðñ ô ˆMõ ™œˆÝ™%œ%ˆà1>ð 		-ð 		-Ñ-ˆF�G˜S +Ø˜^Ð+Ð+°¸Ð0NÐ0Nà'¨Ô/�Ø-¨gÔ6�	ð ˜h¨	Ð1Ð2Ð2Ô2°aÑ7Ð2Ð2Ñ2Ø×"Ò" 6Ñ*Ô*Ð*Ø×#Ò# GÑ,Ô,Ð,øõ !*¨,Ñ 7Ô 7ð 	:ð 	:ÑˆF�HØ˜^Ð+Ð+Ø˜h¨Ð3Ð4Ð4Ô4¸Ñ9Ð4Ð4Ñ4øõ #,Ð,=Ñ">Ô">ð 	;ð 	;ÑˆG�YØ˜oÐ-Ð-Ø˜k¨9Ð4Ð5Ð5Ô5¸Ñ:Ð5Ð5Ñ5øàÐr   Úmatchesc                ó�  — | j         d         dk    r²| | dd…df                              ¦   «         ddd…                  } | t          j        | dd…df         d¬¦  «        d                  } | | dd…df                              ¦   «         ddd…                  } | t          j        | dd…df         d¬¦  «        d                  } | }|S )z›
        Deduplicate matches. If there are multiple matches for the same true or
        predicted box, only the one with the highest IoU is kept.
        r   NrD   rE   r*   T)Úreturn_index)rP   Úargsortr-   r5   )rG  r[   s     r   Ú_drop_extra_matchesz#ConfusionMatrix._drop_extra_matches  sÎ   € ð Œ=˜Ô˜aÒÐØ˜g a a a¨ dœm×3Ò3Ñ5Ô5°d°d¸°dÔ;Ô<ˆGØ�bœi¨°°°°1°¬ÀDÐIÑIÔIÈ!ÔLÔMˆGØ˜g a a a¨ dœm×3Ò3Ñ5Ô5°d°d¸°dÔ;Ô<ˆGØ�bœi¨°°°°1°¬ÀDÐIÑIÔIÈ!ÔLÔMˆGØ*1ˆØˆr   )Úsave_directory_pathÚdatasetr   Úcallbackú-Callable[[npt.NDArray[np.uint8]], Detections]rL  ústr | Path | Nonec               óÄ  — |�&t          |¦  «        }|                     dd¬¦  «         g g }	}t          |¦  «        D �]\  }
\  }}} ||¦  «        }|                     |¦  «         |	                     |¦  «         |�Ãt	          |t           ¦  «        r|j        }n1t	          |t          ¦  «        rt          |¦  «        j        }nd|
d›d�}t          |¦  «        j        dk    r|› d�}||z  }|                     ¦   «         r#t          j
        d|› d	|› d
�t          d¬¦  «         t          |||||||j        |¬¦  «         �Œ|                      ||	|j        |||¬¦  «        S )az  
        Calculate confusion matrix from dataset and callback function.

        Args:
            dataset: Object detection dataset used for evaluation.
            callback: Function that takes an image as input and returns a
                Detections object.
            conf_threshold: Detection confidence threshold between `0` and `1`.
                Detections with lower confidence will be excluded.
            iou_threshold: Detection IoU threshold between `0` and `1`.
                Detections with lower IoU will be classified as `FP`.
            save_directory_path: Optional directory where per-image validation
                result grids are saved using the original image filenames. Images
                are written directly to this directory (no subdirectory is added).
                When ``None`` (default), no images are saved.
            metric_target: The type of detection data to use.
                Supports `MetricTarget.BOXES` and
                `MetricTarget.ORIENTED_BOUNDING_BOXES`. Passed through to
                `from_detections`. `MetricTarget.MASKS` is not supported.

        Returns:
            New instance of ConfusionMatrix.

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

            dataset = sv.DetectionDataset.from_yolo(...)

            model = RFDETRMedium()
            def callback(image: np.ndarray) -> sv.Detections:
                return model.predict(image[:, :, ::-1])

            confusion_matrix = sv.ConfusionMatrix.benchmark(
                dataset = dataset,
                callback = callback
            )

            print(confusion_matrix.matrix)
            # np.array([
            #     [0., 0., 0., 0.],
            #     [0., 1., 0., 1.],
            #     [0., 1., 1., 0.],
            #     [1., 1., 0., 0.]
            # ])
            ```
        NT)ÚparentsÚexist_okÚimage_Ú06dz.jpgr›   zValidation image 'z' already exists at 'z' and will be overwritten.rD   rç   )r£   r]   r_   rã   rn   rp   r—   r   r  )r   Úmkdirrž   rU   rh   Únamer%   ÚsuffixÚexistsrì   rí   rî   rü   r  r  )r  rM  rN  rn   rp   r   rL  Úsave_directoryr]   r_   r    Ú
image_nameÚimageÚ
annotationÚpredictions_batchÚimage_filenamerã   s                    r   Ú	benchmarkzConfusionMatrix.benchmark  sÜ  € ðv Ð*Ý!Ð"5Ñ6Ô6ˆNØ× Ò ¨¸Ð Ñ=Ô=Ð=à! 2�WˆÝ6?ÀÑ6HÔ6Hð !	ñ !	Ñ2ˆEÑ2�J  zØ ( ¨¡¤ÐØ×ÒÐ0Ñ1Ô1Ð1Ø�NŠN˜:Ñ&Ô&Ð&à"Ð.Ý˜j­$Ñ/Ô/ð >Ø%/¤_�N�NÝ 
­CÑ0Ô0ð >Ý%)¨*Ñ%5Ô%5Ô%:�N�Nà%=¨eÐ%=Ð%=Ð%=Ð%=�Nå˜Ñ'Ô'Ô.°"Ò4Ð4Ø(6Ð%<Ð%<Ð%<�Nà*¨^Ñ;�	Ø×#Ò#Ñ%Ô%ð Ý”MðB¨^ð Bð BØ%ðBð Bð Bå#Ø#$ð	ñ ô ð õ 9ØØ 1Ø&Ø'Ø#1Ø"/Ø '¤Ø"/ð	ñ 	ô 	ð 	ùð ×"Ò"Ø#ØØ”OØ)Ø'Ø'ð #ñ 
ô 
ð 	
r   F©é   rb   rã   ú
str | Noner·   r˜   Ú	normalizeÚfig_sizeútuple[int, int]r   c                óL  — ddl m} | j                             t          j        ¦  «        }|r1d}||                     d¦  «                             dd¦  «        |z   z  }t          j        ||dk     <   | 	                    |dd¬	¦  «        \  }	}
|�|n| j
        }|d
uodt          |¦  «        cxk     odk     nc }|rg |¢d‘}g |¢d‘}t          |¦  «        }nd
}d
}t          |¦  «        }|
                     |d¬¦  «        }|
j                             ||
¬¦  «        }|j                             dt#          t	          j        |¦  «        ¦  «        ¬¦  «         |€d}nd}|
                     t	          j        d||¦  «        |¬¦  «         |
                     t	          j        d||¦  «        |¬¦  «         |                     |
                     ¦   «         ddd¬¦  «         |dk     rdnd}|
                     dd|¬¦  «         |dk     r˜t3          |j        d         ¦  «        D ]}}t3          |j        d         ¦  «        D ]`}|||f         }t	          j        |¦  «        s@|
                     |||r|d›n|d›d d |d!t	          j        |¦  «        z  k     rd"nd¬#¦  «         ŒaŒ~|r|
                     |d$¬%¦  «         |
                     d&¦  «         |
                     d'¦  «         |
                      d¦  «         |r+|	 !                    |d(|	 "                    ¦   «         d¬)¦  «         |	S )*a  
        Create confusion matrix plot and save it at selected location.

        Args:
            save_path: Path to save the plot. If not provided,
                plot will be displayed.
            title: Title of the plot.
            classes: List of classes to be displayed on the plot.
                If not provided, all classes will be displayed.
            normalize: If True, normalize the confusion matrix.
            fig_size: Size of the plot.

        Returns:
            Confusion matrix plot.
        r   )Úpyplotg:Œ0âŽyE>r*   rE   g{®Gázt?TÚwhite)ÚfigsizeÚtight_layoutÚ	facecolorNéc   ÚFNÚFPÚBlues)Úcmap)Úax)ÚvminÚvmaxrD   rÃ   éZ   ÚrightÚdefault)ÚrotationÚhaÚrotation_modeé2   rb   rA   Úboth)rG   ÚwhichÚ	labelsizeé   r�   z.0fÚcenterr  Úblack)ry  ÚvarÀ   é   )ÚfontsizeÚ	PredictedÚTrueéú   )Údpirl  Útransparent)#Ú
matplotlibrh  r  r3   r-   Úfloat64ÚsumrQ   ÚnanÚsubplotsr  rL   ÚimshowÚfigureÚcolorbarÚmappableÚset_climro   ÚnanmaxÚ
set_xticksÚarangeÚ
set_yticksÚsetpÚget_xticklabelsÚtick_paramsrx   rP   ÚisnanÚtextÚ	set_titleÚ
set_xlabelÚ
set_ylabelÚset_facecolorÚsavefigÚget_facecolor)r  rã   r·   r  rd  re  ÚpltÚarrayÚepsÚfigrr  r—   Úuse_labels_for_ticksÚx_tick_labelsÚy_tick_labelsÚ	num_ticksÚimÚcbarÚtick_intervalr~  ÚiÚjÚn_predss                          r   ÚplotzConfusionMatrix.plot~  sˆ  € ð. 	-Ð,Ð,Ð,Ð,Ð,ð ”×"Ò"¥2¤:Ñ.Ô.ˆàð 	@ØˆCØ˜UŸYšY q™\œ\×1Ò1°!°RÑ8Ô8¸3Ñ>Ñ?ˆEå!œvˆˆe�eŠmÑà—,’, x¸dÈg�,ÑVÔV‰ˆˆRà!(Ð!4�g�g¸$¼,ˆØ*°$Ð6ÐV¸AÅÀKÑ@PÔ@PÐ<UÐ<UÒ<UÐ<UÐSUÒ<UÐ<UÐ<UÐ<UÐØð 	#Ø0˜kÐ0¨4Ð0ˆMØ0˜kÐ0¨4Ð0ˆMÝ˜MÑ*Ô*ˆIˆIà ˆMØ ˆMÝ˜E™
œ
ˆIØ�YŠY�u 7ˆYÑ+Ô+ˆàŒy×!Ò! "¨Ð!Ñ,Ô,ˆØŒ×Ò A­Eµ"´)¸EÑ2BÔ2BÑ,CÔ,CÐÑDÔDÐDàÐ ØˆMˆMàˆMØ
�Š•b”i  9¨mÑ<Ô<À]ˆÑSÔSÐSØ
�Š•b”i  9¨mÑ<Ô<À]ˆÑSÔSÐSà�Š�×#Ò#Ñ%Ô%°°wÈiˆÑXÔXÐXà# bš.˜.�B�B¨aˆ	Ø
�Š˜F¨&¸IˆÑFÔFÐFà�rŠ>ˆ>Ý˜5œ; qœ>Ñ*Ô*ð ð �Ý˜uœ{¨1œ~Ñ.Ô.ð ð �AØ# A q Dœk�GÝœ8 GÑ,Ô,ð 
ØŸšØØØ09ÐO˜wÐ,Ð,Ð,À'Ð?OÐ?OØ'Ø'à&¨­r¬y¸Ñ/?Ô/?Ñ)?Ò?Ð?ð #* 'à!(ð  ñ 	ô 	ð 	øðð ð 	-Ø�LŠL˜¨ˆLÑ,Ô,Ð,à
�Š�kÑ"Ô"Ð"Ø
�Š�fÑÔÐØ
×Ò˜Ñ!Ô!Ð!Øð 	Ø�KŠKØ˜s¨c×.?Ò.?Ñ.AÔ.AÈtð ñ ô ð ð ˆ
r   )r	  r
  r   r?   )r]   r  r_   r  r  r™   rn   ro   rp   ro   r   r   r   r  )r]   r^   r_   r^   r  r™   rn   ro   rp   ro   r   r   r   r  )r]   r!   r_   r!   r"   r#   rn   ro   rp   ro   r   r   r   r  )rG  r!   r   r!   )rM  r   rN  rO  rn   ro   rp   ro   r   r   rL  rP  r   r  )NNNFra  )rã   rc  r·   rc  r  r˜   rd  r?   re  rf  r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   ÚBOXESr   r  Ú__hash__Úclassmethodr  r  Ústaticmethodr  rK  r`  r±  r%  r   r   r  r  „  s¿  € € € € € € ðð ð$ "Ð!Ð!Ñ!ØÐÐÑØÐÐÑØÐÐÑØ".Ô"4€MÐ4Ð4Ð4Ñ4ð
ð 
ð 
ð 
ð €Hàð !$Ø"Ø&2Ô&8ðQ
ð Q
ð Q
ð Q
ñ „[ðQ
ðf ð !$Ø"Ø&2Ô&8ð[
ð [
ð [
ð [
ñ „[ð[
ðz ð '3Ô&8ðdð dð dð dñ „\ðdðL ðð ð ñ „\ðð ð
 !$Ø"Ø&2Ô&8ðh
ð 26ðh
ð h
ð h
ð h
ð h
ñ „[ðh
ðX !%Ø Ø$(ØØ$,ðZð Zð Zð Zð Zð Zð Zr   r  z0.27.0z0.31.0T)Úfrozenc                  óÐ   — e Zd ZU dZded<   ded<   ded<   ded<   ed$d„¦   «         Zed%d„¦   «         Zed&d„¦   «         Ze	d'd„¦   «         Z
e	d(d„¦   «         Ze		 d)d*d"„¦   «         Zd#S )+ÚMeanAveragePrecisiona4  
    !!! deprecated "Deprecated"
        `MeanAveragePrecision` is **deprecated** and will be removed in
        `supervision-0.31.0`.

        The deprecated implementation provides results that are inconsistent with
        `pycocotools`. Please use
        `supervision.metrics.mean_average_precision.MeanAveragePrecision` instead,
        which matches the results of `pycocotools` and is now the recommended approach.

    Mean Average Precision for object detection tasks.

    Attributes:
        map50_95: Mean Average Precision (mAP) calculated over IoU thresholds
            ranging from `0.50` to `0.95` with a step size of `0.05`.
        map50: Mean Average Precision (mAP) calculated specifically at
            an IoU threshold of `0.50`.
        map75: Mean Average Precision (mAP) calculated specifically at
            an IoU threshold of `0.75`.
        per_class_ap50_95: Average Precision (AP) values calculated over
            IoU thresholds ranging from `0.50` to `0.95` with a step size of `0.05`,
            provided for each individual class.
    ro   Úmap50_95Úmap50Úmap75únpt.NDArray[np.float64]Úper_class_ap50_95r]   r  r_   r   c                óô   — g }g }t          ||¦  «        D ]M\  }}|                     t          |d¬¦  «        ¦  «         |                     t          |d¬¦  «        ¦  «         ŒN|                      ||¬¦  «        S )ag  
        Calculate mean average precision based on predicted and ground-truth detections.

        Args:
            targets: Detections objects from ground-truth.
            predictions: Detections objects predicted by the model.
        Returns:
            New instance of ConfusionMatrix.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> targets = [
            ...     sv.Detections(
            ...         xyxy=np.array([[0, 0, 10, 10]]),
            ...         class_id=np.array([0])
            ...     )
            ... ]
            >>> predictions = [
            ...     sv.Detections(
            ...         xyxy=np.array([[0, 0, 10, 10]]),
            ...         class_id=np.array([0]),
            ...         confidence=np.array([0.9])
            ...     )
            ... ]
            >>> mAP = sv.MeanAveragePrecision.from_detections(
            ...     predictions=predictions,
            ...     targets=targets,
            ... )
            >>> round(float(mAP.map50), 2)
            1.0

            ```
        T)r>   Fr  r  )r  r]   r_   r  r  r  rý   s          r   r  z$MeanAveragePrecision.from_detectionsÿ  s¢   € ðR  ÐØˆÝ"% k°7Ñ";Ô";ð 	Wð 	WÑˆJ˜Ø×%Ò%Ý$ ZÀÐFÑFÔFñô ð ð ×!Ò!Õ"6°vÈuÐ"UÑ"UÔ"UÑVÔVÐVÐVØ×ÒØ*Ø"ð  ñ 
ô 
ð 	
r   rM  r   rN  rO  c                ó´   — g g }}|D ];\  }}} ||¦  «        }|                      |¦  «         |                      |¦  «         Œ<|                      ||¬¦  «        S )a™  
        Calculate mean average precision from dataset and callback function.

        Args:
            dataset: Object detection dataset used for evaluation.
            callback: Function that takes
                an image as input and returns Detections object.
        Returns:
            New instance of MeanAveragePrecision.

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

            dataset = sv.DetectionDataset.from_yolo(...)

            model = RFDETRMedium()
            def callback(image: np.ndarray) -> sv.Detections:
                return model.predict(image[:, :, ::-1])

            mean_average_precision = sv.MeanAveragePrecision.benchmark(
                dataset = dataset,
                callback = callback
            )

            print(mean_average_precision.map50_95)
            # 0.433
            ```
        r  )rU   r  )	r  rM  rN  r]   r_   Ú_r\  r]  r^  s	            r   r`  zMeanAveragePrecision.benchmark4  s   € ðH  " 2�WˆØ$+ð 	'ð 	'Ñ ˆAˆu�jØ ( ¨¡¤ÐØ×ÒÐ0Ñ1Ô1Ð1Ø�NŠN˜:Ñ&Ô&Ð&Ð&Ø×"Ò"Ø#Øð #ñ 
ô 
ð 	
r   r^   c           
     ó\  — t          ||¦  «         t          j        dddt          j        ¬¦  «        }g }t	          ||¦  «        D �]N\  }}|j        d         dk    re|j        d         rW|                     t          j        d|j        ft          ¬¦  «        gt          j        d¦  «        ¢|dd…df         ‘R ¦  «         Œ||j        d         rO|  
                    |||¦  «        }|                     ||dd…d	f         |dd…df         |dd…df         f¦  «         ŒØ|                     t          j        |j        d         |j        ft          ¬¦  «        |dd…d	f         |dd…df         t          j        d
t          j        ¬¦  «        f¦  «         �ŒP|�rmd„ t	          |Ž D ¦   «         }|                      t          t          j        t          j                 |d         ¦  «        t          t          j        t          j                 |d         ¦  «        t          t          j        t          j                 |d         ¦  «        t          t          j        t          j                 |d         ¦  «        ¦  «        }	|	j        dk    rd\  }
}}n’t#          |	dd…df                              ¦   «         ¦  «        }
t#          |	dd…d	f                              ¦   «         ¦  «        }t#          |	                     ¦   «         ¦  «        }nd\  }
}}t          j        g ¦  «        }	 | ||
||	¬¦  «        S )a­  
        Calculate Mean Average Precision based on predicted and ground-truth
            detections at different threshold.

        Args:
            predictions: Each element of the list describes
                a single image and has `shape = (M, 6)` where `M` is
                the number of detected objects. Each row is expected to be
                in `(x_min, y_min, x_max, y_max, class, conf)` format.
            targets: Each element of the list describes a single
                image and has `shape = (N, 5)` where `N` is the
                number of ground-truth objects. Each row is expected to be in
                `(x_min, y_min, x_max, y_max, class)` format. An empty array
                (``N = 0``) represents a background image; all predictions on
                that image count as false positives and reduce AP accordingly.

        Returns:
            MeanAveragePrecision: New instance computed from the provided
                predictions and targets.

        Examples:
            ```pycon
            >>> import supervision as sv
            >>> import numpy as np
            >>> targets = [
            ...     np.array([
            ...         [0.0, 0.0, 3.0, 3.0, 0],
            ...         [2.0, 2.0, 5.0, 5.0, 0],
            ...         [6.0, 1.0, 8.0, 3.0, 1],
            ...     ])
            ... ]
            >>> predictions = [
            ...     np.array([
            ...         [0.0, 0.0, 3.0, 3.0, 0, 0.9],
            ...         [0.1, 0.1, 3.0, 3.0, 0, 0.9],
            ...         [6.0, 1.0, 8.0, 3.0, 1, 0.8],
            ...     ])
            ... ]
            >>> mAP = sv.MeanAveragePrecision.from_tensors(
            ...     predictions=predictions,
            ...     targets=targets,
            ... )
            >>> round(float(mAP.map50), 2)
            0.75

            >>> bg_pred = [np.array([[0., 0., 10., 10., 0, 0.9]], dtype=np.float32)]
            >>> bg_tgt = [np.zeros((0, 5), dtype=np.float32)]
            >>> mAP_bg = sv.MeanAveragePrecision.from_tensors(
            ...     predictions=bg_pred,
            ...     targets=bg_tgt,
            ... )
            >>> float(mAP_bg.map50)
            0.0

            ```
        r  gffffffî?rb   r(   r   )rD   r   NrC   re   ©r   c                ó8   — g | ]}t          j        |d ¦  «        ‘ŒS rÇ  )r-   rV   )r&  Úitemss     r   r,  z5MeanAveragePrecision.from_tensors.<locals>.<listcomp>Ï  s$   € Ð!TÐ!TÐ!T¸u¥"¤.°¸Ñ":Ô":Ð!TÐ!TÐ!Tr   r*   rD   rB   )ç        rÊ  rÊ  )r   r   r   )r¾  r¿  rÀ  rÂ  )rm   r-   ÚlinspacerN   r  rP   rU   rz   r,   r?   Ú_match_detection_batchÚ_average_precisions_per_classr	   rÍ   rÎ   Úbool_r  ro   Úmeanr¤  )r  r]   r_   Úiou_thresholdsÚstatsÚ	true_objsÚpredicted_objsrG  Úconcatenated_statsÚaverage_precisionsr¿  rÀ  r¾  s                r   r  z!MeanAveragePrecision.from_tensorsb  sO  € õ| 	  ¨WÑ5Ô5Ð5Ýœ S¨$°½"¼*ÐEÑEÔEˆØˆõ *-¨W°kÑ)BÔ)Bð &	ñ &	Ñ%ˆI�~ØÔ# AÔ&¨!Ò+Ð+Ø”? 1Ô%ð Ø—L’LåœH a¨Ô)<Ð%=ÅTÐJÑJÔJðåœX fÑ-Ô-ðð & a a a¨ dœOðð ñô ð ð àŒ˜qÔ!ð Ø×4Ò4Ø" I¨~ñô �ð —’àØ& q q q¨! tÔ,Ø& q q q¨! tÔ,Ø! ! ! ! Q $œð	ñô ð ð ð —’åœØ+Ô1°!Ô4°nÔ6IÐJÕRVðñ ô ð ' q q q¨! tÔ,Ø& q q q¨! tÔ,Ýœ ­R¬ZÐ8Ñ8Ô8ðñ	ô 	ð 	ñ 	ð ñ 	.Ø!TÐ!TÍÈUÈÐ!TÑ!TÔ!TÐØ!$×!BÒ!BÝ•S”[¥¤Ô*Ð,>¸qÔ,AÑBÔBÝ•S”[¥¤Ô,Ð.@ÀÔ.CÑDÔDÝ•S”[¥¤Ô*Ð,>¸qÔ,AÑBÔBÝ•S”[¥¤Ô*Ð,>¸qÔ,AÑBÔBñ	"ô "Ðð "Ô&¨!Ò+Ð+ð *7Ñ&��u˜h˜håÐ0°°°°A°Ô6×;Ò;Ñ=Ô=Ñ>Ô>�ÝÐ0°°°°A°Ô6×;Ò;Ñ=Ô=Ñ>Ô>�Ý Ð!3×!8Ò!8Ñ!:Ô!:Ñ;Ô;��à%,Ñ"ˆE�5˜(Ý!#¤¨"¡¤ÐàˆsØØØØ0ð	
ñ 
ô 
ð 	
r   ÚrecallÚ	precisionc                óœ  — t          j        dg| dgf¦  «        }t          j        dg|dgf¦  «        }t          j        t           j                             t          j        |¦  «        ¦  «        ¦  «        }t          j        ddd¦  «        }t          j        ||d¬¦  «        }||         }t          j        |¦  «        }t          |¦  «        S )a  
        Compute the average precision using 101-point interpolation (COCO), given
            the recall and precision curves.

        Args:
            recall: The recall curve.
            precision: The precision curve.

        Returns:
            Average precision.
        rÊ  r©   r   r*   ée   Úleft)Úside)	r-   rV   ÚflipÚmaximumÚ
accumulaterË  ÚsearchsortedrÏ  ro   )	rÖ  r×  Úextended_recallÚextended_precisionÚmax_accumulated_precisionÚinterpolated_recall_levelsÚrecall_indicesÚinterpolated_precisionÚaverage_precisions	            r   Úcompute_average_precisionz.MeanAveragePrecision.compute_average_precisioné  sÊ   € õ  œ.¨3¨%°¸#¸Ð)?Ñ@Ô@ˆÝœ^¨c¨U°IÀ¸uÐ,EÑFÔFÐÝ$&¤GÝŒJ×!Ò!¥"¤'Ð*<Ñ"=Ô"=Ñ>Ô>ñ%
ô %
Ð!õ &(¤[°°A°sÑ%;Ô%;Ð"ÝœØÐ7¸fð
ñ 
ô 
ˆð ";¸>Ô!JÐÝœGÐ$:Ñ;Ô;ÐåÐ&Ñ'Ô'Ð'r   r!   rÐ  únpt.NDArray[np.bool_]c                óš  — | j         d         |j         d         }}t          j        ||ft          ¬¦  «        }t	          |dd…dd…f         | dd…dd…f         ¦  «        }|dd…dd…f         | dd…df         k    }t          |¦  «        D ]=\  }}	t          j        ||	k    |z  ¦  «        }
t          ||
¦  «        D ]\  }}d|||f<   ŒŒ>|}|S )a   
        Match predictions with target labels based on IoU levels.

        Args:
            predictions: Batch prediction. Describes a single image and
                has `shape = (M, 6)` where `M` is the number of detected objects.
                Each row is expected to be in
                `(x_min, y_min, x_max, y_max, class, conf)` format.
            targets: Batch target labels. Describes a single image and
                has `shape = (N, 5)` where `N` is the number of ground-truth objects.
                Each row is expected to be in
                `(x_min, y_min, x_max, y_max, class)` format.
            iou_thresholds: Array contains different IoU thresholds.

        Returns:
            Matched prediction with target labels result.
        r   r(   NrC   re   T)rP   r-   rz   r?   r   rž   ry   r   )r]   r_   rÐ  Únum_predictionsÚnum_iou_levelsÚcorrectrE  Úcorrect_classr®  Ú	iou_levelÚmatched_indicesÚtÚpr[   s                 r   rÌ  z+MeanAveragePrecision._match_detection_batch  sý   € ð. +6Ô*;¸AÔ*>ÀÔ@TÐUVÔ@W˜ˆÝ”(˜O¨^Ð<ÅDÐIÑIÔIˆÝ˜G A A A r¨ r EœN¨K¸¸¸¸2¸A¸2¸Ô,>Ñ?Ô?ˆØ    1 Q 3 œ¨;°q°q°q¸!°tÔ+<Ò<ˆå% nÑ5Ô5ð 	%ð 	%‰LˆAˆyÝ œh¨¨yÒ(8¸MÑ'IÑJÔJˆOå% c¨?Ñ;Ô;ð %ð %‘��1Ø $�˜˜1˜‘�ð%à(/ˆØˆr   ç¼‰Ø—²Òœ<rG  r€   Úprediction_class_idsr  Útrue_class_idsr¥  c                ó¶  — t          j        | ¦  «        }| |         } ||         }t          j        |d¬¦  «        \  }}|j        d         }t          j        || j        d         ft           j        ¬¦  «        }	t          |¦  «        D ]Î\  }
}||k    }||
         }|                     ¦   «         }|dk    s|dk    rŒ4d| |         z
                       d¦  «        }| |                              d¦  «        }|||z   z  }|||z   z  }t          | j        d         ¦  «        D ]6}t                               |dd…|f         |dd…|f         ¦  «        |	|
|f<   Œ7ŒÏ|	}|S )a  
        Compute the average precision, given the recall and precision curves.
        Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.

        Args:
            matches: True positives.
            prediction_confidence: Objectness value from 0-1.
            prediction_class_ids: Predicted object classes.
            true_class_ids: True object classes.
            eps: Small value to prevent division by zero.

        Returns:
            Average precision for different IoU levels.
        T)Úreturn_countsr   r*   r(   N)r-   rJ  r5   rP   rz   r‹  rž   rŒ  Úcumsumrx   r½  rç  )rG  r€   ró  rô  r¥  Úsorted_indicesÚunique_classesÚclass_countsr"   rÕ  Ú	class_idxrH   Úis_classÚ
total_trueÚtotal_predictionÚfalse_positivesÚtrue_positivesrÖ  r×  Úiou_level_idxr[   s                        r   rÍ  z2MeanAveragePrecision._average_precisions_per_class+  sš  € õ, œÐ%:Ð$:Ñ;Ô;ˆØ˜.Ô)ˆØ3°NÔCÐå')¤y°ÈtÐ'TÑ'TÔ'TÑ$ˆ˜Ø$Ô*¨1Ô-ˆå68´hØ˜'œ-¨Ô*Ð+µ2´:ð7
ñ 7
ô 7
Ðõ $-¨^Ñ#<Ô#<ð 	ð 	ÑˆI�xØ+¨xÒ7ˆHØ% iÔ0ˆJØ'Ÿ|š|™~œ~Ðà 1Ò$Ð$¨
°aª¨Øà  7¨8Ô#4Ñ4×<Ò<¸QÑ?Ô?ˆOØ$ XÔ.×5Ò5°aÑ8Ô8ˆNØ# z°CÑ'7Ñ8ˆFØ&¨.¸?Ñ*JÑKˆIå!& w¤}°QÔ'7Ñ!8Ô!8ð ð �å(×BÒBØ˜q˜q˜q -Ð/Ô0°)¸A¸A¸A¸}Ð<LÔ2Mñô ð # 9¨mÐ#;Ñ<Ð<ðð +=ˆØˆr   N)r]   r  r_   r  r   r½  )rM  r   rN  rO  r   r½  )r]   r^   r_   r^   r   r½  )rÖ  rÁ  r×  rÁ  r   ro   )r]   r!   r_   r!   rÐ  r!   r   rè  )rò  )rG  rè  r€   r!   ró  r  rô  r  r¥  ro   r   rÁ  )r²  r³  r´  rµ  r¶  r¹  r  r`  r  rº  rç  rÌ  rÍ  r%  r   r   r½  r½  Û  s  € € € € € € ðð ð0 €O€O�OØ€L€L�LØ€L€L�LØ.Ð.Ð.Ñ.àð2
ð 2
ð 2
ñ „[ð2
ðh ð+
ð +
ð +
ñ „[ð+
ðZ ðD
ð D
ð D
ñ „[ðD
ðL ð(ð (ð (ñ „\ð(ð: ð!ð !ð !ñ „\ð!ðF ð ð5ð 5ð 5ð 5ñ „\ð5ð 5ð 5r   r½  )r   r   r   r   )r    r!   r"   r#   r$   r%   r   r&   )r=   r   r>   r?   r   r   r   r!   )r]   r^   r_   r^   r   r   r   r   )r]   r   r_   r   rn   ro   rp   ro   r   r   r   rq   )r=   r   r—   r˜   r   r™   )r£   r¤   r   r¥   )r£   r¤   r=   r   r·   r%   r—   r˜   r¸   r¥   r   r¤   )r£   r¤   r]   r   r_   r   rã   r   rn   ro   rp   ro   r—   r˜   r   r   r   r   )r]   r^   r_   r^   r   r   )3Ú
__future__r   rì   Úcollections.abcr   Údataclassesr   Úpathlibr   Útypingr   r   r	   Únumpyr-   Únumpy.typingrÍ   Ú	deprecater
   r   r   r   Úsupervision.configr   Úsupervision.dataset.corer   Úsupervision.detection.corer   Ú'supervision.detection.utils.iou_and_nmsr   r   Úsupervision.metrics.corer   Ú"supervision.metrics.utils.matchingr   Úmatplotlib.figurer   r   r<   r·  r\   rm   r–   r¢   r¶   râ   rü   r  r  ÚNOTIFYr½  r%  r   r   ú<module>r     ss  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +à Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð 8Ð 7Ð 7Ð 7Ð 7Ð 7Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1ðð ð ð ð ð ð ð ð 2Ð 1Ð 1Ð 1Ð 1Ð 1Ø <Ð <Ð <Ð <Ð <Ð <àð )Ø(Ð(Ð(Ð(Ð(Ð(ð
ð 
ð 
ð 
ðð ð ð ð4 "Ø".Ô"4ðsð sð sð sð sðr #/Ô"4ð&ð &ð &ð &ð &ð\ #/Ô"4ðVð Vð Vð Vð Vðr!ð !ð !ð !ðHNð Nð Nð Nð2Mð Mð Mð Mðp #/Ô"4ðq
ð q
ð q
ð q
ð q
ðh €Ø"ØØðñ ô ð
ð ð ñô ð
ð ðS	ð S	ð S	ð S	ð S	ñ S	ô S	ñ „ðS	ðl ÐØÔØØðñ ô ð
 €�$ÐÑÔð@ð @ð @ð @ð @ñ @ô @ñ Ôñô ð@ð @ð @r   