§
    >²¸jÌ‡  ã                  ó0  — 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 d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZmZmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$ erd dl%Z& G d„ ded         ¦  «        Z'e G d„ d¦  «        ¦   «         Z(dS )é    )Úannotations)Údeepcopy)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚcastN)ÚORIENTED_BOX_COORDINATES)ÚCompactMask)Ú
Detections)Úbox_iou_batchÚmask_iou_batchÚoriented_box_iou_batch)ÚLEGACY_COLOR_PALETTE)ÚAveragingMethodÚMetricÚMetricTarget©Ú*_match_detection_batch_with_target_indices)ÚObjectSizeCategoryÚget_detection_size_category)Úensure_pandas_installedc                  óÒ   — e Zd ZdZej        ej        fd9d„Zd:d	„Z	d;d„Z
d<d„Zej        fd=d„Zd>d„Zed?d$„¦   «         Zed@d,„¦   «         ZedAd.„¦   «         ZdBd2„ZdCd4„ZdDd5„ZdEd7„Zd8S )FÚRecallaC	  
    Recall is a metric used to evaluate object detection models. It is the ratio of
    true positive detections to the total number of ground truth instances. We calculate
    it at different IoU thresholds.

    In simple terms, Recall is a measure of a model's completeness, calculated as:

    `Recall = TP / (TP + FN)`

    Here, `TP` is the number of true positives (correct detections), and `FN` is the
    number of false negatives (missed detections).

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> from supervision.metrics import Recall
        >>> predictions = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10]]),
        ...     class_id=np.array([0]),
        ...     confidence=np.array([0.9])
        ... )
        >>> targets = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10]]),
        ...     class_id=np.array([0])
        ... )
        >>> recall_metric = Recall()
        >>> recall_result = recall_metric.update(predictions, targets).compute()
        >>> round(float(recall_result.recall_at_50), 2)
        1.0

        ```

        A class that only ever appears in the predictions (for example a detection
        on a background image with no ground truth) has no instances to recall, so
        it is tracked with a recall of `0.0` rather than dropped. This keeps the
        tracked class set aligned with Precision and F1Score for the same input:

        ```pycon
        >>> predictions = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10], [100, 0, 110, 10]]),
        ...     class_id=np.array([0, 1]),  # class 1 has no ground-truth instance
        ...     confidence=np.array([0.9, 0.8])
        ... )
        >>> targets = sv.Detections(
        ...     xyxy=np.array([[0, 0, 10, 10]]),
        ...     class_id=np.array([0])
        ... )
        >>> recall_result = Recall().update(predictions, targets).compute()
        >>> recall_result.matched_classes.tolist()
        [0, 1]
        >>> round(float(recall_result.recall_per_class[0][0]), 2)  # matched class 0
        1.0
        >>> round(float(recall_result.recall_per_class[1][0]), 2)  # prediction-only
        0.0

        ```

    ![example_plot](
        https://media.roboflow.com/supervision-docs/metrics/recall_plot_example.png
    ){ align=center width="800" }
    Úmetric_targetr   Úaveraging_methodr   c                ó>   — || _         || _        g | _        g | _        dS )a  
        Initialize the Recall metric.

        Args:
            metric_target: The type of detection data to use.
            averaging_method: The averaging method used to compute the
                recall. Determines how the recall is aggregated across classes.
        N)Ú_metric_targetr   Ú_predictions_listÚ_targets_list)Úselfr   r   s      új/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/metrics/recall.pyÚ__init__zRecall.__init__a   s*   € ð ,ˆÔØ 0ˆÔà35ˆÔØ/1ˆÔÐÐó    ÚreturnÚNonec                ó"   — g | _         g | _        dS )zR
        Reset the metric to its initial state, clearing all stored data.
        N)r   r   ©r    s    r!   ÚresetzRecall.resett   s   € ð "$ˆÔØˆÔÐÐr#   ÚpredictionsúDetections | list[Detections]Útargetsc                ón  — t          |t          ¦  «        s|g}t          |t          ¦  «        s|g}t          |¦  «        t          |¦  «        k    r0t          dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚| j                             |¦  «         | j                             |¦  «         | S )a  
        Add new predictions and targets to the metric, but do not compute the result.

        Args:
            predictions: The predicted detections.
            targets: The target detections.

        Returns:
            The updated metric instance.
        zThe number of predictions (z) and targets (z%) during the update must be the same.)Ú
isinstanceÚlistÚlenÚ
ValueErrorr   Úextendr   )r    r)   r+   s      r!   ÚupdatezRecall.update{   sÍ   € õ ˜+¥tÑ,Ô,ð 	(Ø&˜-ˆKÝ˜'¥4Ñ(Ô(ð 	 Ø�iˆGåˆ{ÑÔ�s 7™|œ|Ò+Ð+ÝðQ­c°+Ñ.>Ô.>ð Qð QÝ  ™\œ\ðQð Qð Qñô ð ð
 	Ô×%Ò% kÑ2Ô2Ð2ØÔ×!Ò! 'Ñ*Ô*Ð*àˆr#   ÚRecallResultc                óf  — |                       | j        | j        ¦  «        }|                       | j        | j        t          j        ¦  «        |_        |                       | j        | j        t          j        ¦  «        |_        |                       | j        | j        t          j        ¦  «        |_	        |S )zÁ
        Calculate the recall metric based on the stored predictions and ground-truth
        data, at different IoU thresholds.

        Returns:
            The recall metric result.
        )
Ú_computer   r   r   ÚSMALLÚsmall_objectsÚMEDIUMÚmedium_objectsÚLARGEÚlarge_objects)r    Úresults     r!   ÚcomputezRecall.computeš   s�   € ð —’˜tÔ5°tÔ7IÑJÔJˆØ#Ÿ}š}ØÔ" DÔ$6Õ8JÔ8Pñ 
ô  
ˆÔð !%§¢ØÔ" DÔ$6Õ8JÔ8Qñ!
ô !
ˆÔð  $Ÿ}š}ØÔ" DÔ$6Õ8JÔ8Pñ 
ô  
ˆÔð ˆr#   Úpredictions_listúlist[Detections]Útargets_listÚsize_categoryr   c                ó^  — t          j        dddt           j        ¬¦  «        }g }t          ||¦  «        D �]<\  }}|                      |¦  «        }|                      |¦  «        }	t          j        t          |¦  «        t          ¬¦  «        }
t          j        t          |¦  «        t          ¬¦  «        }|t          j	        k    rbt          |¦  «        dk    rt          || j        ¦  «        |j        k    }
t          |¦  «        dk    rt          || j        ¦  «        |j        k    }t          |¦  «        dk    �r:t          |¦  «        dk    �r&|j        �|j        €t          d¦  «        ‚t          j        |j        t           j        ¬¦  «        |
         }t          j        |j        t           j        ¬¦  «        |
         }t          |¦  «        dk    r�Œ¢|                     t          j        t          |¦  «        |j        ft           j        ¬¦  «        t          j        t          |¦  «        |j        ft           j        ¬¦  «        ||t          j        dt           j        ¬¦  «        f¦  «         �Œ@t          |¦  «        dk    �rè|j        �|j        €t          d¦  «        ‚t          |¦  «        dk    rÓt          j        |j        t           j        ¬¦  «        |         }t          |¦  «        dk    r�ŒÄ|                     t          j        d|j        ft          ¬¦  «        t          j        d|j        ft          ¬¦  «        t          j        dt           j        ¬¦  «        t          j        dt,          ¬¦  «        |f¦  «         �ŒW|j        €t          d	¦  «        ‚t          j        |j        t           j        ¬¦  «        }t          j        |j        t           j        ¬¦  «        }t          j        |j        t           j        ¬¦  «        }| j        t.          j        k    rat3          t5          t6          j        t           j                 |	¦  «        t5          t6          j        t           j                 |¦  «        ¦  «        }n«| j        t.          j        k    rt?          |	|¦  «        }n…| j        t.          j         k    ratC          t5          t6          j        t           j                 |	¦  «        t5          t6          j        t           j                 |¦  «        ¦  «        }nt          d
¦  «        ‚|t          j	        k    r|nd }tE          |||||¬¦  «        \  }}t          j#        |t          ¬¦  «        }|t          j	        k    rÏ|dk    }t          j#        |t          ¬¦  «        }t          j$        |¦  «        r|||                  ||<   |
d d …d f         |z  }| || z  z  }t          j$        | d¬¦  «        }||         ||         z  }||         }||         }||         }||         }t          |¦  «        dk    rt          |¦  «        dk    r�Œ"|                     |||||f¦  «         �Œ>|swtK          | j        | j&        t          j        |j'        d         ¦  «        t          j        d|j'        d         f¦  «        |t          j(        g t,          ¬¦  «        d d d ¬¦	  «	        S d„ t          |Ž D ¦   «         } | j)        |Ž \  }}}tK          | j        | j&        ||||d d d ¬¦	  «	        S )Ng      à?gffffffî?é
   ©Údtyper   zBRecall metric requires `class_id` and `confidence` on predictions.©r   zBRecall metric requires `class_id` on both predictions and targets.z3Recall metric requires `confidence` on predictions.z-Unsupported metric target for IoU calculation)Útarget_scored_maské   ©Úaxis)	r   r   Úrecall_scoresÚrecall_per_classÚiou_thresholdsÚmatched_classesr7   r9   r;   c                ó8   — g | ]}t          j        |d ¦  «        ‘ŒS rF   )ÚnpÚconcatenate)Ú.0Úitemss     r!   ú
<listcomp>z#Recall._compute.<locals>.<listcomp>d  s$   € ÐPÐPÐP¸5�bœn¨U°AÑ6Ô6ÐPÐPÐPr#   )*rP   ÚlinspaceÚfloat32ÚzipÚ_detections_contentÚonesr/   Úboolr   ÚANYr   r   ÚvalueÚclass_idÚ
confidencer0   ÚasarrayÚint32ÚappendÚzerosÚsizeÚbool_Úintr   ÚBOXESr   r   ÚnptÚNDArrayÚnumberÚMASKSr   ÚORIENTED_BOUNDING_BOXESr   r   Ú
zeros_likeÚanyr3   r   ÚshapeÚarrayÚ_compute_recall_for_classes)r    r>   r@   rA   rM   Ústatsr)   r+   Úprediction_contentsÚtarget_contentsÚprediction_size_maskÚtarget_size_maskÚprediction_class_idsÚprediction_confidenceÚtarget_class_idsÚiourG   ÚmatchesÚmatched_target_indicesÚignored_matchesÚvalid_target_matchÚmatched_scored_targetÚprediction_scoredÚprediction_keepÚconcatenated_statsrK   rL   Úunique_classess                               r!   r5   zRecall._compute¯   sg  € õ œ S¨$°½"¼*ÐEÑEÔEˆØˆå$'Ð(8¸,Ñ$GÔ$Gð ]	ñ ]	Ñ ˆK˜Ø"&×":Ò":¸;Ñ"GÔ"GÐØ"×6Ò6°wÑ?Ô?ˆOÝ#%¤7­3¨{Ñ+;Ô+;Å4Ð#HÑ#HÔ#HÐ Ý!œw¥s¨7¡|¤|½4Ð@Ñ@Ô@ÐØÕ 2Ô 6Ò6Ð6Ý�{Ñ#Ô# aÒ'Ð'å3°KÀÔATÑUÔUØ(Ô.ò/ð )õ �w‘<”< !Ò#Ð#å3°G¸TÔ=PÑQÔQØ(Ô.ò/ð %õ
 �7‰|Œ|˜qÒ Ñ ¥S¨Ñ%5Ô%5¸Ò%9Ñ%9ð
 Ô'Ð/°;Ô3IÐ3QÝ$ð*ñô ð õ (*¤z°+Ô2FÍbÌhÐ'WÑ'WÔ'WØ(ô(Ð$õ )+¬
ØÔ*µ"´*ð)ñ )ô )à&ô)(Ð%õ Ð+Ñ,Ô,°Ò1Ð1ÙØ—’åœÝ Ð!5Ñ6Ô6¸Ô8KÐLÝ"$¤(ðñ ô õ œÝ Ð!5Ñ6Ô6¸Ô8KÐLÝ"$¤(ðñ ô ð .Ø,Ýœ ­R¬XÐ6Ñ6Ô6ðñô ð ñ õ �W‘” Ò!Ñ!ØÔ'Ð/°7Ô3CÐ3KÝ$ð'ñô ð õ �{Ñ#Ô# qÒ(Ð(Ý')¤z°'Ô2BÍ"Ì(Ð'SÑ'SÔ'SØ(ô(Ð$õ Ð+Ñ,Ô,°Ò1Ð1Ù Ø—L’LåœH a¨Ô)<Ð%=ÅTÐJÑJÔJÝœH a¨Ô)<Ð%=ÅTÐJÑJÔJÝœH Tµ´Ð<Ñ<Ô<ÝœH TµÐ5Ñ5Ô5Ø,ðñô ð ñ ð #Ô-Ð5Ý(ØQñô ð õ ,.¬:Ø#Ô,µB´Hð,ñ ,ô ,Ð(õ (*¤z°'Ô2BÍ"Ì(Ð'SÑ'SÔ'SÐ$Ý,.¬JØ#Ô.µb´jð-ñ -ô -Ð)ð Ô*­lÔ.@Ò@Ð@å+Ý ¥¤­R¬YÔ!7¸ÑIÔIÝ ¥¤­R¬YÔ!7Ð9LÑMÔMñô ˜˜ð Ô,µÔ0BÒBÐBÝ,¨_Ð>QÑRÔR˜˜ØÔ,µÔ0TÒTÐTå4Ý ¥¤­R¬YÔ!7¸ÑIÔIÝ ¥¤­R¬YÔ!7Ð9LÑMÔMñô ˜˜õ
 )ØKñô ð ð )Õ,>Ô,BÒBÐBð )Ð(à!ð 'õ CØ0Ø,ØØ*Ø/Aðñ ô ñ 4�GÐ3õ ')¤m°GÅ4Ð&HÑ&HÔ&H�OØ$Õ(:Ô(>Ò>Ð>Ø-CÀqÒ-HÐ*Ý02´¸gÍTÐ0RÑ0RÔ0RÐ-Ýœ6Ð"4Ñ5Ô5ð à 0Ø$:Ð;MÔ$Nô!"ð 2Ð2DÑEð 1°°°°D°Ô9Ð<QÑQð *ð ,=Ð*<Ø.Ð2GÐ1GÑGñ+˜õ +-¬&°/Ð1AÈÐ*JÑ*JÔ*J˜à# OÔ4Ø3°OÔDñEð  ð +:¸/Ô*J˜Ø0EÀoÔ0VÐ-Ø/CÀOÔ/TÐ,Ø+;Ð<LÔ+MÐ(åÐ 4Ñ5Ô5¸Ò:Ð:Ý #Ð$4Ñ 5Ô 5¸Ò :Ð :á$Ø—L’Là#Ø+Ø1Ø0Ø,ðñô ð ùð ð 	ÝØ"Ô1Ø!%Ô!6Ý œh ~Ô';¸AÔ'>Ñ?Ô?Ý!#¤¨1¨nÔ.BÀ1Ô.EÐ*FÑ!GÔ!GØ-Ý "¤¨µ3Ð 7Ñ 7Ô 7Ø"Ø#Ø"ð
ñ 
ô 
ð 
ð QÐPÅCÈÀKÐPÑPÔPÐà,ˆDÔ,Ð.@ÐAñ 	8ˆÐ'¨õ ØÔ-Ø!Ô2Ø'Ø-Ø)Ø*ØØØð

ñ 

ô 

ð 
	
r#   rz   únpt.NDArray[np.bool_]r|   rw   únpt.NDArray[np.float32]rv   únpt.NDArray[np.int32]Útrue_class_idsúNtuple[npt.NDArray[np.float64], npt.NDArray[np.float64], npt.NDArray[np.int32]]c                ó   — t          j        | ¦  «        }||         }||         }||         }t          j        |d¬¦  «        \  }}t          j        |¦  «        }	t          j        ||	¦  «        }
t          j        |
j        d         t          ¬¦  «        }||t          j        |
|¦  «        <   |                      ||||
|¦  «        }|  	                    |¦  «        }| j
        t          j        k    rt          j        |d¬¦  «        }nÃ| j
        t          j        k    r+|                     d¦  «        }|  	                    |¦  «        }nƒ| j
        t          j        k    rn|                     t           j        ¦  «        }|                     ¦   «         dk    r t          j        |j        d         ¦  «        }nt          j        |d|¬¦  «        }|||
fS )NT)Úreturn_countsr   rD   rI   rH   )rJ   Úweights)rP   ÚargsortÚuniqueÚunion1drb   rn   re   ÚsearchsortedÚ_compute_confusion_matrixÚ_compute_recallr   r   ÚMACROÚmeanÚMICROÚsumÚWEIGHTEDÚastyperV   Úaverage)r    rz   r|   rw   rv   r†   Úsorted_indicesÚtrue_classesÚtrue_countsÚpred_classesr‚   Úclass_countsÚconfusion_matrixrL   rK   Úconfusion_matrix_mergeds                   r!   rp   z"Recall._compute_recall_for_classesu  sÌ  € õ œÐ%:Ð$:Ñ;Ô;ˆØ˜.Ô)ˆØ)¨.Ô9ˆØ3°NÔCÐõ
 %'¤I¨nÈDÐ$QÑ$QÔ$QÑ!ˆ�kÝ”yÐ!5Ñ6Ô6ˆõ
 œ L°,Ñ?Ô?ˆÝ”x Ô 4°QÔ 7½sÐCÑCÔCˆØFQˆ•R”_ ^°\ÑBÔBÑCð  ×9Ò9Ø�_Ð&:¸NÈLñ
ô 
Ðð
  ×/Ò/Ð0@ÑAÔAÐð Ô ¥OÔ$9Ò9Ð9ÝœGÐ$4¸1Ð=Ñ=Ô=ˆMˆMØÔ"¥oÔ&;Ò;Ð;Ø&6×&:Ò&:¸1Ñ&=Ô&=Ð#Ø ×0Ò0Ð1HÑIÔIˆMˆMØÔ"¥oÔ&>Ò>Ð>Ø'×.Ò.­r¬zÑ:Ô:ˆLØ×ÒÑ!Ô! QÒ&Ð&õ !#¤Ð)9Ô)?ÀÔ)BÑ CÔ C��å "¤
Ø$¨1°lð!ñ !ô !�ð Ð.°Ð>Ð>r#   Úpredictions_classesÚtarget_classesry   rM   c                ó0   — t          | |||¦  «        \  }}|S )Nr   )rŸ   r    ry   rM   Úresult_correctÚ_s         r!   Ú_match_detection_batchzRecall._match_detection_batch¯  s*   € õ GØ °°nñ
ô 
Ñˆ˜ð Ðr#   Úsorted_matchesÚsorted_ignored_matchesÚsorted_prediction_class_idsr‚   únpt.NDArray[np.integer]rœ   únpt.NDArray[np.float64]c                óØ  — | j         d         }|j         d         }t          j        ||dft          j        ¬¦  «        }t	          |¦  «        D �]\  }}	||	k    }
||         }|
                     ¦   «         }|dk    r>t          j        |¦  «        }t          j        |¦  «        }t          j        ||¦  «        }n‘|dk    rEt          j        |¦  «        }||
                               d¦  «        }t          j        |¦  «        }nF| |
                              d¦  «        }| |
          ||
          z                       d¦  «        }||z
  }t          j        |||gd¬¦  «        ||<   �Œ|}|S )aÀ  
        Compute the confusion matrix for each class and IoU threshold.

        Assumes the matches and prediction_class_ids are sorted by confidence
        in descending order.

        Args:
            sorted_matches: shape (P, Th), that is True
                if the prediction is a true positive at the given IoU threshold.
            sorted_ignored_matches: shape (P, Th), that is True
                if the prediction should not affect the given IoU threshold.
            sorted_prediction_class_ids: shape (P,), containing
                the class id for each prediction.
            unique_classes: shape (C,), containing the unique
                class ids.
            class_counts: shape (C,), containing the number
                of true instances for each class.

        Returns:
            shape (C, Th, 3), containing the true positives, false
                positives, and false negatives for each class and IoU threshold.
        rH   r   é   rD   rI   )rn   rP   rb   Úfloat64Ú	enumerater”   ÚfullÚstack)r¥   r¦   r§   r‚   rœ   Únum_thresholdsÚnum_classesr�   Ú	class_idxr]   Úis_classÚnum_trueÚnum_predictionsÚtrue_positivesÚfalse_positivesÚfalse_negativesr<   s                    r!   r�   z Recall._compute_confusion_matrix»  s†  € ð> (Ô-¨aÔ0ˆØ$Ô*¨1Ô-ˆå46´HØ˜.¨!Ð,µB´Jð5
ñ 5
ô 5
Ðõ $-¨^Ñ#<Ô#<ð 	ñ 	ÑˆI�xØ2°hÒ>ˆHØ# IÔ.ˆHØ&Ÿlšl™nœnˆOà !Ò#Ð#Ý!#¤¨.Ñ!9Ô!9�Ý"$¤(¨>Ñ":Ô":�Ý"$¤'¨.¸(Ñ"CÔ"C��Ø˜Q’�Ý!#¤¨.Ñ!9Ô!9�Ø$:¸8Ô$DÐ#D×"IÒ"IÈ!Ñ"LÔ"L�Ý"$¤(¨>Ñ":Ô":��à!/°Ô!9×!=Ò!=¸aÑ!@Ô!@�à# HÔ-Ð-Ð1GÈÔ1QÐ0QÑQß’#�a‘&”&ð  ð #+¨^Ñ";�Ý*,¬(Ø °/ÐBÈð+ñ +ô +Ð˜YÑ'Ñ'ð +;ˆØˆr#   r�   c                óà   — | j         d         dk    st          d| j         › �¦  «        ‚| d         }| d         }||z   }t          j        ||t          j        |¦  «        |dk    ¬¦  «        }|}|S )a[  
        Broadcastable function, computing the recall from the confusion matrix.

        Args:
            confusion_matrix: shape (N, ..., 3), where the last dimension
                contains the true positives, false positives, and false negatives.

        Returns:
            shape (N, ...), containing the recall for each element.
        éÿÿÿÿr«   z/Confusion matrix must have shape (..., 3), got ).r   ).é   r   )ÚoutÚwhere)rn   r0   rP   Údividerl   )r�   r¶   r¸   ÚdenominatorÚrecallÚresult_recalls         r!   r�   zRecall._compute_recallù  sœ   € ð  Ô% bÔ)¨QÒ.Ð.Ýð,Ø#Ô)ð,ð ,ñô ð ð *¨&Ô1ˆØ*¨6Ô2ˆà$ Ñ6ˆÝ”ØØÝ”˜nÑ-Ô-Ø Ò"ð	
ñ 
ô 
ˆð 28ˆØÐr#   Ú
detectionsr   únpt.NDArray[Any] | CompactMaskc                ó^  — | j         t          j        k    r*t          t          j        t                   |j        ¦  «        S | j         t          j        k    rD|j	        �|j	        S t          |¦  «        dk    rt          d¦  «        ‚|                      ¦   «         S | j         t          j        k    rj|j                             t           ¦  «        }|�5t          |¦  «        dk    r"t#          j        |t"          j        ¬¦  «        }|S |                      ¦   «         S t          d| j         › �¦  «        ‚)a  Return boxes, masks or oriented bounding boxes from detections.

        For the mask target this may return a
        :class:`~supervision.detection.compact_mask.CompactMask` rather than a
        dense boolean array when the detections carry compact masks.
        Nr   zFRecall with `MetricTarget.MASKS` requires detections to include masks.rD   úInvalid metric target: )r   r   rf   r   rg   rh   r   Úxyxyrj   Úmaskr/   r0   Ú_make_empty_contentrk   ÚdataÚgetr	   rP   ro   rV   )r    rÂ   ÚobbÚ
result_obbs       r!   rX   zRecall._detections_content  s  € ð Ô¥,Ô"4Ò4Ð4Ý�œ¥CÔ(¨*¬/Ñ:Ô:Ð:ØÔ¥,Ô"4Ò4Ð4ØŒÐ*à!”Ð&Ý�:‰Œ Ò"Ð"Ý ð%ñô ð ð ×+Ò+Ñ-Ô-Ð-ØÔ¥,Ô"FÒFÐFØ”/×%Ò%Õ&>Ñ?Ô?ˆCØˆ¥3 s¡8¤8¨a¢< <Ý68´h¸sÍ"Ì*Ð6UÑ6UÔ6U�
Ø!Ð!Ø×+Ò+Ñ-Ô-Ð-ÝÐH°4Ô3FÐHÐHÑIÔIÐIr#   únpt.NDArray[Any]c                óp  — | j         t          j        k    r"t          j        dt          j        ¬¦  «        }|S | j         t          j        k    rt          j        dt          ¬¦  «        }|S | j         t          j        k    r"t          j        dt          j        ¬¦  «        }|S t          d| j         › �¦  «        ‚)N)r   é   rD   )r   r   r   )r   rÏ   r»   rÅ   )
r   r   rf   rP   ÚemptyrV   rj   rZ   rk   r0   )r    Úempty_boxesÚempty_masksÚ	empty_obbs       r!   rÈ   zRecall._make_empty_content7  s¡   € ØÔ¥,Ô"4Ò4Ð4Ý35´8¸FÍ"Ì*Ð3UÑ3UÔ3UˆKØÐàÔ¥,Ô"4Ò4Ð4Ý13´¸)Í4Ð1PÑ1PÔ1PˆKØÐàÔ¥,Ô"FÒFÐFÝ13´¸)Í2Ì:Ð1VÑ1VÔ1VˆIØÐåÐH°4Ô3FÐHÐHÑIÔIÐIr#   c                ó,  — t          |¦  «        }|                     ¦   «         s|t          j        k    r|S t	          || j        ¦  «        }||j        k    }|j        |         |_        |j        �|j        |         |_        |j	        �|j	        |         |_	        |j
        �|j
        |         |_
        |j        �|j        |         |_        |j        �A|j                             ¦   «         D ]'\  }}t          j        |¦  «        |         |j        |<   Œ(|S )zBReturn a copy of detections with contents filtered by object size.)r   Úis_emptyr   r[   r   r   r\   rÆ   rÇ   r]   r^   Ú
tracker_idrÉ   rS   rP   ro   )r    rÂ   rA   Únew_detectionsÚsizesÚ	size_maskÚkeyr\   s           r!   Ú_filter_detections_by_sizez!Recall._filter_detections_by_sizeH  s  € õ " *Ñ-Ô-ˆØ×ÒÑ Ô ð 	" MÕ5GÔ5KÒ$KÐ$KØ!Ð!å+¨N¸DÔ<OÑPÔPˆØ˜]Ô0Ò0ˆ	à,Ô1°)Ô<ˆÔØÔÐ*Ø"0Ô"5°iÔ"@ˆNÔØÔ"Ð.Ø&4Ô&=¸iÔ&HˆNÔ#ØÔ$Ð0Ø(6Ô(AÀ)Ô(LˆNÔ%ØÔ$Ð0Ø(6Ô(AÀ)Ô(LˆNÔ%ØÔÐ*Ø,Ô1×7Ò7Ñ9Ô9ð Fð F‘
��UÝ+-¬8°E©?¬?¸9Ô+E�Ô# CÑ(Ð(àÐr#   ú)tuple[list[Detections], list[Detections]]c                óâ   — g }g }t          ||¦  «        D ]W\  }}|                     |                      ||¦  «        ¦  «         |                     |                      ||¦  «        ¦  «         ŒX||fS )zI
        Filter predictions and targets by object size category.
        )rW   ra   rÛ   )r    r>   r@   rA   Únew_predictions_listÚnew_targets_listr)   r+   s           r!   Ú'_filter_predictions_and_targets_by_sizez.Recall._filter_predictions_and_targets_by_sizeb  sš   € ð  "ÐØÐÝ$'Ð(8¸,Ñ$GÔ$Gð 	ð 	Ñ ˆK˜Ø ×'Ò'Ø×/Ò/°¸]ÑKÔKñô ð ð ×#Ò#Ø×/Ò/°¸ÑGÔGñô ð ð ð $Ð%5Ð5Ð5r#   N)r   r   r   r   ©r$   r%   )r)   r*   r+   r*   r$   r   )r$   r3   )r>   r?   r@   r?   rA   r   r$   r3   )rz   rƒ   r|   rƒ   rw   r„   rv   r…   r†   r…   r$   r‡   )
rŸ   r…   r    r…   ry   r„   rM   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   rA   r   r$   r   )r>   r?   r@   r?   rA   r   r$   rÜ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rf   r   r•   r"   r(   r2   r=   r   r[   r5   rp   Ústaticmethodr¤   r�   r�   rX   rÈ   rÛ   rà   © r#   r!   r   r   !   sx  € € € € € ð=ð =ðB '3Ô&8Ø,;Ô,Dð2ð 2ð 2ð 2ð 2ð& ð  ð  ð  ðð ð ð ð>ð ð ð ð2 -?Ô,Bð	D
ð D
ð D
ð D
ð D
ðL8?ð 8?ð 8?ð 8?ðt ð	ð 	ð 	ñ „\ð	ð ð;ð ;ð ;ñ „\ð;ðz ðð ð ñ „\ðð@Jð Jð Jð Jð:Jð Jð Jð Jð"ð ð ð ð46ð 6ð 6ð 6ð 6ð 6r#   r   r3   c                  ó¶   — e Zd ZU dZded<   ded<   edd„¦   «         Zedd	„¦   «         Zd
ed<   d
ed<   ded<   ded<   ded<   ded<   ded<   dd„Zdd„Z	dd„Z
dS ) r3   u†  
    The results of the recall metric calculation.

    Defaults to `0` if no detections or targets were provided.

    Attributes:
        metric_target: the type of data used for the metric -
            boxes, masks or oriented bounding boxes.
        averaging_method: the averaging method used to compute the
            recall. Determines how the recall is aggregated across classes.
        recall_at_50: the recall at IoU threshold of `0.5`.
        recall_at_75: the recall at IoU threshold of `0.75`.
        recall_scores: the recall scores at each IoU threshold.
            Shape: `(num_iou_thresholds,)`
        recall_per_class: the recall scores per class and IoU threshold.
            Shape: `(num_classes, num_iou_thresholds)`
        iou_thresholds: the IoU thresholds used in the calculations.
        matched_classes: the class IDs present in either predictions or ground
            truth. Corresponds to the rows of `recall_per_class`. Classes that
            appear only in predictions (no ground-truth instances) are included;
            their per-threshold recall values will be `0.0`.
        small_objects: the Recall metric results
            for small objects (area < 32Â²).
        medium_objects: the Recall metric results
            for medium objects (32Â² â‰¤ area < 96Â²).
        large_objects: the Recall metric results
            for large objects (area â‰¥ 96Â²).
    r   r   r   r   r$   Úfloatc                ó6   — t          | j        d         ¦  «        S )Nr   ©ré   rK   r'   s    r!   Úrecall_at_50zRecallResult.recall_at_50™  ó   € å�TÔ'¨Ô*Ñ+Ô+Ð+r#   c                ó6   — t          | j        d         ¦  «        S )Né   rë   r'   s    r!   Úrecall_at_75zRecallResult.recall_at_75�  rí   r#   r©   rK   rL   r„   rM   r…   rN   zRecallResult | Noner7   r9   r;   Ústrc                ó|  — | j         j        › d| j        › d| j        › d| j        d›d| j        d›d| j        › d| j        › d�}| j        j	        d	k    r|d
z  }t          | j        | j        ¦  «        D ]\  }}|d|› d|› d�z  }Œd}| j        �6|t          | j        ¦  «                             dd|› �¦  «        z   }|d|› �z  }| j        �6|t          | j        ¦  «                             dd|› �¦  «        z   }|d|› �z  }| j        �6|t          | j        ¦  «                             dd|› �¦  «        z   }|d|› �z  }|S )a=  
        Format as a pretty string.

        Example:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> from supervision.metrics import Recall
            >>> predictions = sv.Detections(
            ...     xyxy=np.array([[0, 0, 10, 10]]),
            ...     class_id=np.array([0]),
            ...     confidence=np.array([0.9])
            ... )
            >>> targets = sv.Detections(
            ...     xyxy=np.array([[0, 0, 10, 10]]),
            ...     class_id=np.array([0])
            ... )
            >>> recall_metric = Recall()
            >>> recall_result = recall_metric.update(predictions, targets).compute()
            >>> print(recall_result)  # doctest: +ELLIPSIS
            RecallResult:
            Metric target:    MetricTarget.BOXES
            Averaging method: AveragingMethod.WEIGHTED
            R @ 50:     1.0000
            R @ 75:     1.0000
            R @ thresh: [1. ... 1.]
            IoU thresh: [0.5  0.55 ... 0.95]
            Recall per class:
              0: [1. ... 1.]
            ...
            Medium objects:
              RecallResult:
              Metric target:    MetricTarget.BOXES
              Averaging method: AveragingMethod.WEIGHTED
              R @ 50:     0.0000
              ...

            ```
        z:
