§
    ’©ºjz¨  ã            	       óZ  — d dl Z d dlmZ d dlmZmZmZmZmZm	Z	 d dl
Zd dlZd dlmZ d dlmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZ esd
gZ eresd
dgZ  e j!        e"¦  «        Z#dde$e         ded         defd„Z%	 dde$e         de$e         ded         defd„Z& G d„ de'¦  «        Z( G d„ de(¦  «        Z) G d„ de(¦  «        Z* G d„ de(¦  «        Z+de$e,ej-        ej-        f                  de$e,ej-        ej-        f                  defd„Z. G d„ de¦  «        Z/dS ) é    N)ÚSequence)ÚAnyÚCallableÚListÚLiteralÚOptionalÚUnion)Ú	IntTensorÚTensor)Ú_fix_empty_tensorsÚ_input_validator)ÚMetric)Ú_cumsum)Ú_MATPLOTLIB_AVAILABLEÚ_PYCOCOTOOLS_AVAILABLEÚ_TORCHVISION_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzMeanAveragePrecision.plotÚMeanAveragePrecisionÚbboxÚinputsÚiou_type©r   ÚsegmÚreturnc                 ób  — ddl m} ddlm} t	          | ¦  «        dk    rt          g ¦  «        S |dk    r |t          j        | ¦  «        ¦  «        S |dk    rFd„ | D ¦   «         } t          j        | 	                    | ¦  «         
                    d¦  «        ¦  «        S t          d|› d	�¦  «        ‚)
z~Compute area of input depending on the specified iou_type.

    Default output for empty input is :class:`~torch.Tensor`

    r   N)Úbox_arear   r   c                 ó0   — g | ]}|d          |d         dœ‘ŒS ©r   é   )ÚsizeÚcounts© ©Ú.0Úis     úo/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/detection/_mean_ap.pyú
<listcomp>z compute_area.<locals>.<listcomp>5   s(   € ÐAÐAÐA°Q˜1˜Qœ4¨1¨Q¬4Ð0Ð0ÐAÐAÐAó    Úfloatú	IOU type ú is not supported)Úpycocotools.maskÚmaskÚtorchvision.opsr   Úlenr   ÚtorchÚstackÚtensorÚareaÚastypeÚ	Exception)r   r   Ú
mask_utilsr   s       r'   Úcompute_arear8   &   sÌ   € ð *Ð)Ð)Ð)Ð)Ð)Ø(Ð(Ð(Ð(Ð(Ð(å
ˆ6�{„{�aÒÐÝ�b‰zŒzÐà�6ÒÐØˆx�œ FÑ+Ô+Ñ,Ô,Ð,Ø�6ÒÐØAÐA¸&ÐAÑAÔAˆÝŒ|˜JŸOšO¨FÑ3Ô3×:Ò:¸7ÑCÔCÑDÔDÐDå
Ð; Ð;Ð;Ð;Ñ
<Ô
<Ð<r)   ÚdetÚgtc                 óÌ   — ddl m} |dk    r0 |t          j        | ¦  «        t          j        |¦  «        ¦  «        S |dk    rt	          | |¦  «        S t          d|› d�¦  «        ‚)zMCompute IOU between detections and ground-truth using the specified iou_type.r   )Úbox_iour   r   r+   r,   )r/   r<   r1   r2   Ú	_segm_iour6   )r9   r:   r   r<   s       r'   Úcompute_iour>   ;   sz   € ð (Ð'Ð'Ð'Ð'Ð'à�6ÒÐØˆw•u”{ 3Ñ'Ô'­¬°R©¬Ñ9Ô9Ð9Ø�6ÒÐÝ˜˜bÑ!Ô!Ð!Ý
Ð; Ð;Ð;Ð;Ñ
<Ô
<Ð<r)   c                   óF   — e Zd ZdZdedefd„Zdededdfd„Zdeddfd„ZdS )	ÚBaseMetricResultsz>Base metric class, that allows fields for pre-defined metrics.Úkeyr   c                 ó>   — || v r| |         S t          d|› �¦  «        ‚)z Get a specific metric attribute.úNo such attribute: ©ÚAttributeError©ÚselfrA   s     r'   Ú__getattr__zBaseMetricResults.__getattr__M   s.   € ð �$ˆ;ˆ;Ø˜”9ÐÝÐ8°3Ð8Ð8Ñ9Ô9Ð9r)   ÚvalueNc                 ó   — || |<   dS )z Set a specific metric attribute.Nr#   )rG   rA   rI   s      r'   Ú__setattr__zBaseMetricResults.__setattr__T   s   € àˆˆS‰	ˆ	ˆ	r)   c                 ó4   — || v r| |= t          d|› �¦  «        ‚)z#Delete a specific metric attribute.rC   rD   rF   s     r'   Ú__delattr__zBaseMetricResults.__delattr__X   s)   € à�$ˆ;ˆ;Ø�S�	ÝÐ8°3Ð8Ð8Ñ9Ô9Ð9r)   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   rH   rK   rM   r#   r)   r'   r@   r@   J   s‡   € € € € € ØHÐHð:˜sð : vð :ð :ð :ð :ð˜sð ¨6ð °dð ð ð ð ð:˜sð : tð :ð :ð :ð :ð :ð :r)   r@   c                   ó   — e Zd ZdZdZdS )ÚMAPMetricResultsz$Class to wrap the final mAP results.)ÚclassesÚmapÚmap_50Úmap_75Ú	map_largeÚ
map_mediumÚ	map_smallN©rN   rO   rP   rQ   Ú	__slots__r#   r)   r'   rT   rT   _   s   € € € € € Ø.Ð.à^€I€I€Ir)   rT   c                   ó   — e Zd ZdZdZdS )ÚMARMetricResultsz$Class to wrap the final mAR results.)Úmar_1Úmar_10Úmar_100Ú	mar_largeÚ
mar_mediumÚ	mar_smallNr\   r#   r)   r'   r_   r_   e   s   € € € € € Ø.Ð.àV€I€I€Ir)   r_   c                   ó   — e Zd ZdZdZdS )ÚCOCOMetricResultszMClass to wrap the final COCO metric results including various mAP/mAR values.)rV   rW   rX   rY   rZ   Úmap_per_classr[   r`   ra   rb   Úmar_100_per_classrc   rd   re   Nr\   r#   r)   r'   rg   rg   k   s   € € € € € ØWÐWð€I€I€Ir)   rg   c                 ó¤   — ddl m} d„ | D ¦   «         }d„ |D ¦   «         }t          j        |                     ||d„ |D ¦   «         ¦  «        ¦  «        S )a
  Compute IOU between detections and ground-truths using mask-IOU.

    Implementation is based on pycocotools toolkit for mask_utils.

    Args:
       det: A list of detection masks as ``[(RLE_SIZE, RLE_COUNTS)]``, where ``RLE_SIZE`` is (width, height) dimension
           of the input and RLE_COUNTS is its RLE representation;

       gt: A list of ground-truth masks as ``[(RLE_SIZE, RLE_COUNTS)]``, where ``RLE_SIZE`` is (width, height) dimension
           of the input and RLE_COUNTS is its RLE representation;

    r   Nc                 ó0   — g | ]}|d          |d         dœ‘ŒS r   r#   r$   s     r'   r(   z_segm_iou.<locals>.<listcomp>�   s(   € ÐCÐCÐC¸!  !¤°°!´Ð5Ð5ÐCÐCÐCr)   c                 ó0   — g | ]}|d          |d         dœ‘ŒS r   r#   r$   s     r'   r(   z_segm_iou.<locals>.<listcomp>�   s(   € ÐAÐAÐA¸˜q œt¨q°¬tÐ4Ð4ÐAÐAÐAr)   c                 ó   — g | ]}d ‘ŒS )Fr#   ©r%   Ú_s     r'   r(   z_segm_iou.<locals>.<listcomp>’   s   € ÐH[ÐH[ÐH[ÐSTÈÐH[ÐH[ÐH[r)   )r-   r.   r1   r3   Úiou)r9   r:   r7   Údet_coco_formatÚgt_coco_formats        r'   r=   r=   €   sl   € ð *Ð)Ð)Ð)Ð)Ð)àCÐC¸sÐCÑCÔC€OØAÐA¸bÐAÑAÔA€NåŒ<˜
