class_docstr: Abstract class to calculate average precision and recall for various vision tasks.
  
  Parameters
  ----------
  max_dets: Union[List[int], Tuple[int]], default: [1, 10, 100]
      Maximum number of detections per class.
  area_range: tuple, default: (32**2, 96**2)
      Slices for small/medium/large buckets.
  return_option: str, default: 'ap'
      ap: ap only, ar: ar only, None: all (not ignite compliant).
  average: str, default: none
      The method for averaging over the classes. If none, returns the result per class.
  iou_range: Tuple[float, float, float], default: (0.5, 0.95, 10)
      The closed range of the iou values (min, max (including), number of points)
class_docstr_tok: ["Abstract","class","to","calculate","average","precision","and","recall","for","various","vision","tasks",".","Parameters","--","--","--","--","--","max_dets",":","Union","[","List","[","int","]",",","Tuple","[","int","]","]",",","default",":","[","1",",","10",",","100","]","Maximum","number","of","detections","per","class",".","area_range",":","tuple",",","default",":","(","32","*","*","2",",","96","*","*","2",")","Slices","for","small\/medium\/large","buckets",".","return_option",":","str",",","default",":","'ap'","ap",":","ap","only",",","ar",":","ar","only",",","None",":","all","(","not","ignite","compliant",")",".","average",":","str",",","default",":","none","The","method","for","averaging","over","the","classes",".","If","none",",","returns","the","result","per","class",".","iou_range",":","Tuple","[","float",",","float",",","float","]",",","default",":","(","0.5",",","0.95",",","10",")","The","closed","range","of","the","iou","values","(","min",",","max","(","including",")",",","number","of","points",")"]
docstr: Compute metric value.
docstr_tok: ["Compute","metric","value","."]
code: def compute(self):
      """Compute metric value."""
      # now reduce accumulations
      sorted_classes = [
          int(class_id) for class_id in sorted(self._evals.keys())
      ]
      max_class = max(sorted_classes)
      for class_id in sorted_classes:
          acc = self._evals[class_id]
          acc["scores"] = _dict_conc(acc["scores"])
          acc["matched"] = _dict_conc(acc["matched"])
          acc["NP"] = _dict_conc(acc["NP"])
      reses = {
          "precision": -np.ones(
              (
                  len(self.iou_thresholds),
                  len(self.area_ranges_names),
                  len(self.max_detections_per_class),
                  max_class + 1,
              )
          ),
          "recall": -np.ones(
              (
                  len(self.iou_thresholds),
                  len(self.area_ranges_names),
                  len(self.max_detections_per_class),
                  max_class + 1,
              )
          ),
      }
  
      classes_counts = -np.ones(
          (
              len(self.iou_thresholds),
              len(self.area_ranges_names),
              len(self.max_detections_per_class),
              max_class + 1,
          )
      )
  
      for iou_i, min_iou in enumerate(self.iou_thresholds):
          for dets_i, dets in enumerate(self.max_detections_per_class):
              for area_i, area_size in enumerate(
                  self.area_ranges_names
              ):
                  precision_list = np.empty(max_class + 1)
                  precision_list.fill(np.nan)
                  recall_list = np.empty(max_class + 1)
                  recall_list.fill(np.nan)
                  counts_list = np.empty(max_class + 1)
                  counts_list.fill(np.nan)
  
                  # run ap calculation per-class
                  for class_id in sorted_classes:
                      ev = self._evals[class_id]
                      class_counts = np.nansum(
                          np.array(ev["NP"][(area_size, dets, min_iou)])
                      )
                      precision, recall = self._compute_ap_recall(
                          np.array(
                              ev["scores"][(area_size, dets, min_iou)]
                          ),
                          np.array(
                              ev["matched"][(area_size, dets, min_iou)]
                          ),
                          class_counts,
                      )
                      precision_list[class_id] = precision
                      recall_list[class_id] = recall
                      counts_list[class_id] = (
                          np.nan if recall == -1 else class_counts
                      )
                  reses["precision"][
                      iou_i, area_i, dets_i
                  ] = precision_list
                  reses["recall"][iou_i, area_i, dets_i] = recall_list
                  classes_counts[iou_i, area_i, dets_i] = counts_list
  
      if self.average == "weighted":
          classes_counts = self.filter_res(
              classes_counts,
              area=self.area_ranges_names[0],
              max_dets=self.max_detections_per_class[0],
          )
          classes_counts = np.nanmean(classes_counts, axis=(0, 1, 2))
          classes_counts = classes_counts[~np.isnan(classes_counts)]
          class_weights = 1.0 / classes_counts
          class_weights = class_weights / np.sum(class_weights)
      else:
          class_weights = None
  
      if self.return_option == "ap":
          return self.get_classes_scores_at(
              reses["precision"],
              max_dets=self.max_detections_per_class[0],
              area=self.area_ranges_names[0],
              get_mean_val=self.get_mean_value,
              class_weights=class_weights,
          )
      elif self.return_option == "ar":
          return self.get_classes_scores_at(
              reses["recall"],
              max_dets=self.max_detections_per_class[0],
              area=self.area_ranges_names[0],
              get_mean_val=self.get_mean_value,
              class_weights=class_weights,
          )
      return [reses]
  
imports: import warnings
  from collections import defaultdict
  from typing import List, Optional, Tuple, Union
  import numpy
  from ignite.metrics import Metric
  from ignite.metrics.metric import reinit__is_reduced, sync_all_reduce
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.vision.metrics_utils.metric_mixin import MetricMixin, ObjectDetectionMetricMixin
label_desc: Use image node_id 4 for calling the AveragePrecisionRecall obj's underlying member method code with example usage: obj.compute() and returns: list, self, self