class_docstr: 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`_.
  
  .. note::
      ``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.
  
  .. note::
      This metric is following the mAP implementation of `pycocotools`_ a standard implementation for the mAP metric
      for object detection.
  
  .. note::
      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.)}
class_docstr_tok: ["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","`","_",".","..","note",":",":","``","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",".","..","note",":",":","This","metric","is","following","the","mAP","implementation","of","`","pycocotools","`","_","a","standard","implementation","for","the","mAP","metric","for","object","detection",".","..","note",":",":","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",".",")","}"]
docstr: 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.
docstr_tok: ["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","."]
code: def _summarize(
      self,
      results: Dict,
      avg_prec: bool = True,
      iou_threshold: Optional[float] = None,
      area_range: str = "all",
      max_dets: int = 100,
  ) -> Tensor:
      """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.
  
      """
      area_inds = [
          i
          for i, k in enumerate(self.bbox_area_ranges.keys())
          if k == area_range
      ]
      mdet_inds = [
          i
          for i, k in enumerate(self.max_detection_thresholds)
          if k == max_dets
      ]
      if avg_prec:
          # dimension of precision: [TxRxKxAxM]
          prec = results["precision"]
          # IoU
          if iou_threshold is not None:
              thr = self.iou_thresholds.index(iou_threshold)
              prec = prec[thr, :, :, area_inds, mdet_inds]
          else:
              prec = prec[:, :, :, area_inds, mdet_inds]
      else:
          # dimension of recall: [TxKxAxM]
          prec = results["recall"]
          if iou_threshold is not None:
              thr = self.iou_thresholds.index(iou_threshold)
              prec = prec[thr, :, :, area_inds, mdet_inds]
          else:
              prec = prec[:, :, area_inds, mdet_inds]
  
      return (
          torch.tensor([-1.0])
          if len(prec[prec > -1]) == 0
          else torch.mean(prec[prec > -1])
      )
  
imports: import logging
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.distributed
  from torch import IntTensor, Tensor
  from torchmetrics.detection.helpers import _fix_empty_tensors, _input_validator
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.data import _cumsum
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE, _PYCOCOTOOLS_AVAILABLE, _TORCHVISION_GREATER_EQUAL_0_8
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
label_desc: Use image node_id 11 for calling the MeanAveragePrecision obj's underlying member method code with example usage: obj._summarize(results, avg_prec, iou_threshold, area_range, max_dets) and returns: unknown