Ÿš ¸ÐH[ÐH[ÐXZÐH[ÑH[ÔH[Ñ\Ô\Ñ]Ô]Ð]r)   c                   ó  ‡ — e Zd ZU dZdZeed<   dZee         ed<   dZ	eed<   dZ
eed<   d	Zeed
<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   	 	 	 	 	 	 dYdeded         deee                  deee                  deee                  dededdfˆ fd„Zdeeeef                  deeeef                  ddfd„ZdZd „Zd!eeef         deeef         fd"„Zdefd#„Zd$ed%ed&edefd'„Zd(ed)ed*eeef         d+edeeef         f
d,„Zd-ed$ed.ed&ed*eeef         d+edeeef         fd/„Zd$ed%ed*eeef         d&ed0edee         fd1„Ze d2ed3ed4ed5ed0ed6edefd7„¦   «         Z!	 	 	 	 d[d:ed;ed<ee         d*ed=edefd>„Z"d?edee#e$f         fd@„Z%dAedBedee#e$f         fdC„Z&e dDedEedFedGedHedIedJeded&edKedLedeeeef         fdM„¦   «         Z'defdN„Z(dOe)de*j+        j,        fˆ fdP„Z-d\dQee)         dRee         ddfˆ fdS„Z.e 	 d]dTeeeef                  dRee         dee         fdU„¦   «         Z/	 d\dVeeeeef         e0eeef                  f                  dWee1         de2fdX„Z3ˆ xZ4S )^r   a¸  Compute the `Mean-Average-Precision (mAP) and Mean-Average-Recall (mAR)`_ for object detection predictions.

    .. math::
        \text{mAP} = \frac{1}{n} \sum_{i=1}^{n} AP_i

    where :math:`AP_i` is the average precision for class :math:`i` and :math:`n` is the number of classes. The average
    precision is defined as the area under the precision-recall curve. If argument `class_metrics` is set to ``True``,
    the metric will also return the mAP/mAR per class.

    As input to ``forward`` and ``update`` the metric accepts the following input:

    - ``preds`` (:class:`~List`): A list consisting of dictionaries each containing the key-values
      (each dictionary corresponds to a single image). Parameters that should be provided per dict

        - boxes: (:class:`~torch.FloatTensor`) of shape ``(num_boxes, 4)`` containing ``num_boxes`` detection
          boxes of the format specified in the constructor.
          By default, this method expects ``(xmin, ymin, xmax, ymax)`` in absolute image coordinates.
        - scores: :class:`~torch.FloatTensor` of shape ``(num_boxes)`` containing detection scores for the boxes.
        - labels: :class:`~torch.IntTensor` of shape ``(num_boxes)`` containing 0-indexed detection classes for
          the boxes.
        - masks: :class:`~torch.bool` of shape ``(num_boxes, image_height, image_width)`` containing boolean masks.
          Only required when `iou_type="segm"`.

    - ``target`` (:class:`~List`) A list consisting of dictionaries each containing the key-values
      (each dictionary corresponds to a single image). Parameters that should be provided per dict:

        - boxes: :class:`~torch.FloatTensor` of shape ``(num_boxes, 4)`` containing ``num_boxes`` ground truth
          boxes of the format specified in the constructor.
          By default, this method expects ``(xmin, ymin, xmax, ymax)`` in absolute image coordinates.
        - labels: :class:`~torch.IntTensor` of shape ``(num_boxes)`` containing 0-indexed ground truth
          classes for the boxes.
        - masks: :class:`~torch.bool` of shape ``(num_boxes, image_height, image_width)`` containing boolean masks.
          Only required when `iou_type="segm"`.

    As output of ``forward`` and ``compute`` the metric returns the following output:

    - ``map_dict``: A dictionary containing the following key-values:

        - map: (:class:`~torch.Tensor`)
        - map_small: (:class:`~torch.Tensor`)
        - map_medium:(:class:`~torch.Tensor`)
        - map_large: (:class:`~torch.Tensor`)
        - mar_1: (:class:`~torch.Tensor`)
        - mar_10: (:class:`~torch.Tensor`)
        - mar_100: (:class:`~torch.Tensor`)
        - mar_small: (:class:`~torch.Tensor`)
        - mar_medium: (:class:`~torch.Tensor`)
        - mar_large: (:class:`~torch.Tensor`)
        - map_50: (:class:`~torch.Tensor`) (-1 if 0.5 not in the list of iou thresholds)
        - map_75: (:class:`~torch.Tensor`) (-1 if 0.75 not in the list of iou thresholds)
        - map_per_class: (:class:`~torch.Tensor`) (-1 if class metrics are disabled)
        - mar_100_per_class: (:class:`~torch.Tensor`) (-1 if class metrics are disabled)
        - classes (:class:`~torch.Tensor`)

    For an example on how to use this metric check the `torchmetrics mAP example`_.

    .. attention::
        The ``map`` score is calculated with @[ IoU=self.iou_thresholds | area=all | max_dets=max_detection_thresholds ]
        **Caution:** If the initialization parameters are changed, dictionary keys for mAR can change as well.
        The default properties are also accessible via fields and will raise an ``AttributeError`` if not available.

    .. important::
        This metric is following the mAP implementation of `pycocotools`_ a standard implementation for the mAP metric
        for object detection.

    .. hint::
        This metric requires you to have `torchvision` version 0.8.0 or newer installed
        (with corresponding version 1.7.0 of torch or newer). This metric requires `pycocotools`
        installed when iou_type is `segm`. Please install with ``pip install torchvision`` or
        ``pip install torchmetrics[detection]``.

    Args:
        box_format:
            Input format of given boxes. Supported formats are ``[`xyxy`, `xywh`, `cxcywh`]``.
        iou_type:
            Type of input (either masks or bounding-boxes) used for computing IOU.
            Supported IOU types are ``["bbox", "segm"]``.
            If using ``"segm"``, masks should be provided (see :meth:`update`).
        iou_thresholds:
            IoU thresholds for evaluation. If set to ``None`` it corresponds to the stepped range ``[0.5,...,0.95]``
            with step ``0.05``. Else provide a list of floats.
        rec_thresholds:
            Recall thresholds for evaluation. If set to ``None`` it corresponds to the stepped range ``[0,...,1]``
            with step ``0.01``. Else provide a list of floats.
        max_detection_thresholds:
            Thresholds on max detections per image. If set to `None` will use thresholds ``[1, 10, 100]``.
            Else, please provide a list of ints.
        class_metrics:
            Option to enable per-class metrics for mAP and mAR_100. Has a performance impact.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ModuleNotFoundError:
            If ``torchvision`` is not installed or version installed is lower than 0.8.0
        ModuleNotFoundError:
            If ``iou_type`` is equal to ``segm`` and ``pycocotools`` is not installed
        ValueError:
            If ``class_metrics`` is not a boolean
        ValueError:
            If ``preds`` is not of type (:class:`~List[Dict[str, Tensor]]`)
        ValueError:
            If ``target`` is not of type ``List[Dict[str, Tensor]]``
        ValueError:
            If ``preds`` and ``target`` are not of the same length
        ValueError:
            If any of ``preds.boxes``, ``preds.scores`` and ``preds.labels`` are not of the same length
        ValueError:
            If any of ``target.boxes`` and ``target.labels`` are not of the same length
        ValueError:
            If any box is not type float and of length 4
        ValueError:
            If any class is not type int and of length 1
        ValueError:
            If any score is not type float and of length 1

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.detection import MeanAveragePrecision
        >>> preds = [
        ...   dict(
        ...     boxes=tensor([[258.0, 41.0, 606.0, 285.0]]),
        ...     scores=tensor([0.536]),
        ...     labels=tensor([0]),
        ...   )
        ... ]
        >>> target = [
        ...   dict(
        ...     boxes=tensor([[214.0, 41.0, 562.0, 285.0]]),
        ...     labels=tensor([0]),
        ...   )
        ... ]
        >>> metric = MeanAveragePrecision()
        >>> metric.update(preds, target)
        >>> from pprint import pprint
        >>> pprint(metric.compute())
        {'classes': tensor(0, dtype=torch.int32),
         'map': tensor(0.6000),
         'map_50': tensor(1.),
         'map_75': tensor(1.),
         'map_large': tensor(0.6000),
         'map_medium': tensor(-1.),
         'map_per_class': tensor(-1.),
         'map_small': tensor(-1.),
         'mar_1': tensor(0.6000),
         'mar_10': tensor(0.6000),
         'mar_100': tensor(0.6000),
         'mar_100_per_class': tensor(-1.),
         'mar_large': tensor(0.6000),
         'mar_medium': tensor(-1.),
         'mar_small': tensor(-1.)}

    FÚis_differentiableTÚhigher_is_betterÚfull_state_updateç        Úplot_lower_boundç      ð?Úplot_upper_boundÚ
detectionsÚdetection_scoresÚdetection_labelsÚgroundtruthsÚgroundtruth_labelsÚxyxyr   NÚ
box_formatr   r   Úiou_thresholdsÚrec_thresholdsÚmax_detection_thresholdsÚclass_metricsÚkwargsr   c                 ó  •—  t          ¦   «         j        di |¤Ž t          st          d¦  «        ‚t          st          d¦  «        ‚d}d}	||vrt          d|› d|› �¦  «        ‚|| _        |p7t          j        ddt          d	¦  «        d
z   ¦  «         
                    ¦   «         | _        |p7t          j        ddt          d¦  «        d
z   ¦  «         
                    ¦   «         | _        t          j        t          |pg d¢¦  «        ¦  «        \  }
}|
 
                    ¦   «         | _        ||	vrt          d|	› d|› �¦  «        ‚|dk    rt          st          d¦  «        ‚|| _        t#          d¦  «        t#          d¦  «        ft#          d¦  «        t#          d¦  «        ft#          d¦  «        t#          d¦  «        ft#          d¦  «        t#          d¦  «        fdœ| _        t'          |t(          ¦  «        st          d¦  «        ‚|| _        |                      dg d ¬¦  «         |                      dg d ¬¦  «         |                      dg d ¬¦  «         |                      dg d ¬¦  «         |                      dg d ¬¦  «         d S )NzŠ`MAP` metric requires that `pycocotools` installed. Please install with `pip install pycocotools` or `pip install torchmetrics[detection]`z‚`MeanAveragePrecision` metric requires that `torchvision` is installed. Please install with `pip install torchmetrics[detection]`.)r€   ÚxywhÚcxcywh)r   r   z,Expected argument `box_format` to be one of z	 but got ç      à?gffffffî?gÿÿÿÿÿÿ!@r    rw   ry   g      Y@)r    é
   éd   z*Expected argument `iou_type` to be one of r   zBWhen `iou_type` is set to 'segm', pycocotools need to be installedr   g    _ Bi   i $  )ÚallÚsmallÚmediumÚlargez1Expected argument `class_metrics` to be a booleanr{   )ÚdefaultÚdist_reduce_fxr|   r}   r~   r   r#   )ÚsuperÚ__init__r   ÚModuleNotFoundErrorr   Ú
