class_docstr: Compute CMC-top-k and mAP metrics in retrieval setup.
class_docstr_tok: ["Compute","CMC-top-k","and","mAP","metrics","in","retrieval","setup","."]
code: def __init__(
      self,
      opts: argparse.Namespace = None,
      is_distributed: bool = False,
      pred: str = "embedding",
      target: str = None,
      compute_map: bool = True,
  ) -> None:
      super().__init__(opts, is_distributed, pred, target)
      distance_metric = getattr(
          opts, "stats.metrics.retrieval_cmc.distance_metric"
      )
      self.k = getattr(opts, "stats.metrics.retrieval_cmc.k")
      self.subset_fraction = float(
          getattr(opts, "stats.metrics.retrieval_cmc.subset_fraction")
      )
  
      self.compute_map = compute_map
  
      self.get_distance_matrix = DISTANCE_REGISTRY[distance_metric]
      self.embedding = []
      self.label = []
      self.is_master = is_master(opts)
      if self.subset_fraction > 1.0:
          logger.error(
              "Subset fraction should be a positive number smaller than 1.0."
              f" Got {self.subset_fraction}"
          )
  
imports: import argparse
  import copy
  from typing import Dict, Tuple
  import numpy
  import torch
  from sklearn.metrics import average_precision_score
  from torch.nn import functional
  from metrics import METRICS_REGISTRY
  from metrics.metric_base import EpochMetric
  from utils import logger
  from utils.ddp_utils import is_master
  from utils.registry import Registry
label_desc: Use image node_id 1 to create a new RetrievalCMC object from inherited base classes: EpochMetric with example: obj = RetrievalCMC(opts, is_distributed, pred, target, compute_map)