Metric target:    z
Averaging method: z
R @ 50:     z.4fz
R @ 75:     z
R @ thresh: z
IoU thresh: z
Recall per class:
r   z  No results
z  z: ú
Nz
Small objects:
z
Medium objects:
z
Large objects:
)Ú	__class__râ   r   r   rì   rð   rK   rM   rL   rc   rW   rN   r7   rñ   Úreplacer9   r;   )r    Úout_strr]   Úrecall_of_classÚindentÚindenteds         r!   Ú__str__zRecallResult.__str__ª  s×  € ðR Œ~Ô&ð #ð #Ø!%Ô!3ð#ð #à!%Ô!6ð#ð #ð  Ô,Ð4ð#ð #ð  Ô,Ð4ð	#ð #ð
  Ô-ð#ð #ð  Ô.ð#ð #ð #ð 	ð Ô Ô%¨Ò*Ð*ØÐ'Ñ'ˆGÝ),ØÔ  $Ô"7ñ*
ô *
ð 	<ð 	<Ñ%ˆH�oð Ð;˜HÐ;Ð;¨Ð;Ð;Ð;Ñ;ˆGˆGàˆØÔÐ)Ø¥ DÔ$6Ñ 7Ô 7× ?Ò ?ÀÀmÈ6ÀmÀmÑ TÔ TÑTˆHØÐ6¨HÐ6Ð6Ñ6ˆGØÔÐ*Ø¥ DÔ$7Ñ 8Ô 8× @Ò @ÀÀ}ÈFÀ}À}Ñ UÔ UÑUˆHØÐ7¨XÐ7Ð7Ñ7ˆGØÔÐ)Ø¥ DÔ$6Ñ 7Ô 7× ?Ò ?ÀÀmÈ6ÀmÀmÑ TÔ TÑTˆHØÐ6¨HÐ6Ð6Ñ6ˆGàˆr#   úpd.DataFramec                óö  — t          ¦   «          ddl}| j        | j        dœ}| j        �;| j                             ¦   «         }|                     ¦   «         D ]\  }}||d|› �<   Œ| j        �;| j                             ¦   «         }|                     ¦   «         D ]\  }}||d|› �<   Œ| j        �;| j                             ¦   «         }|                     ¦   «         D ]\  }}||d|› �<   Œ |j	        |dg¬¦  «        S )zt
        Convert the result to a pandas DataFrame.

        Returns:
            The result as a DataFrame.
        r   N)zR@50zR@75Úsmall_objects_Úmedium_objects_Úlarge_objects_)Úindex)