ValueErrorr�   r1   ÚlinspaceÚroundÚtolistr‚   rƒ   Úsortr
   r„   r   r*   Úbbox_area_rangesÚ
isinstanceÚboolr…   Ú	add_state)rG   r�   r   r‚   rƒ   r„   r…   r†   Úallowed_box_formatsÚallowed_iou_typesÚmax_det_thresholdro   Ú	__class__s               €r'   r”   zMeanAveragePrecision.__init__;  s°  ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ý%ð 	Ý%ðjñô ð õ &ð 	Ý%ðNñô ð ð
 9ÐØ,ÐØÐ0Ð0Ð0ÝÐvÐL_ÐvÐvÐjtÐvÐvÑwÔwÐwØ$ˆŒØ,Ðrµ´¸sÀDÍ%ÐPcÑJdÔJdÐghÑJhÑ0iÔ0i×0pÒ0pÑ0rÔ0rˆÔØ,Ðjµ´¸sÀDÍ%ÐP[ÑJ\ÔJ\Ð_`ÑJ`Ñ0aÔ0a×0hÒ0hÑ0jÔ0jˆÔÝ$œz­)Ð4LÐ4\ÐP\ÐP\ÐP\Ñ*]Ô*]Ñ^Ô^ÑÐ˜1Ø(9×(@Ò(@Ñ(BÔ(BˆÔ%ØÐ,Ð,Ð,ÝÐpÐJ[ÐpÐpÐfnÐpÐpÑqÔqÐqØ�vÒÐÕ&<ÐÝ%Ð&jÑkÔkÐkØ ˆŒå˜$‘K”K¥ v¡¤Ð/Ý˜D‘k”k¥5¨¡<¤<Ð0Ý˜U‘|”|¥U¨5¡\¤\Ð2Ý˜E‘l”l¥E¨&¡M¤MÐ2ð	!
ð !
ˆÔõ ˜-­Ñ.Ô.ð 	RÝÐPÑQÔQÐQà*ˆÔØ�Š�|¨RÀˆÑEÔEÐEØ�ŠÐ)°2ÀdˆÑKÔKÐKØ�ŠÐ)°2ÀdˆÑKÔKÐKØ�Š�~¨rÀ$ˆÑGÔGÐGØ�ŠÐ+°RÈˆÑMÔMÐMÐMÐMr)   ÚpredsÚtargetc                 óÄ  — t          ||| j        ¬¦  «         |D ]q}|                      |¦  «        }| j                             |¦  «         | j                             |d         ¦  «         | j                             |d         ¦  «         Œr|D ]Q}|                      |¦  «        }| j                             |¦  «         | j                             |d         ¦  «         ŒRdS )z*Update state with predictions and targets.©r   ÚlabelsÚscoresN)	r   r   Ú_get_safe_item_valuesr{   Úappendr}   r|   r~   r   )rG   r£   r¤   Úitemr{   r~   s         r'   ÚupdatezMeanAveragePrecision.updatep  së   € å˜ °´Ð?Ñ?Ô?Ð?àð 	9ð 	9ˆDØ×3Ò3°DÑ9Ô9ˆJàŒO×"Ò" :Ñ.Ô.Ð.ØÔ!×(Ò(¨¨h¬Ñ8Ô8Ð8ØÔ!×(Ò(¨¨h¬Ñ8Ô8Ð8Ð8àð 	;ð 	;ˆDØ×5Ò5°dÑ;Ô;ˆLØÔ×$Ò$ \Ñ2Ô2Ð2ØÔ#×*Ò*¨4°¬>Ñ:Ô:Ð:Ð:ð	;ð 	;r)   c                 ó  — | j         D ]~}t          | |¦  «        }g }t          |t          ¦  «        rD|D ]A}t          |t          ¦  «        s|                     d¦  «        }|                     |¦  «         ŒBt          | ||¦  «         ŒdS )z+Move list states to cpu to save GPU memory.ÚcpuN)Ú	_defaultsÚgetattrrœ   r   ÚtupleÚtorª   Úsetattr)rG   rA   Úcurrent_valÚcurrent_to_cpuÚcur_vs        r'   Ú_move_list_states_to_cpuz-MeanAveragePrecision._move_list_states_to_cpu€  sŸ   € à”>ð 		/ð 		/ˆCÝ! $¨Ñ,Ô,ˆKØˆNÝ˜+¥xÑ0Ô0ð 1Ø(ð 1ð 1�Eå% e­UÑ3Ô3ð 0Ø %§¢¨¡¤˜Ø"×)Ò)¨%Ñ0Ô0Ð0Ð0Ý�D˜#˜~Ñ.Ô.Ð.Ð.ð		/ð 		/r)   r«   c                 ó(  — dd l m} ddlm} | j        dk    rBt          |d         ¦  «        }|                     ¦   «         dk    r ||| j        d¬¦  «        }|S | j        dk    r—g }|d                              ¦   «          	                    ¦   «         D ]Y}| 
                    t          j        |¦  «        ¦  «        }|                     t          |d	         ¦  «        |d
         f¦  «         ŒZt          |¦  «        S t          d| j        › d�¦  «        ‚)Nr   )Úbox_convertr   Úboxesr€   )Úin_fmtÚout_fmtr   Úmasksr!   r"   r+   r,   )r-   r.   r/   r¹   r   r   Únumelr�   r®   ÚnumpyÚencodeÚnpÚasfortranarrayrª   r±   r6   )rG   r«   r7   r¹   rº   r½   r&   Úrles           r'   r©   z*MeanAveragePrecision._get_safe_item_values�  s#  € Ø-Ð-Ð-Ð-Ð-Ð-Ø/Ð/Ð/Ð/Ð/Ð/àŒ=˜FÒ"Ð"Ý& t¨G¤}Ñ5Ô5ˆEØ�{Š{‰}Œ}˜qÒ Ð Ø#˜ E°$´/È6ÐRÑRÔR�ØˆLØŒ=˜FÒ"Ð"ØˆEØ˜'”]×&Ò&Ñ(Ô(×.Ò.Ñ0Ô0ð Bð B�Ø ×'Ò'­Ô(9¸!Ñ(<Ô(<Ñ=Ô=�Ø—’�e C¨¤KÑ0Ô0°#°h´-Ð@ÑAÔAÐAÐAÝ˜‘<”<ÐÝÐD D¤MÐDÐDÐDÑEÔEÐEr)   c                 óð   — t          | j        ¦  «        dk    st          | j        ¦  «        dk    rEt          j        | j        | j        z   ¦  «                             ¦   «                              ¦   «         S g S )zIReturn a list of unique classes found in ground truth and detection data.r   )r0   r}   r   r1   ÚcatÚuniquer™   )rG   s    r'   Ú_get_classesz!MeanAveragePrecision._get_classesž  se   € åˆtÔ$Ñ%Ô%¨Ò)Ð)­S°Ô1HÑ-IÔ-IÈAÒ-MÐ-MÝ”9˜TÔ2°TÔ5LÑLÑMÔM×TÒTÑVÔV×]Ò]Ñ_Ô_Ð_Øˆ	r)   ÚidxÚclass_idÚmax_detc                 óD  ‡	‡
— | j         |         Š
| j        |         Š	| j        |         |k                         ¦   «                              d¦  «        }| j        |         |k                         ¦   «                              d¦  «        }t          |¦  «        dk    st          |¦  «        dk    rt          g ¦  «        S ˆ
fd„|D ¦   «         Š
ˆ	fd„|D ¦   «         Š	t          ‰
¦  «        dk    st          ‰	¦  «        dk    rt          g ¦  «        S | j        |         }|| j        |         |k             }t          j
        |d¬¦  «        }ˆ	fd„|D ¦   «         Š	t          ‰	¦  «        |k    r
‰	d|…         Š	t          ‰	‰
| j        ¦  «                             | j        ¦  «        S )	aŠ  Compute the Intersection over Union (IoU) between bounding boxes for the given image and class.

        Args:
            idx:
                Image Id, equivalent to the index of supplied samples
            class_id:
                Class Id of the supplied ground truth and detection labels
            max_det:
                Maximum number of evaluated detection bounding boxes

        r    r   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   ©r%   r&   r:   s     €r'   r(   z5MeanAveragePrecision._compute_iou.<locals>.<listcomp>º  ó   ø€ Ð+Ð+Ð+˜ˆb�ŒeÐ+Ð+Ð+r)   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   ©r%   r&   r9   s     €r'   r(   z5MeanAveragePrecision._compute_iou.<locals>.<listcomp>»  ó   ø€ Ð.Ð.Ð.˜!ˆs�1ŒvÐ.Ð.Ð.r)   T©Ú
