class_docstr: Computes the image-text retrieval metrics for a list of images and their captions
  using the distance between their embeddings.
  
  Expects predictions to contain two keys:
      image (Tensor): [batch, hidden_dim]
      text (Tensor): [batch * num_captions, hidden_dim]
  
  Computes the following metrics:
      image2text
          recall@1, recall@5, recall@10, mean_rank, median_rank
      text2image
          recall@1, recall@5, recall@10, mean_rank, median_rank
  
  NOTE: each image MUST have the same number of captions.
class_docstr_tok: ["Computes","the","image-text","retrieval","metrics","for","a","list","of","images","and","their","captions","using","the","distance","between","their","embeddings",".","Expects","predictions","to","contain","two","keys",":","image","(","Tensor",")",":","[","batch",",","hidden_dim","]","text","(","Tensor",")",":","[","batch","*","num_captions",",","hidden_dim","]","Computes","the","following","metrics",":","image2text","recall","@","1",",","recall","@","5",",","recall","@","10",",","mean_rank",",","median_rank","text2image","recall","@","1",",","recall","@","5",",","recall","@","10",",","mean_rank",",","median_rank","NOTE",":","each","image","MUST","have","the","same","number","of","captions","."]
code: def __init__(
      self,
      image: str = "image",
      text: str = "text",
      opts: Dict[str, Any] = None,
      is_distributed: bool = False,
  ) -> None:
      # Ignoring pred_key and target_key as we won't be using them
      # The issue is, both text and image are in the prediction, so pred_key and
      # target_key don't make sense here. We can still use pred_key to support nested
      # dicts, but it didn't seem required.
      super().__init__(opts, is_distributed)
      self._image_key = image
      self._text_key = text
  
      distance_metric = getattr(
          opts, "stats.metrics.img_text_retrieval.distance_metric"
      )
      self.measure = DISTANCE_REGISTRY[distance_metric]
  
imports: import argparse
  from numbers import Number
  from typing import Any, Dict, Tuple, Union
  import torch
  from torch import Tensor
  from metrics import METRICS_REGISTRY
  from metrics.metric_base import BaseMetric
  from metrics.retrieval_cmc import DISTANCE_REGISTRY
  from utils import logger
  from utils.tensor_utils import all_gather_list
label_desc: Use image node_id 1 to create a new ImageTextRetrievalMetric object from inherited base classes: BaseMetric with example: obj = ImageTextRetrievalMetric(image, text, opts, is_distributed)