r   Úpandasrì   rð   r7   Ú	to_pandasrS   r9   r;   Ú	DataFrame)r    ÚpdÚpandas_dataÚsmall_objects_dfrÚ   r\   Úmedium_objects_dfÚlarge_objects_dfs           r!   r  zRecallResult.to_pandasð  sJ  € õ 	 Ñ!Ô!Ð!ØÐÐÐð Ô%ØÔ%ð'
ð '
ˆð
 ÔÐ)Ø#Ô1×;Ò;Ñ=Ô=ÐØ.×4Ò4Ñ6Ô6ð <ð <‘
��UØ6;�Ð2¨SÐ2Ð2Ñ3Ð3ØÔÐ*Ø $Ô 3× =Ò =Ñ ?Ô ?ÐØ/×5Ò5Ñ7Ô7ð =ð =‘
��UØ7<�Ð3¨cÐ3Ð3Ñ4Ð4ØÔÐ)Ø#Ô1×;Ò;Ñ=Ô=ÐØ.×4Ò4Ñ6Ô6ð <ð <‘
��UØ6;�Ð2¨SÐ2Ð2Ñ3Ð3àˆrŒ|˜K°¨sÐ3Ñ3Ô3Ð3r#   r%   c                ó¨  — ddl m} ddg}| j        | j        g}t          d         gdz  }| j        �3| j        }|ddgz  }||j        |j        gz  }|t          d	         gdz  z  }| j        �3| j        }|d
dgz  }||j        |j        gz  }|t          d         gdz  z  }| j        �3| j        }|ddgz  }||j        |j        gz  }|t          d         gdz  z  }d|j        d<   | 	                    d¬¦  «        \  }}	|	 
                    dd¦  «         |	                     dd¬¦  «         d| j        j        › d| j        j        › d�}