descendingc                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÐ   s     €r'   r(   z5MeanAveragePrecision._compute_iou.<locals>.<listcomp>Æ  s   ø€ Ð$Ð$Ð$˜!ˆs�1ŒvÐ$Ð$Ð$r)   N)r~   r{   r   ÚnonzeroÚsqueezer}   r0   r   r|   r1   Úargsortr>   r   r²   Údevice)rG   rÈ   rÉ   rÊ   Úgt_label_maskÚdet_label_maskr¨   Úscores_filteredÚindsr9   r:   s            @@r'   Ú_compute_iouz!MeanAveragePrecision._compute_iou¤  sœ  øø€ ð Ô˜sÔ#ˆØŒo˜cÔ"ˆàÔ0°Ô5¸ÒA×JÒJÑLÔL×TÒTÐUVÑWÔWˆØÔ/°Ô4¸Ò@×IÒIÑKÔK×SÒSÐTUÑVÔVˆåˆ}ÑÔ Ò"Ð"¥c¨.Ñ&9Ô&9¸QÒ&>Ð&>Ý˜"‘:”:Ðà+Ð+Ð+Ð+˜]Ð+Ñ+Ô+ˆØ.Ð.Ð.Ð.˜~Ð.Ñ.Ô.ˆåˆr‰7Œ7�aŠ<ˆ<�3˜s™8œ8 qš=˜=Ý˜"‘:”:Ðð Ô& sÔ+ˆØ  Ô!6°sÔ!;¸xÒ!GÔHˆÝŒ}˜_¸Ð>Ñ>Ô>ˆð %Ð$Ð$Ð$˜tÐ$Ñ$Ô$ˆÝˆs‰8Œ8�gÒÐØ�h�w�h”-ˆCå˜3  D¤MÑ2Ô2×5Ò5°d´kÑBÔBÐBr)   r:   rÙ   Ú
area_rangeÚnum_iou_thrsc                 ó¶  ‡— ˆfd„|D ¦   «         Št          ‰¦  «        }t          ‰| j        ¬¦  «                             | j        ¦  «        }||d         k     ||d         k    z  }t          j        |                     t
          j        ¦  «        ¦  «        \  }}	|                     t
          j        ¦  «        }d}
t          j	        ||
ft
          j        | j        ¬¦  «        }t          j	        ||
ft
          j        | j        ¬¦  «        t          j	        ||ft
          j        | j        ¬¦  «        t          j	        |
t
          j
        | j        ¬¦  «        ||dœS )z7Evaluate images with a ground truth but no predictions.c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÍ   s     €r'   r(   zEMeanAveragePrecision.__evaluate_image_gt_no_preds.<locals>.<listcomp>Ñ  rÎ   r)   r¦   r   r    ©ÚdtyperØ   ©Ú	dtMatchesÚ	gtMatchesÚdtScoresÚgtIgnoreÚdtIgnore)r0   r8   r   r²   rØ   r1   rš   Úuint8r�   ÚzerosÚfloat32)rG   r:   rÙ   rÞ   rß   Únum_gtÚareasÚignore_areaÚ	gt_ignorero   Únum_detÚ
det_ignores    `          r'   Ú__evaluate_image_gt_no_predsz1MeanAveragePrecision.__evaluate_image_gt_no_predsÌ  s2  ø€ ð
 ,Ð+Ð+Ð+˜]Ð+Ñ+Ô+ˆÝ�R‘”ˆÝ˜R¨$¬-Ð8Ñ8Ô8×;Ò;¸D¼KÑHÔHˆØ˜z¨!œ}Ò,°¸ÀA¼Ò1FÑGˆÝ”z +§.¢.µ´Ñ"=Ô"=Ñ>Ô>‰ˆ	�1Ø—L’L¥¤Ñ,Ô,ˆ	ð ˆÝ”[ ,°Ð!8ÅÄ
ÐSWÔS^Ð_Ñ_Ô_ˆ
õ œ l°GÐ%<ÅEÄJÐW[ÔWbÐcÑcÔcÝœ l°FÐ%;Å5Ä:ÐVZÔVaÐbÑbÔbÝœ Gµ5´=ÈÌÐUÑUÔUØ!Ø"ð
ð 
ð 	
r)   r9   rÚ   c                 ó`  ‡— d}t          j        |t           j        | j        ¬¦  «        }ˆfd„|D ¦   «         Š| j        |         }	|	|         }
t          j        |
d¬¦  «        \  }}ˆfd„|D ¦   «         Št          ‰¦  «        |k    r
‰d|…         Št          ‰¦  «        }t          ‰| j        ¬¦  «         	                    | j        ¦  «        }||d         k     ||d	         k    z  }| 
                    d	|f¦  «        }t          j        ||d¦  «        }t          j        ||ft           j        | j        ¬¦  «        t          j        ||ft           j        | j        ¬¦  «        | 	                    | j        ¦  «        | 	                    | j        ¦  «        | 	                    | j        ¦  «        d
