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 update(
      self,
      prediction: Union[Tensor, Dict],
      target: Union[Tensor, Dict],
      extras: Dict[str, Any],
      batch_size: int = 1,
  ) -> None:
      images = prediction[self._image_key]
      texts = prediction[self._text_key]
  
      if not isinstance(images, Tensor) or not isinstance(
          texts, Tensor
      ):
          logger.error(
              "ImageTextRetrievalMetric only works on Tensor, got {} and {}.".format(
                  type(images), type(texts)
              )
          )
          return
  
      if self.is_distributed:
          images = all_gather_list(images)
          texts = all_gather_list(texts)
      else:
          images = [images.detach()]
          texts = [texts.detach()]
  
      self._images.extend(images)
      self._texts.extend(texts)
  
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 4 for calling the ImageTextRetrievalMetric obj's underlying member method code with example usage: obj.update(prediction, target, extras, batch_size) without return types