class_docstr: COCO evaluation metric.
  
  Evaluate AR, AP, and mAP for detection tasks including proposal/box
  detection and instance segmentation. Please refer to
  https://cocodataset.org/#detection-eval for more details.
  
  Args:
      ann_file (str, optional): Path to the coco format annotation file.
          If not specified, ground truth annotations from the dataset will
          be converted to coco format. Defaults to None.
      metric (str | List[str]): Metrics to be evaluated. Valid metrics
          include 'bbox', 'segm', 'proposal', and 'proposal_fast'.
          Defaults to 'bbox'.
      classwise (bool): Whether to evaluate the metric class-wise.
          Defaults to False.
      proposal_nums (Sequence[int]): Numbers of proposals to be evaluated.
          Defaults to (100, 300, 1000).
      iou_thrs (float | List[float], optional): IoU threshold to compute AP
          and AR. If not specified, IoUs from 0.5 to 0.95 will be used.
          Defaults to None.
      metric_items (List[str], optional): Metric result names to be
          recorded in the evaluation result. Defaults to None.
      format_only (bool): Format the output results without perform
          evaluation. It is useful when you want to format the result
          to a specific format and submit it to the test server.
          Defaults to False.
      outfile_prefix (str, optional): The prefix of json files. It includes
          the file path and the prefix of filename, e.g., "a/b/prefix".
          If not specified, a temp file will be created. Defaults to None.
      file_client_args (dict, optional): Arguments to instantiate the
          corresponding backend in mmdet <= 3.0.0rc6. Defaults to None.
      backend_args (dict, optional): Arguments to instantiate the
          corresponding backend. Defaults to None.
      collect_device (str): Device name used for collecting results from
          different ranks during distributed training. Must be 'cpu' or
          'gpu'. Defaults to 'cpu'.
      prefix (str, optional): The prefix that will be added in the metric
          names to disambiguate homonymous metrics of different evaluators.
          If prefix is not provided in the argument, self.default_prefix
          will be used instead. Defaults to None.
      sort_categories (bool): Whether sort categories in annotations. Only
          used for `Objects365V1Dataset`. Defaults to False.
      use_mp_eval (bool): Whether to use mul-processing evaluation
docstr: Convert ground truth to coco format json file.
  
  Args:
      gt_dicts (Sequence[dict]): Ground truth of the dataset.
      outfile_prefix (str): The filename prefix of the json files. If the
          prefix is "somepath/xxx", the json file will be named
          "somepath/xxx.gt.json".
  Returns:
      str: The filename of the json file.
docstr_tok: ["Convert","ground","truth","to","coco","format","json","file",".","Args",":","gt_dicts","(","Sequence","[","dict","]",")",":","Ground","truth","of","the","dataset",".","outfile_prefix","(","str",")",":","The","filename","prefix","of","the","json","files",".","If","the","prefix","is","``","somepath\/xxx","''",",","the","json","file","will","be","named","``","somepath\/xxx.gt.json","''",".","Returns",":","str",":","The","filename","of","the","json","file","."]
code: def gt_to_coco_json(
      self, gt_dicts: Sequence[dict], outfile_prefix: str
  ) -> str:
      """Convert ground truth to coco format json file.
  
      Args:
          gt_dicts (Sequence[dict]): Ground truth of the dataset.
          outfile_prefix (str): The filename prefix of the json files. If the
              prefix is "somepath/xxx", the json file will be named
              "somepath/xxx.gt.json".
      Returns:
          str: The filename of the json file.
      """
      categories = [
          dict(id=id, name=name)
          for id, name in enumerate(self.dataset_meta["classes"])
      ]
      image_infos = []
      annotations = []
  
      for idx, gt_dict in enumerate(gt_dicts):
          img_id = gt_dict.get("img_id", idx)
          image_info = dict(
              id=img_id,
              width=gt_dict["width"],
              height=gt_dict["height"],
              file_name="",
          )
          image_infos.append(image_info)
          for ann in gt_dict["anns"]:
              label = ann["bbox_label"]
              bbox = ann["bbox"]
              coco_bbox = [
                  bbox[0],
                  bbox[1],
                  bbox[2] - bbox[0],
                  bbox[3] - bbox[1],
              ]
  
              annotation = dict(
                  id=len(annotations)
                  + 1,  # coco api requires id starts with 1
                  image_id=img_id,
                  bbox=coco_bbox,
                  iscrowd=ann.get("ignore_flag", 0),
                  category_id=int(label),
                  area=coco_bbox[2] * coco_bbox[3],
              )
              if ann.get("mask", None):
                  mask = ann["mask"]
                  # area = mask_util.area(mask)
                  if isinstance(mask, dict) and isinstance(
                      mask["counts"], bytes
                  ):
                      mask["counts"] = mask["counts"].decode()
                  annotation["segmentation"] = mask
                  # annotation['area'] = float(area)
              annotations.append(annotation)
  
      info = dict(
          date_created=str(datetime.datetime.now()),
          description="Coco json file converted by mmdet CocoMetric.",
      )
      coco_json = dict(
          info=info,
          images=image_infos,
          categories=categories,
          licenses=None,
      )
      if len(annotations) > 0:
          coco_json["annotations"] = annotations
      converted_json_path = f"{outfile_prefix}.gt.json"
      dump(coco_json, converted_json_path)
      return converted_json_path
  
imports: import datetime
  import itertools
  import os.path
  import tempfile
  from collections import OrderedDict
  from typing import Dict, List, Optional, Sequence, Union
  import numpy
  import torch
  from mmengine.evaluator import BaseMetric
  from mmengine.fileio import dump, get_local_path, load
  from mmengine.logging import MMLogger
  from terminaltables import AsciiTable
  from mmdet.datasets.api_wrappers import COCO, COCOeval, COCOevalMP
  from mmdet.registry import METRICS
  from mmdet.structures.mask import encode_mask_results
  from ..functional import eval_recalls
label_desc: Use image node_id 5 for calling the CocoMetric obj's underlying member method code with example usage: obj.gt_to_coco_json(gt_dicts, outfile_prefix) and returns: converted_json_path