œS )z6Evaluate images with a prediction but no ground truth.r   râ   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÐ   s     €r'   r(   zEMeanAveragePrecision.__evaluate_image_preds_no_gt.<locals>.<listcomp>õ  rÑ   r)   TrÒ   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÐ   s     €r'   r(   zEMeanAveragePrecision.__evaluate_image_preds_no_gt.<locals>.<listcomp>ú  ó   ø€ Ð%Ð%Ð%˜!ˆs�1ŒvÐ%Ð%Ð%r)   Nr¦   r    rä   )r1   rë   r�   rØ   r|   rš   r0   r8   r   r²   ÚreshapeÚrepeat_interleave)rG   r9   rÈ   rÚ   rÊ   rÞ   rß   rí   rð   r¨   rÛ   Úscores_sortedÚdtindrñ   Ú	det_areasÚdet_ignore_areaÚarrò   s    `                r'   Ú__evaluate_image_preds_no_gtz1MeanAveragePrecision.__evaluate_image_preds_no_gtä  s¡  ø€ ð ˆå”K ­e¬jÀÄÐMÑMÔMˆ	ð /Ð.Ð.Ð.˜~Ð.Ñ.Ô.ˆØÔ& sÔ+ˆØ  Ô0ˆÝ$œz¨/ÀdÐKÑKÔKÑˆ�uà%Ð%Ð%Ð%˜uÐ%Ñ%Ô%ˆÝˆs‰8Œ8�gÒÐØ�h�w�h”-ˆCÝ�c‘(”(ˆÝ  ¨t¬}Ð=Ñ=Ô=×@Ò@ÀÄÑMÔMˆ	Ø$ z°!¤}Ò4¸ÀZÐPQÄ]Ò9RÑSˆØ×$Ò$ a¨ \Ñ2Ô2ˆÝÔ,¨R°¸qÑAÔAˆ
õ œ l°GÐ%<ÅEÄJÐW[ÔWbÐcÑcÔcÝœ l°FÐ%;Å5Ä:ÐVZÔVaÐbÑbÔbØ%×(Ò(¨¬Ñ5Ô5Ø!Ÿš T¤[Ñ1Ô1Ø"Ÿš d¤kÑ2Ô2ð
ð 
ð 	
r)   Úiousc                 óÖ
  ‡‡ — | j         |         Š | j        |         Š| j        |         |k                         ¦   «                              d¦  «        }| j        |         |k                         ¦   «                              d¦  «        }t          |¦  «        dk    rt          |¦  «        dk    rdS t          | j        ¦  «        }t          |¦  «        dk    r+t          |¦  «        dk    r|                      ‰ |||¦  «        S t          |¦  «        dk    r-t          |¦  «        dk    r|  	                    ‰|||||¦  «        S ˆ fd„|D ¦   «         Š ˆfd„|D ¦   «         Št          ‰ ¦  «        dk    rt          ‰¦  «        dk    rdS t          ‰t          ¦  «        r‰gŠt          ‰ t          ¦  «        r‰ gŠ t          ‰ | j        ¬¦  «                             | j        ¦  «        }	t!          j        |	|d         k     |	|d         k    ¦  «        }
t!          j        |
                     t           j        ¦  «        ¦  «        \  }}|                     t           j        ¦  «                             | j        ¦  «        }ˆ fd„|D ¦   «         Š | j        |         }||         }t!          j        |d¬	¦  «        \  }}ˆfd
„|D ¦   «         Št          ‰¦  «        |k    r
‰d|…         Št          |||f         ¦  «        dk    r|||f         dd…|f         n	|||f         }t          | j        ¦  «        }t          ‰ ¦  «        }t          ‰¦  «        }t!          j        ||ft           j        | j        ¬¦  «        }t!          j        ||ft           j        | j        ¬¦  «        }|}t!          j        ||ft           j        | j        ¬¦  «        }t!          j        |¦  «        dk    rpt1          | j        ¦  «        D ][\  }}t1          ‰¦  «        D ]F\  }}t2                               ||||||¦  «        }|dk    rŒ+||         |||f<   d|||f<   d|||f<   ŒGŒ\t          ‰| j        ¬¦  «                             | j        ¦  «        }||d         k     ||d         k    z  }|                     d|f¦  «        }t!          j        |t!          j        |dk    t!          j        ||d¦  «        ¦  «        ¦  «        }|                     | j        ¦  «        |                     | j        ¦  «        |                     | j        ¦  «        |                     | j        ¦  «        |                     | j        ¦  «        dœS )aü  Perform evaluation for single class and image.

        Args:
            idx:
                Image Id, equivalent to the index of supplied samples.
            class_id:
                Class Id of the supplied ground truth and detection labels.
            area_range:
                List of lower and upper bounding box area threshold.
            max_det:
                Maximum number of evaluated detection bounding boxes.
            ious:
                IoU results for image and class.

        r    r   Nc                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÍ   s     €r'   r(   z8MeanAveragePrecision._evaluate_image.<locals>.<listcomp>0  rÎ   r)   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÐ   s     €r'   r(   z8MeanAveragePrecision._evaluate_image.<locals>.<listcomp>1  rÑ   r)   r¦   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÍ   s     €r'   r(   z8MeanAveragePrecision._evaluate_image.<locals>.<listcomp>C  s   ø€ Ð#Ð#Ð#˜ˆb�ŒeÐ#Ð#Ð#r)   TrÒ   c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   rÐ   s     €r'   r(   z8MeanAveragePrecision._evaluate_image.<locals>.<listcomp>G  r÷   r)   râ   éÿÿÿÿrä   )r~   r{   r   rÕ   rÖ   r}   r0   r‚   Ú1_MeanAveragePrecision__evaluate_image_gt_no_predsÚ1_MeanAveragePrecision__evaluate_image_preds_no_gtrœ   Údictr8   r   r²   rØ   r1   Ú
logical_orrš   rê   r�   r|   rë   r¾   Ú	enumerater   Ú_find_best_gt_matchrø   Úlogical_andrù   )!rG   rÈ   rÉ   rÞ   rÊ   r   rÙ   rÚ   rß   rî   rï   Úignore_area_sortedÚgtindr¨   rÛ   rú   rû   rí   rñ   Ú
gt_matchesÚdet_matchesrð   rò   Úidx_iouÚtÚidx_detro   Úmrü   rý   rþ   r9   r:   s!                                  @@r'   Ú_evaluate_imagez$MeanAveragePrecision._evaluate_image  s^  øø€ ð$ Ô˜sÔ#ˆØŒo˜cÔ"ˆØÔ0°Ô5¸ÒA×JÒJÑLÔL×TÒTÐUVÑWÔWˆØÔ/°Ô4¸Ò@×IÒIÑKÔK×SÒSÐTUÑVÔVˆõ ˆ}ÑÔ Ò"Ð"¥s¨>Ñ':Ô':¸aÒ'?Ð'?Ø�4å˜4Ô.Ñ/Ô/ˆõ ˆ}ÑÔ Ò!Ð!¥c¨.Ñ&9Ô&9¸QÒ&>Ð&>Ø×4Ò4°R¸È
ÐT`ÑaÔaÐaõ ˆ}ÑÔ Ò"Ð"¥s¨>Ñ':Ô':¸QÒ'>Ð'>Ø×4Ò4°S¸#¸~ÈwÐXbÐdpÑqÔqÐqà+Ð+Ð+Ð+˜]Ð+Ñ+Ô+ˆØ.Ð.Ð.Ð.˜~Ð.Ñ.Ô.ˆÝˆr‰7Œ7�aŠ<ˆ<�C ™HœH¨šM˜MØ�4Ý�c�4Ñ Ô ð 	Ø�%ˆCÝ�b�$ÑÔð 	Ø�ˆBå˜R¨$¬-Ð8Ñ8Ô8×;Ò;¸D¼KÑHÔHˆåÔ& u¨z¸!¬}Ò'<¸eÀjÐQRÄmÒ>SÑTÔTˆõ %*¤J¨{¯~ª~½e¼kÑ/JÔ/JÑ$KÔ$KÑ!Ð˜Eð 0×2Ò2µ5´:Ñ>Ô>×AÒAÀ$Ä+ÑNÔNÐà#Ð#Ð#Ð#˜UÐ#Ñ#Ô#ˆØÔ& sÔ+ˆØ  Ô0ˆÝ$œz¨/ÀdÐKÑKÔKÑˆ�uØ%Ð%Ð%Ð%˜uÐ%Ñ%Ô%ˆÝˆs‰8Œ8�gÒÐØ�h�w�h”-ˆCå03°D¸¸h¸Ô4GÑ0HÔ0HÈ1Ò0LÐ0Lˆt�C˜�MÔ" 1 1 1 e 8Ô,Ð,ÐRVÐWZÐ\dÐWdÔReˆå˜4Ô.Ñ/Ô/ˆÝ�R‘”ˆÝ�c‘(”(ˆÝ”[ ,°Ð!7½u¼zÐRVÔR]Ð^Ñ^Ô^ˆ
Ý”k <°Ð"9ÅÄÐTXÔT_Ð`Ñ`Ô`ˆØ&ˆ	Ý”[ ,°Ð!8ÅÄ
ÐSWÔS^Ð_Ñ_Ô_ˆ
åŒ;�tÑÔ˜qÒ Ð Ý'¨Ô(;Ñ<Ô<ð /ð /‘
�˜Ý"+¨C¡.¤.ð /ð /‘J�G˜QÝ,×@Ò@ÀÀJÐPWÐYbÐdhÐjqÑrÔr�AØ˜B’w�wØ Ø3<¸Q´<�J˜w¨Ð/Ñ0Ø45�K ¨Ð 0Ñ1Ø-.�J˜w¨˜zÑ*Ð*ð/õ ! ¨t¬}Ð=Ñ=Ô=×@Ò@ÀÄÑMÔMˆ	Ø$ z°!¤}Ò4¸ÀZÐPQÄ]Ò9RÑSˆØ×$Ò$ a¨ \Ñ2Ô2ˆÝÔ%Ø�Ô)¨+¸Ò*:½EÔ<SÐTVÐXdÐfgÑ<hÔ<hÑiÔiñ
ô 
ˆ
ð
 %Ÿš¨¬Ñ4Ô4Ø#Ÿš t¤{Ñ3Ô3Ø%×(Ò(¨¬Ñ5Ô5Ø!Ÿš T¤[Ñ1Ô1Ø"Ÿš d¤kÑ2Ô2ð
ð 
ð 	
r)   Ú	thresholdr  r  rð   r  c                 ó    — ||         }||z  }||         | z  }|                      ¦   «                              ¦   «         }	||	         | k    r|	S dS )a0  Return id of best ground truth match with current detection.

        Args:
            threshold:
                Current threshold value.
            gt_matches:
                Tensor showing if a ground truth matches for threshold ``t`` exists.
            idx_iou:
                Id of threshold ``t``.
            gt_ignore:
                Tensor showing if ground truth should be ignored.
            ious:
                IoUs for all combinations of detection and ground truth.
            idx_det:
                Id of current detection.

        r  )Úargmaxr«   )
r  r  r  rð   r   r  Úpreviously_matchedÚremove_maskÚgt_iousÚ	match_idxs
             r'   r  z(MeanAveragePrecision._find_best_gt_matcho  s_   € ð* (¨Ô0Ðà(¨9Ñ4ˆØ�w”- ; ,Ñ.ˆØ—N’NÑ$Ô$×)Ò)Ñ+Ô+ˆ	Ø�9Ô 	Ò)Ð)ØÐØˆrr)   r�   rŒ   ÚresultsÚavg_precÚiou_thresholdÚmax_detsc                 ón  ‡‡— ˆfd„t          | j                             ¦   «         ¦  «        D ¦   «         }ˆfd„t          | j        ¦  «        D ¦   «         }|rJ|d         }|�,| j                             |¦  «        }	||	dd…dd…||f         }nZ|dd…dd…dd…||f         }nF|d         }|�,| j                             |¦  «        }	||	dd…dd…||f         }n|dd…dd…||f         }t          ||dk             ¦  «        dk    rt          j        dg¦  «        nt          j	        ||dk             ¦  «        S )	a  Perform evaluation for single class and image.

        Args:
            results:
                Dictionary including precision, recall and scores for all combinations.
            avg_prec:
                Calculate average precision. Else calculate average recall.
            iou_threshold:
                IoU threshold. If set to ``None`` it all values are used. Else results are filtered.
            area_range:
                Bounding box area range key.
            max_dets:
                Maximum detections.

        c                 ó&   •— g | ]\  }}|‰k    ¯|‘ŒS r#   r#   )r%   r&   ÚkrÞ   s      €r'   r(   z3MeanAveragePrecision._summarize.<locals>.<listcomp>¤  s#   ø€ Ð^Ð^Ð^™4˜1˜aÈaÐS]ÊoÈo�QÈoÈoÈor)   c                 ó&   •— g | ]\  }}|‰k    ¯|‘ŒS r#   r#   )r%   r&   r$  r!  s      €r'   r(   z3MeanAveragePrecision._summarize.<locals>.<listcomp>¥  s#   ø€ Ð]Ð]Ð]™4˜1˜aÈqÐT\Ê}È}�QÈ}È}È}r)   Ú	precisionNÚrecallr  r   ç      ð¿)
r  r›   Úkeysr„   r‚   Úindexr0   r1   r3   Úmean)
rG   r  r  r   rÞ   r!  Ú	area_indsÚ	mdet_indsÚprecr  s
       ``    r'   Ú
_summarizezMeanAveragePrecision._summarize�  su  øø€ ð. _Ð^Ð^Ð^¥9¨TÔ-B×-GÒ-GÑ-IÔ-IÑ#JÔ#JÐ^Ñ^Ô^ˆ	Ø]Ð]Ð]Ð]¥9¨TÔ-JÑ#KÔ#KÐ]Ñ]Ô]ˆ	Øð 	8à˜;Ô'ˆDàÐ(Ø Ô/×5Ò5°mÑDÔD�	Ø˜I q q q¨!¨!¨!¨Y¸	ÐAÔB��à˜A˜A˜A˜q˜q˜q ! ! ! Y°	Ð9Ô:��ð ˜8Ô$ˆDØÐ(Ø Ô/×5Ò5°mÑDÔD�	Ø˜I q q q¨!¨!¨!¨Y¸	ÐAÔB��à˜A˜A˜A˜q˜q˜q )¨YÐ6Ô7�å'*¨4°°r²	¬?Ñ';Ô';¸qÒ'@Ð'@�uŒ|˜T˜FÑ#Ô#Ð#ÅeÄjÐQUÐVZÐ]_ÒV_ÔQ`ÑFaÔFaÐar)   Ú	class_idsc                 ót  ‡ ‡‡‡‡‡— t          t          ‰ j        ¦  «        ¦  «        Š‰ j        d         Š‰ j                             ¦   «         Šˆˆˆ fd„‰D ¦   «         Šˆˆˆˆˆ fd„‰D ¦   «         }t          ‰ j        ¦  «        }t          ‰ j        ¦  «        }t          ‰¦  «        }t          ‰ j        ¦  «        }t          ‰ j        ¦  «        }t          ‰¦  «        }t          j	        |||||f¦  «         }	t          j	        ||||f¦  «         }
t          j	        |||||f¦  «         }t          j
        ‰ j        ¦  «        }t          ‰¦  «        D ]b\  }}t          ‰ j        ¦  «        D ]H\  }}t          ‰ j        ¦  «        D ].\  }}t                               |