|	                     |
d¬¦  «         t!          t#          |¦  «        ¦  «        }|	                     |||d¬¦  «        }|	                     |¦  «         |	                     |dd¬¦  «         |D ]_}|                     ¦   «         }|	                     |                     ¦   «         |                     ¦   «         dz  z   |dz   |d ›dd!¬"¦  «         Œ`d#|j        d<   |                     ¦   «          |                     ¦   «          dS )$zÂ
        Plot the recall results.

        ![example_plot](
            https://media.roboflow.com/supervision-docs/metrics/recall_plot_example.png
        ){ align=center width="800" }
        r   )Úpyplotz	Recall@50z	Recall@75r»   NzSmall: R@50zSmall: R@75r«   zMedium: R@50zMedium: R@75zLarge: R@50zLarge: R@75rÏ   Ú	monospacezfont.family)rC   é   )ÚfigsizerH   ÚValueÚbold)Ú
fontweightz Recall, by Object Size
(target: z, averaging: ú)Úcenter)ÚcolorÚaligné-   Úright)ÚrotationÚhag{®Gáz”?z.2fÚbottom)r  Úvaz
sans-serif)Ú
matplotlibr
  rì   rð   r   r7   r9   r;   ÚrcParamsÚsubplotsÚset_ylimÚ
