class_docstr: mAP and CMC evaluation metrics for the ReID task.
  
  Args:
      metric (str | list[str]): Metrics to be evaluated.
          Default value is `mAP`.
      metric_options: (dict, optional): Options for calculating metrics.
          Allowed keys are 'rank_list' and 'max_rank'. Defaults to None.
      collect_device (str): Device name used for collecting results from
          different ranks during distributed training. Must be 'cpu' or
          'gpu'. Defaults to 'cpu'.
      prefix (str, optional): The prefix that will be added in the metric
          names to disambiguate homonymous metrics of different evaluators.
          If prefix is not provided in the argument, self.default_prefix
          will be used instead. Default: None
docstr: Compute the metrics from processed results.
  
  Args:
      results (list): The processed results of each batch.
  
  Returns:
      dict: The computed metrics. The keys are the names of the metrics,
      and the values are corresponding results.
docstr_tok: ["Compute","the","metrics","from","processed","results",".","Args",":","results","(","list",")",":","The","processed","results","of","each","batch",".","Returns",":","dict",":","The","computed","metrics",".","The","keys","are","the","names","of","the","metrics",",","and","the","values","are","corresponding","results","."]
code: def compute_metrics(self, results: list) -> dict:
      """Compute the metrics from processed results.
  
      Args:
          results (list): The processed results of each batch.
  
      Returns:
          dict: The computed metrics. The keys are the names of the metrics,
          and the values are corresponding results.
      """
      # NOTICE: don't access `self.results` from the method.
      metrics = {}
  
      pids = torch.cat(
          [result["gt_label"] for result in results]
      ).numpy()
      features = torch.stack(
          [result["pred_feature"] for result in results]
      )
  
      n, c = features.size()
      mat = torch.pow(features, 2).sum(dim=1, keepdim=True).expand(n, n)
      distmat = mat + mat.t()
      distmat.addmm_(features, features.t(), beta=1, alpha=-2)
      distmat = distmat.numpy()
  
      indices = np.argsort(distmat, axis=1)
      matches = (pids[indices] == pids[:, np.newaxis]).astype(np.int32)
  
      all_cmc = []
      all_AP = []
      num_valid_q = 0.0
      for q_idx in range(n):
          # remove self
          raw_cmc = matches[q_idx][1:]
          if not np.any(raw_cmc):
              # this condition is true when query identity
              # does not appear in gallery
              continue
  
          cmc = raw_cmc.cumsum()
          cmc[cmc > 1] = 1
  
          all_cmc.append(cmc[: self.metric_options["max_rank"]])
          num_valid_q += 1.0
  
          # compute average precision
          num_rel = raw_cmc.sum()
          tmp_cmc = raw_cmc.cumsum()
          tmp_cmc = [x / (i + 1.0) for i, x in enumerate(tmp_cmc)]
          tmp_cmc = np.asarray(tmp_cmc) * raw_cmc
          AP = tmp_cmc.sum() / num_rel
          all_AP.append(AP)
  
      assert (
          num_valid_q > 0
      ), "Error: all query identities do not appear in gallery"
  
      all_cmc = np.asarray(all_cmc)
      all_cmc = all_cmc.sum(0) / num_valid_q
      mAP = np.mean(all_AP)
  
      if "mAP" in self.metrics:
          metrics["mAP"] = np.around(mAP, decimals=3)
      if "CMC" in self.metrics:
          for rank in self.metric_options["rank_list"]:
              metrics[f"R{rank}"] = np.around(
                  all_cmc[rank - 1], decimals=3
              )
  
      return metrics
  
file_path: mmdetection/mmdet/evaluation/metrics/reid_metric.py
imports: from typing import Optional, Sequence, Union
  import numpy
  import torch
  from mmengine.evaluator import BaseMetric
  from mmdet.registry import METRICS
label_desc: Use image node_id 3 for calling the ReIDMetrics obj's underlying member method code with example usage: obj.compute_metrics(results) and returns: metrics