|	|||||||||¬¦  «        \  }
}	}Œ/ŒIŒc|	|
fS )zªCalculate the precision and recall for all supplied classes to calculate mAP/mAR.

        Args:
            class_ids:
                List of label class Ids.

        r  c           	      óN   •— i | ]!}‰D ]}||f‰                      ||‰¦  «        “ŒŒ"S r#   )rÝ   )r%   rÈ   rÉ   r0  Úmax_detectionsrG   s      €€€r'   ú
<dictcomp>z3MeanAveragePrecision._calculate.<locals>.<dictcomp>Æ  sX   ø€ ð 
ð 
ð 
àØ%ð
ð 
ð ð �(ˆO˜T×.Ò.¨s°H¸nÑMÔMð
ð 
ð 
ð 
r)   c                 óV   •— g | ]%}‰D ] }‰D ]}‰                      |||‰‰¦  «        ‘ŒŒ!Œ&S r#   )r  )	r%   rÉ   r4   Úimg_idÚarea_rangesÚimg_idsr   r3  rG   s	       €€€€€r'   r(   z3MeanAveragePrecision._calculate.<locals>.<listcomp>Ì  sm   ø€ ð 
ð 
ð 
àØ#ð
ð 
ð Ø!ð	
ð 
ð ð × Ò  ¨°4¸ÈÑNÔNð
ð 
ð 
ð 
ð 
r)   )Úidx_clsÚidx_bbox_areaÚidx_max_det_thresholdsÚ	eval_imgsrƒ   rÊ   Únum_imgsÚnum_bbox_areas)Úranger0   r~   r„   r›   Úvaluesr‚   rƒ   r1   Úonesr3   r  r   Ú8_MeanAveragePrecision__calculate_recall_precision_scores)rG   r0  r<  rß   Únum_rec_thrsÚnum_classesr>  Únum_max_det_thresholdsr=  r&  r'  r¨   Úrec_thresholds_tensorr9  ro   r:  r;  rÊ   r7  r8  r   r3  s   ``                @@@@r'   Ú
_calculatezMeanAveragePrecision._calculateº  s/  øøøøøø€ õ �˜DÔ-Ñ.Ô.Ñ/Ô/ˆØÔ6°rÔ:ˆØÔ+×2Ò2Ñ4Ô4ˆð
ð 
ð 
ð 
ð 
ð 
àð
ñ 
ô 
ˆð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
à%ð
ñ 
ô 
ˆ	õ ˜4Ô.Ñ/Ô/ˆÝ˜4Ô.Ñ/Ô/ˆÝ˜)‘n”nˆÝ˜TÔ2Ñ3Ô3ˆÝ!$ TÔ%BÑ!CÔ!CÐÝ�w‘<”<ˆÝ”Z ¨|¸[È.ÐZpÐ qÑrÔrÐrˆ	Ý”*˜l¨K¸ÐI_Ð`ÑaÔaÐaˆÝ”*˜l¨L¸+À~ÐWmÐnÑoÔoÐoˆõ !&¤¨TÔ-@Ñ AÔ AÐõ $ IÑ.Ô.ð 	ð 	‰JˆG�QÝ$-¨dÔ.CÑ$DÔ$Dð ð Ñ �˜qÝ7@ÀÔA^Ñ7_Ô7_ð ð Ñ3Ð*¨GÝ0D×0hÒ0hØØ!ØØ 'Ø&3Ø/EØ"+Ø'<Ø 'Ø!)Ø'5ð 1iñ 1ô 1Ñ-�F˜I v vððð  ˜&Ð Ð r)   Ú
precisionsÚrecallsc                 ó`  — ||dœ}t          ¦   «         }| j        d         }|                      |d|¬¦  «        |_        d| j        v r|                      |dd|¬¦  «        |_        nt          j        dg¦  «        |_        d| j        v r|                      |dd|¬¦  «        |_        nt          j        dg¦  «        |_        |                      |dd|¬	¦  «        |_	        |                      |dd
|¬	¦  «        |_
        |                      |dd|¬	¦  «        |_        t          ¦   «         }| j        D ] }|                      |d|¬¦  «        |d|› �<   Œ!|                      |dd|¬	¦  «        |_        |                      |dd
|¬	¦  «        |_        |                      |dd|¬	¦  «        |_        ||fS )z÷Summarizes the precision and recall values to calculate mAP/mAR.

        Args:
            precisions:
                Precision values for different thresholds
            recalls:
                Recall values for different thresholds

        )r&  r'  r  T)r!  rŠ   )r   r!  g      è?rŽ   )rÞ   r!  r�   r�   FÚmar_)rT   r„   r/  rV   r‚   rW   r1   r3   rX   r[   rZ   rY   r_   re   rd   rc   )rG   rH  rI  r  Úmap_metricsÚlast_max_det_thresholdÚmar_metricsrÊ   s           r'   Ú_summarize_resultsz'MeanAveragePrecision._summarize_resultsô  sÉ  € ð !+°gÐ>Ð>ˆÝ&Ñ(Ô(ˆØ!%Ô!>¸rÔ!BÐØŸ/š/¨'°4ÐBX˜/ÑYÔYˆŒØ�$Ô%Ð%Ð%Ø!%§¢°¸$ÈcÐ\r Ñ!sÔ!sˆKÔÐå!&¤¨r¨dÑ!3Ô!3ˆKÔØ�4Ô&Ð&Ð&Ø!%§¢°¸$ÈdÐ]s Ñ!tÔ!tˆKÔÐå!&¤¨r¨dÑ!3Ô!3ˆKÔØ $§¢°¸È'Ð\r Ñ sÔ sˆÔØ!%§¢°¸$È8Ð^t Ñ!uÔ!uˆÔØ $§¢°¸È'Ð\r Ñ sÔ sˆÔå&Ñ(Ô(ˆØÔ4ð 	^ð 	^ˆGØ,0¯OªO¸GÀUÐU\¨OÑ,]Ô,]ˆKÐ(˜wÐ(Ð(Ñ)Ð)Ø $§¢°¸È7Ð]s Ñ tÔ tˆÔØ!%§¢°¸%ÈHÐ_u Ñ!vÔ!vˆÔØ $§¢°¸È7Ð]s Ñ tÔ tˆÔà˜KÐ'Ð'r)   r'  r&  r¨   r9  r:  r;  r<  r=  r>  c           	      óØ  ‡‡‡$‡%— t          |¦  «        }||
