code: def get_prediction_from_annotation(
      annotations: Dict,
      annotation_idx: int,
      category_mapping: Dict[int, int],
  ) -> Tuple[int, torch.Tensor, torch.Tensor]:
      annotation = annotations["annotations"][annotation_idx]
      image_id = annotation["image_id"]
      image = [
          im for im in annotations["images"] if im["id"] == image_id
      ]
      assert len(image) == 1, f"Too many images with a single id."
      image = image[0]
      h, w = image["height"], image["width"]
      boxes = annotation["bbox"]
  
      # Boxes are in (x1, y1, w, h) format. Convert to (x1, y1, x2, y2) format.
      boxes[0] /= w
      boxes[1] /= h
      boxes[2] /= w
      boxes[3] /= h
  
      boxes[2] += boxes[0]
      boxes[3] += boxes[1]
  
      masks = annotation["segmentation"]
      rles = maskUtils.frPyObjects(masks, h, w)
      rle = maskUtils.merge(rles)
      binary_mask = maskUtils.decode(rle)
  
      label = category_mapping[annotation["category_id"]]
  
      return label, boxes, binary_mask
  
file_path: ml-cvnets/tests/metrics/test_coco_map.py
imports: import argparse
  import json
  import os
  from typing import Dict, List, Tuple
  import numpy
  import torch
  from pycocotools import mask
  from cvnets.models.detection import DetectionPredTuple
  from metrics import coco_map
  from metrics.stats import Statistics
label_desc: Use image node_id 2 for calling a global function with example usage: get_prediction_from_annotation(annotations, annotation_idx, category_mapping) and returns: label,  boxes,  binary_mask