set_ylabelr   r\   r   Ú	set_titleÚranger/   ÚbarÚ
set_xticksÚset_xticklabelsÚ
get_heightÚtextÚget_xÚ	get_widthÚtight_layoutÚshow)r    ÚpltÚlabelsÚvaluesÚcolorsr7   r9   r;   r£   ÚaxÚtitleÚx_positionsÚbarsr"  Úy_values                  r!   ÚplotzRecallResult.plot  s¾  € ð 	-Ð,Ð,Ð,Ð,Ð,à˜{Ð+ˆØÔ# TÔ%6Ð7ˆÝ& qÔ)Ð*¨QÑ.ˆàÔÐ)Ø Ô.ˆMØ�} mÐ4Ñ4ˆFØ�}Ô1°=Ô3MÐNÑNˆFØÕ+¨AÔ.Ð/°!Ñ3Ñ3ˆFàÔÐ*Ø!Ô0ˆNØ�~ ~Ð6Ñ6ˆFØ�~Ô2°NÔ4OÐPÑPˆFØÕ+¨AÔ.Ð/°!Ñ3Ñ3ˆFàÔÐ)Ø Ô.ˆMØ�} mÐ4Ñ4ˆFØ�}Ô1°=Ô3MÐNÑNˆFØÕ+¨AÔ.Ð/°!Ñ3Ñ3ˆFà&1ˆŒ�]Ñ#à—’ W�Ñ-Ô-‰ˆˆ2Ø
�Š�A�qÑÔÐØ
�Š�g¨&ˆÑ1Ô1Ð1ð:ØÔ,Ô2ð:ð :àÔ0Ô6ð:ð :ð :ð 	ð
 	�Š�U vˆÑ.Ô.Ð.å�C ™KœKÑ(Ô(ˆØ�vŠv�k 6°¸xˆvÑHÔHˆà
�Š�kÑ"Ô"Ð"Ø
×Ò˜6¨B°7ÐÑ;Ô;Ð;àð 	ð 	ˆCØ—n’nÑ&Ô&ˆGØ�GŠGØ—	’	‘”˜cŸmšm™oœo°Ñ1Ñ1Ø˜$‘ØÐ Ð ØØð ñ ô ð ð ð '3ˆŒ�]Ñ#à×ÒÑÔÐØ�Š‰
Œ
ˆ
ˆ
ˆ
r#   N)r$   ré   )r$   rñ   )r$   rû   rá   )râ   rã   rä   rå   Ú__annotations__Úpropertyrì   rð   rú   r  r4  rç   r#   r!   r3   r3   w  s  € € € € € € ðð ð:  ÐÐÑØ%Ð%Ð%Ñ%àð,ð ,ð ,ñ „Xð,ð ð,ð ,ð ,ñ „Xð,ð +Ð*Ð*Ñ*Ø-Ð-Ð-Ñ-Ø+Ð+Ð+Ñ+Ø*Ð*Ð*Ñ*à&Ð&Ð&Ñ&Ø'Ð'Ð'Ñ'Ø&Ð&Ð&Ñ&ðDð Dð Dð DðL4ð 4ð 4ð 4ð<?ð ?ð ?ð ?ð ?ð ?r#   ))Ú
__future__r   Úcopyr   Údataclassesr   Útypingr   r   r   ÚnumpyrP   Únumpy.typingrg   Úsupervision.configr	   Ú"supervision.detection.compact_maskr
   Úsupervision.detection.corer   Ú'supervision.detection.utils.iou_and_nmsr   r   r   Úsupervision.draw.colorr   Úsupervision.metrics.corer   r   r   Ú"supervision.metrics.utils.matchingr   Ú%supervision.metrics.utils.object_sizer   r   Úsupervision.metrics.utils.utilsr   r  r  r   r3   rç   r#   r!   ú<module>rF     s   ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +à Ð Ð Ð Ø Ð Ð Ð Ð Ð à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø :Ð :Ð :Ð :Ð :Ð :Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1ðð ð ð ð ð ð ð ð ð ð
 8Ð 7Ð 7Ð 7Ð 7Ð 7Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jðð ð ð ð ð ðð ð ð ð ð ð ð ð DÐ CÐ CÐ CÐ CÐ Càð ØÐÐÐðS	6ð S	6ð S	6ð S	6ð S	6ˆV�NÔ#ñ S	6ô S	6ð S	6ðl ðUð Uð Uð Uð Uñ Uô Uñ „ðUð Uð Ur#   