z  |	z  Š%||	z  Š$ˆˆ$ˆ%fd„t          |	¦  «        D ¦   «         }d„ |D ¦   «         }|s| ||fS t          j        ˆfd„|D ¦   «         ¦  «        }|j        r|j        t          j        u rt          j        n|j        }t          j        | 	                    |¦  «        d¬¦  «        }||         }t          j        ˆfd„|D ¦   «         d¬¦  «        d d …|f         }t          j        ˆfd	„|D ¦   «         d¬¦  «        d d …|f         }t          j        d
„ |D ¦   «         ¦  «        }t          j
        |dk    ¦  «        }|dk    r| ||fS t          j        |t          j        |¦  «        ¦  «        }t          j        t          j        |¦  «        t          j        |¦  «        ¦  «        }t          |dt          j        ¬¦  «        }t          |dt          j        ¬¦  «        }t          t!          ||¦  «        ¦  «        D �]È\  }\  }}t          |¦  «        }||z  }|||z   t          j        t          j        ¦  «        j        z   z  }t          j        |f¦  «        }t          j        |f¦  «        } |r|d         nd| ||||f<   t          j        d|j        ¬¦  «        }!t          j        d|j        ¬¦  «        }"t          j        |"dk    ¦  «        s[t          j        t          j        |dd …         |d d…         z
  |!fd¦  «        d¬¦  «        }"||"z  }t          j        |"dk    ¦  «        ¯[t          j        || 	                    |j        ¦  «        d¬¦  «        }|                     ¦   «         |k    r|                     ¦   «         n|}#|d |#…         }||         |d |#…<   ||         | d |#…<   |||d d …|||f<   | ||d d …|||f<   �ŒÊ| ||fS )Nc                 ó,   •— g | ]}‰‰‰z   |z            ‘ŒS r#   r#   )r%   r&   r<  Úidx_bbox_area_pointerÚidx_cls_pointers     €€€r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>)  s+   ø€ ÐmÐmÐmÐXY˜Y Ð9NÑ'NÐQRÑ'RÔSÐmÐmÐmr)   c                 ó   — g | ]}|®|‘ŒS ©Nr#   ©r%   Úes     r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>*  s   € ÐKÐKÐK 1¸Q¸]˜Q¸]¸]¸]r)   c                 ó0   •— g | ]}|d          d‰…         ‘ŒS )rç   Nr#   ©r%   rW  rÊ   s     €r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>.  s&   ø€ ÐSÐSÐS¸A  *¤¨h¨w¨hÔ 7ÐSÐSÐSr)   TrÒ   c                 ó8   •— g | ]}|d          dd…d‰…f         ‘ŒS )rå   Nr#   rY  s     €r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>8  s.   ø€ Ð XÐ XÐ XÀ  ;¤°°°°8°G°8°Ô!<Ð XÐ XÐ Xr)   r    )Úaxisc                 ó8   •— g | ]}|d          dd…d‰…f         ‘ŒS )ré   Nr#   rY  s     €r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>9  s.   ø€ ÐVÐVÐV¸q  *¤¨a¨a¨a°°'°¨kÔ :ÐVÐVÐVr)   c                 ó   — g | ]
}|d          ‘ŒS )rè   r#   rV  s     r'   r(   zLMeanAveragePrecision.__calculate_recall_precision_scores.<locals>.<listcomp>:  s   € ÐHÐHÐH°˜q œ}ÐHÐHÐHr)   Fr   )Údimrã   r  )r    )rØ   )Úmin)Úright)r0   r?  r1   rÅ   Úis_cudarã   r�   rê   r×   r²   Úcount_nonzeror  Úlogical_notr   r*   r  ÚzipÚfinfoÚfloat64Úepsrë   rØ   rA  r�   ÚclampÚsearchsortedÚmaxr  )&r'  r&  r¨   r9  r:  r;  r<  rƒ   rÊ   r=  r>  rC  Úimg_eval_cls_bboxÚ
det_scoresrã   rÜ   Údet_scores_sortedr  rò   rð   ÚnpigÚtpsÚfpsÚtp_sumÚfp_sumrÈ   ÚtpÚfpÚtp_lenÚrcÚprr.  ÚscoreÚ	diff_zeroÚdiffÚnum_indsrR  rS  s&         ` `                           @@r'   Ú#__calculate_recall_precision_scoresz8MeanAveragePrecision.__calculate_recall_precision_scores  s7  øøøø€ õ ˜>Ñ*Ô*ˆØ! NÑ2°XÑ=ˆØ -°Ñ 8ÐàmÐmÐmÐmÐmÐmÕ]bÐckÑ]lÔ]lÐmÑmÔmÐØKÐKÐ(9ÐKÑKÔKÐØ ð 	-Ø˜9 fÐ,Ð,å”YÐSÐSÐSÐSÐARÐSÑSÔSÑTÔTˆ
ð
  *Ô1Ðj°jÔ6FÍ%Ì*Ð6TÐ6T•”�ÐZdÔZjˆåŒ}˜ZŸ]š]¨5Ñ1Ô1¸dÐCÑCÔCˆØ& tÔ,Ðå”iÐ XÐ XÐ XÐ XÐFWÐ XÑ XÔ XÐ_`ÐaÑaÔaÐbcÐbcÐbcÐeiÐbiÔjˆÝ”YÐVÐVÐVÐVÐDUÐVÑVÔVÐ]^Ð_Ñ_Ô_Ð`aÐ`aÐ`aÐcgÐ`gÔhˆ
Ý”IÐHÐHÐ6GÐHÑHÔHÑIÔIˆ	ÝÔ" 9°Ò#5Ñ6Ô6ˆØ�1Š9ˆ9Ø˜9 fÐ,Ð,ÝÔ ­UÔ->¸zÑ-JÔ-JÑKÔKˆÝÔ¥Ô 1°+Ñ >Ô >ÅÔ@QÐR\Ñ@]Ô@]Ñ^Ô^ˆå˜ !­5¬;Ð7Ñ7Ô7ˆÝ˜ !­5¬;Ð7Ñ7Ô7ˆÝ&¥s¨6°6Ñ':Ô':Ñ;Ô;ð 	Sñ 	S‰MˆC‘�"�bÝ˜‘W”WˆFØ�d‘ˆBØ�r˜B‘w¥¤­U¬]Ñ!;Ô!;Ô!?Ñ?Ñ@ˆBÝ”; ˜Ñ/Ô/ˆDÝ”K  Ñ0Ô0ˆEàTZÐJaÈ"ÈRÌ&È&Ð`aˆF�3˜ Ð0FÐFÑGõ œ D°´Ð;Ñ;Ô;ˆIÝ”:˜d¨2¬9Ð5Ñ5Ô5ˆDÝ”i ¨¢	Ñ*Ô*ð Ý”{¥5¤9¨r°!°"°"¬v¸¸3¸B¸3¼Ñ/?À)Ð-LÈaÑ#PÔ#PÐVWÐXÑXÔX�Ø�d‘
�õ ”i ¨¢	Ñ*Ô*ð õ Ô% b¨.×*;Ò*;¸B¼IÑ*FÔ*FÈeÐTÑTÔTˆDØ(,¯ª©
¬
°fÒ(<Ð(<�t—{’{‘}”}�}À,ˆHØ˜	˜˜	”?ˆDØ  œhˆD��(�‰OØ0°Ô6ˆE�)�8�)ÑØPTˆI�c˜1˜1˜1˜g }Ð6LÐLÑMØMRˆF�3˜˜˜˜7 MÐ3IÐIÑJÑJà�y &Ð(Ð(r)   c                 óÒ  — |                       ¦   «         }|                      |¦  «        \  }}|                      ||¦  «        \  }}t          j        dg¦  «        }t          j        dg¦  «        }| j        røg }g }	t          |¦  «        D ]¤\  }
}|dd…dd…|
f                              d¬¦  «        }|dd…|
f                              d¬¦  «        }|                      ||¦  «        \  }}|                     |j	        ¦  «         |	                     |d| j
        d         › �         ¦  «         Œ¥t          j        |t          j        ¬¦  «        }t          j        |	t          j        ¬¦  «        }t          ¦   «         }|                     |¦  «         |                     |¦  «         ||_        ||d| j
        d         › d	�<   t          j        |t          j        ¬¦  «        |_        |S )
zCompute metric.r(  Né   )r^  r    rK  r  )rã   Ú
_per_class)rÇ   rG  rO  r1   r3   r…   r  Ú	unsqueezerª   rV   r„   r*   rg   r¬   rh   ÚintrU   )rG   rU   rH  rI  Úmap_valÚmar_valÚmap_per_class_valuesÚmar_max_dets_per_class_valuesÚmap_per_class_listÚmar_max_dets_per_class_listÚ	class_idxro   Úcls_precisionsÚcls_recallsÚcls_mapÚcls_marÚmetricss                    r'   ÚcomputezMeanAveragePrecision.compute]  sì  € à×#Ò#Ñ%Ô%ˆØ"Ÿošo¨gÑ6Ô6Ñˆ
�GØ×2Ò2°:¸wÑGÔGÑˆ�õ (-¤|°T°FÑ';Ô';ÐÝ05´¸d¸VÑ0DÔ0DÐ%ØÔð 	iØ!#ÐØ*,Ð'å )¨'Ñ 2Ô 2ð hð h‘�	˜1Ø!+¨A¨A¨A¨q¨q¨q°)¨OÔ!<×!FÒ!FÈ1Ð!FÑ!MÔ!M�Ø% a a a¨ lÔ3×=Ò=À!Ð=ÑDÔD�Ø#'×#:Ò#:¸>È;Ñ#WÔ#WÑ �˜Ø"×)Ò)¨'¬+Ñ6Ô6Ð6Ø+×2Ò2°7Ð;eÀ$ÔB_Ð`bÔBcÐ;eÐ;eÔ3fÑgÔgÐgÐgå#(¤<Ð0BÍ%Ì+Ð#VÑ#VÔ#VÐ Ý,1¬LÐ9TÕ\aÔ\gÐ,hÑ,hÔ,hÐ)å#Ñ%Ô%ˆØ�Š�wÑÔÐØ�Š�wÑÔÐØ 4ˆÔØHeˆÐD�tÔ4°RÔ8ÐDÐDÐDÑEÝœ, wµe´iÐ@Ñ@Ô@ˆŒØˆr)   Úfnc                 ó¨   •— | j         dk    r$t          ¦   «                              |d¬¦  «        }n!t          ¦   «                              |¦  «        }|S )z¾Custom apply function.

        Excludes the detections and groundtruths from the casting when the iou_type is set to `segm` as the state is
        no longer a tensor but a tuple.

        r   )r{   r~   )Úexclude_state)r   r“   Ú_apply)rG   r�  Úthisr¢   s      €r'   r’  zMeanAveragePrecision._apply|  sH   ø€ ð Œ=˜FÒ"Ð"Ý‘7”7—>’> "Ð4R�>ÑSÔSˆDˆDå‘7”7—>’> "Ñ%Ô%ˆDØˆr)   Údist_sync_fnÚprocess_groupc                 óè   •— t          ¦   «                              ||¬¦  «         | j        dk    rB|                      | j        |¦  «        | _        |                      | j        |¦  «        | _        dS dS )zèCustom sync function.

        For the iou_type `segm` the detections and groundtruths are no longer tensors but tuples. Therefore, we need
        to gather the list of tuples and then convert it back to a list of tuples.

        )r”  r•  r   N)r“   Ú
