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 compute(self) -> Union[Number, Dict[str, Number]]:
      # image: [batch, hidden_dim]
      # text:  [batch, num_captions, hidden_dim] or [batch * num_captions, hidden_dim]
      images, texts = self.get_aggregates()
  
      # make sure text shape is: [batch * num_captions, hidden_dim]
      if texts.dim() == 3:
          # [batch, num_captions, hidden_dim] --> [batch * num_captions, hidden_dim]
          texts = texts.reshape(-1, texts.shape[-1])
  
      num_images = images.shape[0]
      num_texts = texts.shape[0]
      assert (
          num_texts % num_images == 0
      ), "Number of captions is not consistent"
      num_captions = num_texts // num_images
  
      with torch.no_grad():
          i2t_ranks = self._image2text(images, texts, num_captions)
          t2i_ranks = self._text2image(images, texts, num_captions)
  
      return {
          "text2image": self._rank_metrics(t2i_ranks),
          "image2text": self._rank_metrics(i2t_ranks),
      }
  
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 8 for calling the ImageTextRetrievalMetric obj's underlying member method code with example usage: obj.compute() and returns: dict