code: def process(
      self, data_batch: Any, data_samples: Sequence[dict]
  ) -> None:
      for data_sample in data_samples:
          result = {}
  
          filename = data_sample["img_path"]
          filename = filename.replace(self.img_prefix, "")
          if filename.startswith("/"):
              filename = filename[1:]
          result["filename"] = filename
  
          height = data_sample["ori_shape"][0]
          width = data_sample["ori_shape"][1]
          result["height"] = height
          result["width"] = width
  
          pred_instances = data_sample["pred_instances"]
  
          bboxes = pred_instances["bboxes"].cpu()
          scores = pred_instances["scores"].cpu()
          labels = pred_instances["labels"].cpu()
  
          bboxes = bboxes[scores > self.score_thr]
          labels = labels[scores > self.score_thr]
          scores = scores[scores > self.score_thr]
  
          if "tokens_positive" in data_sample:
              task = "vg"
          else:
              task = "od"
  
          if task == "od":
              classes_name = data_sample["text"]
              result["detection"] = {}
  
              if len(bboxes) > 0:
                  det_bboxes, keep = batched_nms(
                      bboxes,
                      scores,
                      labels,
                      dict(type="nms", iou_threshold=self.nms_thr),
                  )
                  _scores = det_bboxes[:, -1]
                  _bboxes = det_bboxes[:, :-1]
                  _labels = labels[keep]
  
                  instances = []
                  _bboxes = _bboxes.numpy().tolist()
                  _scores = _scores.numpy().tolist()
                  _labels = _labels.numpy().tolist()
                  for bbox, score, label in zip(
                      _bboxes, _scores, _labels
                  ):
                      round_bbox = [round(b, 2) for b in bbox]
                      round_score = round(score, 2)
                      instances.append(
                          {
                              "bbox": round_bbox,
                              "score": round_score,
                              "label": label,
                              "category": classes_name[label],
                          }
                      )
                  result["detection"]["instances"] = instances
              else:
                  result["detection"]["instances"] = []
              self.results.append(result)
          else:
              caption = data_sample["text"]
              result["grounding"] = {}
              result["grounding"]["caption"] = caption
  
              tokens_positive = data_sample["tokens_positive"]
  
              region_list = []
              for label, positive in enumerate(tokens_positive):
                  phrase = [
                      caption[pos[0] : pos[1]] for pos in positive
                  ]
  
                  _bboxes = bboxes[labels == label]
                  _scores = scores[labels == label]
                  det_bboxes, _ = batched_nms(
                      _bboxes,
                      _scores,
                      None,
                      dict(type="nms", iou_threshold=self.nms_thr),
                      class_agnostic=True,
                  )
                  _scores = det_bboxes[:, -1].numpy().tolist()
                  _bboxes = det_bboxes[:, :-1].numpy().tolist()
  
                  round_bboxes = []
                  for bbox in _bboxes:
                      round_bboxes.append([round(b, 2) for b in bbox])
                  _scores = [[round(s, 2) for s in _scores]]
                  region = {
                      "phrase": phrase,
                      "bbox": round_bboxes,
                      "score": _scores,
                      "tokens_positive": positive,
                  }
                  region_list.append(region)
              result["grounding"]["regions"] = region_list
              self.results.append(result)
  
file_path: mmdetection/mmdet/evaluation/metrics/dump_odvg_results.py
imports: from typing import Any, Optional, Sequence
  from mmcv.ops import batched_nms
  from mmengine.evaluator import BaseMetric
  from mmengine.logging import print_log
  from mmdet.registry import METRICS
label_desc: Use image node_id 2 for calling the DumpODVGResults obj's underlying member method code with example usage: obj.process(data_batch, data_samples) without return types