_sync_distr   Ú_gather_tuple_listr{   r~   )rG   r”  r•  r¢   s      €r'   r—  zMeanAveragePrecision._sync_dist‰  sq   ø€ õ 	‰Œ×Ò¨ÀMÐÑRÔRÐRàŒ=˜FÒ"Ð"Ø"×5Ò5°d´oÀ}ÑUÔUˆDŒOØ $× 7Ò 7¸Ô8IÈ=Ñ YÔ YˆDÔÐÐð #Ð"r)   Úlist_to_gatherc                 ó  ‡‡— t          j        |¬¦  «        Št          j        |¬¦  «         d„ t          ‰¦  «        D ¦   «         Št          j        ‰| |¬¦  «         ˆˆfd„t          t          ‰d         ¦  «        ¦  «        D ¦   «         S )z.Gather a list of tuples over multiple devices.)Úgroupc                 ó   — g | ]}d ‘ŒS rU  r#   rn   s     r'   r(   z;MeanAveragePrecision._gather_tuple_list.<locals>.<listcomp>ž  s   € Ð9Ð9Ð9 !˜Ð9Ð9Ð9r)   c                 óP   •— g | ]"}t          ‰¦  «        D ]}‰|         |         ‘ŒŒ#S r#   )r?  )r%   rÈ   ÚrankÚlist_gatheredÚ
world_sizes      €€r'   r(   z;MeanAveragePrecision._gather_tuple_list.<locals>.<listcomp>¡  s;   ø€ ÐoÐoÐo¨SÕ]bÐcmÑ]nÔ]nÐoÐoÐUY�˜dÔ# CÔ(ÐoÐoÐoÐor)   r   )ÚdistÚget_world_sizeÚbarrierr?  Úall_gather_objectr0   )r™  r•  rŸ  r   s     @@r'   r˜  z'MeanAveragePrecision._gather_tuple_list–  s‘   øø€ õ
 Ô(¨}Ð=Ñ=Ô=ˆ
ÝŒ˜=Ð)Ñ)Ô)Ð)à9Ð9¥u¨ZÑ'8Ô'8Ð9Ñ9Ô9ˆÝÔ˜}¨nÀMÐRÑRÔRÐRàoÐoÐoÐoÐoµE½#¸mÈAÔ>NÑ:OÔ:OÑ4PÔ4PÐoÑoÔoÐor)   ÚvalÚaxc                 ó.   — |                       ||¦  «        S )aÿ  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure object and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> from torch import tensor
            >>> from torchmetrics.detection.mean_ap import MeanAveragePrecision
            >>> preds = [dict(
            ...     boxes=tensor([[258.0, 41.0, 606.0, 285.0]]),
            ...     scores=tensor([0.536]),
            ...     labels=tensor([0]),
            ... )]
            >>> target = [dict(
            ...     boxes=tensor([[214.0, 41.0, 562.0, 285.0]]),
            ...     labels=tensor([0]),
            ... )]
            >>> metric = MeanAveragePrecision()
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.detection.mean_ap import MeanAveragePrecision
            >>> preds = lambda: [dict(
            ...     boxes=torch.tensor([[258.0, 41.0, 606.0, 285.0]]) + torch.randint(10, (1,4)),
            ...     scores=torch.tensor([0.536]) + 0.1*torch.rand(1),
            ...     labels=torch.tensor([0]),
            ... )]
            >>> target = [dict(
            ...     boxes=torch.tensor([[214.0, 41.0, 562.0, 285.0]]),
            ...     labels=torch.tensor([0]),
            ... )]
            >>> metric = MeanAveragePrecision()
            >>> vals = []
            >>> for _ in range(20):
            ...     vals.append(metric(preds(), target))
            >>> fig_, ax_ = metric.plot(vals)

        )Ú_plot)rG   r¥  r¦  s      r'   ÚplotzMeanAveragePrecision.plot£  s   € ðr �zŠz˜#˜rÑ"Ô"Ð"r)   )r€   r   NNNF)r   N)TNr�   rŒ   )NNrU  )5rN   rO   rP   rQ   rt   r�   Ú__annotations__ru   r   rv   rx   r*   rz   r   r   rR   r   Úlistr�  r   r”   r	  r¬   r·   r	   r±   r©   rÇ   rÝ   r  r  r  Ústaticmethodr  r/  rT   r_   rG  rO  rB  rŽ  r   r1   ÚnnÚModuler’  r—  r˜  r   r   r   r©  Ú__classcell__)r¢   s   @r'   r   r   •   sÁ  ø€ € € € € € ðWð Wðr $Ð�tÐ#Ð#Ñ#Ø'+Ð�h˜t”nÐ+Ð+Ñ+Ø"Ð�tÐ"Ð"Ñ"Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!à�V”ÐÐÑØ˜6”lÐ"Ð"Ñ"Ø˜6”lÐ"Ð"Ñ"Ø�v”,ÐÐÑØ˜VœÐ$Ð$Ñ$ð !Ø,2Ø04Ø04Ø8<Ø#ð3Nð 3Nàð3Nð ˜.Ô)ð3Nð !  e¤Ô-ð	3Nð
 !  e¤Ô-ð3Nð #+¨4°¬9Ô"5ð3Nð ð3Nð ð3Nð 
ð3Nð 3Nð 3Nð 3Nð 3Nð 3Nðj;˜D  c¨6 kÔ!2Ô3ð ;¸TÀ$ÀsÈFÀ{ÔBSÔ=Tð ;ÐY]ð ;ð ;ð ;ð ;ð /ð /ð /ð /ðF¨$¨s°C¨x¬.ð F¸UÀ6È5À=Ô=Qð Fð Fð Fð Fð"˜dð ð ð ð ð&C ð &C¨sð &C¸Sð &CÀVð &Cð &Cð &Cð &CðP
Øð
Ø)/ð
Ø=BÀ3ÈÀ8¼_ð
Ø\_ð
à	ˆc�3ˆhŒð
ð 
ð 
ð 
ð0%
àð%
ð ð%
ð ð	%
ð
 ð%
ð ˜#˜s˜(”Oð%
ð ð%
ð 
ˆc�3ˆhŒð%
ð %
ð %
ð %
ðNb
Øðb
Ø"%ðb
Ø38¸¸c¸´?ðb
ØMPðb
ØX\ðb
à	�$Œðb
ð b
ð b
ð b
ðH ðØðØ$*ðØ5:ðØGMðØU[ðØfiðà	ðð ð ñ „\ðð@ Ø)-ØØð+bð +bàð+bð ð+bð   ”ð	+bð
 ð+bð ð+bð 
ð+bð +bð +bð +bðZ8! Dð 8!¨UÐ3CÐEUÐ3UÔ-Vð 8!ð 8!ð 8!ð 8!ðt!(¨Vð !(¸fð !(ÈÐO_ÐaqÐOqÔIrð !(ð !(ð !(ð !(ðF ðC)ØðC)àðC)ð ðC)ð ð	C)ð
 ðC)ð !$ðC)ð ðC)ð ðC)ð ðC)ð ðC)ð ðC)ð 
ˆv�v˜vÐ%Ô	&ðC)ð C)ð C)ñ „\ðC)ðJ˜ð ð ð ð ð>˜ð  e¤h¤oð ð ð ð ð ð ðZð Z x°Ô'9ð ZÐQYÐZ]ÔQ^ð ZÐjnð Zð Zð Zð Zð Zð Zð àSWð
pð 
pØ˜U 5¨& =Ô1Ô2ð
pØCKÈCÄ=ð
pà	ˆcŒð
pð 
pð 
pñ „\ð
pð uyð9#ð 9#Ø˜E $ s¨F {Ô"3°X¸dÀ3ÈÀ;Ô>OÔ5PÐ"PÔQÔRð9#Ø_gÐhpÔ_qð9#à	ð9#ð 9#ð 9#ð 9#ð 9#ð 9#ð 9#ð 9#r)   )r   )0ÚloggingÚcollections.abcr   Útypingr   r   r   r   r   r	   r¿   rÁ   r1   Útorch.distributedÚdistributedr¡  r
   r   Útorchmetrics.detection.helpersr   r   Útorchmetrics.metricr   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   r   r   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__Ú	getLoggerrN   Úlogr«  r8   r>   r	  r@   rT   r_   rg   r±   Úndarrayr=   r   r#   r)   r'   ú<module>r¾     s  ðð €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @à Ð Ð Ð Ø €€€Ø  Ð  Ð  Ð  Ð  Ð  Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #à OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ &Ð &Ð &Ð &Ð &Ð &Ø /Ð /Ð /Ð /Ð /Ð /Ø pÐ pÐ pÐ pÐ pÐ pÐ pÐ pÐ pÐ pØ @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 5Ø3Ð4Ðàð MÐ%;ð MØ3Ð5KÐLÐà€gÔ˜Ñ!Ô!€ð=ð =˜˜cœð =¨g°nÔ.Eð =ÐSYð =ð =ð =ð =ð0 )/ð=ð =Ø	ˆcŒð=àˆSŒ	ð=ð �nÔ%ð=ð ð	=ð =ð =ð =ð:ð :ð :ð :ð :˜ñ :ô :ð :ð*_ð _ð _ð _ð _Ð(ñ _ô _ð _ðWð Wð Wð Wð WÐ(ñ Wô Wð Wðð ð ð ð Ð)ñ ô ð ð*^�4˜˜bœj¨"¬*Ð4Ô5Ô6ð ^¸DÀÀrÄzÐSUÔS]ÐG]ÔA^Ô<_ð ^Ðdjð ^ð ^ð ^ð ^ð*G#ð G#ð G#ð G#ð G#˜6ñ G#ô G#ð G#ð G#ð G#r)   