class_docstr: COCO panoptic segmentation evaluation metric.
  
  Evaluate PQ, SQ RQ for panoptic segmentation tasks. Please refer to
  https://cocodataset.org/#panoptic-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.
      seg_prefix (str, optional): Path to the directory which contains the
          coco panoptic segmentation mask. It should be specified when
          evaluate. Defaults to None.
      classwise (bool): Whether to evaluate the metric class-wise.
          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.
          It should be specified when format_only is True. 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.
      nproc (int): Number of processes for panoptic quality computing.
          Defaults to 32. When ``nproc`` exceeds the number of cpu cores,
          the number of cpu cores is used.
      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.
class_docstr_tok: ["COCO","panoptic","segmentation","evaluation","metric",".","Evaluate","PQ",",","SQ","RQ","for","panoptic","segmentation","tasks",".","Please","refer","to","https",":","\/\/cocodataset.org\/","#","panoptic-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",".","seg_prefix","(","str",",","optional",")",":","Path","to","the","directory","which","contains","the","coco","panoptic","segmentation","mask",".","It","should","be","specified","when","evaluate",".","Defaults","to","None",".","classwise","(","bool",")",":","Whether","to","evaluate","the","metric","class-wise",".","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",".","It","should","be","specified","when","format_only","is","True",".","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",".","nproc","(","int",")",":","Number","of","processes","for","panoptic","quality","computing",".","Defaults","to","32",".","When","``","nproc","``","exceeds","the","number","of","cpu","cores",",","the","number","of","cpu","cores","is","used",".","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","."]
docstr: Convert ground truth to coco panoptic segmentation format json file.
  
  Args:
      gt_dicts (Sequence[dict]): Ground truth of the dataset.
      outfile_prefix (str): The filename prefix of the json file. If the
          prefix is "somepath/xxx", the json file will be named
          "somepath/xxx.gt.json".
  
  Returns:
      Tuple[str, str]: The filename of the json file and the name of the                directory which contains panoptic segmentation masks.
docstr_tok: ["Convert","ground","truth","to","coco","panoptic","segmentation","format","json","file",".","Args",":","gt_dicts","(","Sequence","[","dict","]",")",":","Ground","truth","of","the","dataset",".","outfile_prefix","(","str",")",":","The","filename","prefix","of","the","json","file",".","If","the","prefix","is","``","somepath\/xxx","''",",","the","json","file","will","be","named","``","somepath\/xxx.gt.json","''",".","Returns",":","Tuple","[","str",",","str","]",":","The","filename","of","the","json","file","and","the","name","of","the","directory","which","contains","panoptic","segmentation","masks","."]
code: def gt_to_coco_json(
      self, gt_dicts: Sequence[dict], outfile_prefix: str
  ) -> Tuple[str, str]:
      """Convert ground truth to coco panoptic segmentation format json file.
  
          Args:
              gt_dicts (Sequence[dict]): Ground truth of the dataset.
              outfile_prefix (str): The filename prefix of the json file. If the
                  prefix is "somepath/xxx", the json file will be named
                  "somepath/xxx.gt.json".
  
          Returns:
              Tuple[str, str]: The filename of the json file and the name of the\
                  directory which contains panoptic segmentation masks.
          """
      assert len(gt_dicts) > 0, "gt_dicts is empty."
      gt_folder = osp.dirname(gt_dicts[0]["seg_map_path"])
      converted_json_path = f"{outfile_prefix}.gt.json"
  
      categories = []
      for id, name in enumerate(self.dataset_meta["classes"]):
          isthing = (
              1 if name in self.dataset_meta["thing_classes"] else 0
          )
          categories.append(
              {"id": id, "name": name, "isthing": isthing}
          )
  
      image_infos = []
      annotations = []
      for gt_dict in gt_dicts:
          img_id = gt_dict["image_id"]
          image_info = {
              "id": img_id,
              "width": gt_dict["width"],
              "height": gt_dict["height"],
              "file_name": osp.split(gt_dict["seg_map_path"])[-1],
          }
          image_infos.append(image_info)
  
          pan_png = mmcv.imread(gt_dict["seg_map_path"]).squeeze()
          pan_png = pan_png[:, :, ::-1]
          pan_png = rgb2id(pan_png)
          segments_info = []
          for segment_info in gt_dict["segments_info"]:
              id = segment_info["id"]
              label = segment_info["category"]
              mask = pan_png == id
              isthing = categories[label]["isthing"]
              if isthing:
                  iscrowd = 1 if not segment_info["is_thing"] else 0
              else:
                  iscrowd = 0
  
              new_segment_info = {
                  "id": id,
                  "category_id": label,
                  "isthing": isthing,
                  "iscrowd": iscrowd,
                  "area": mask.sum(),
              }
              segments_info.append(new_segment_info)
  
          segm_file = image_info["file_name"].replace(".jpg", ".png")
          annotation = dict(
              image_id=img_id,
              segments_info=segments_info,
              file_name=segm_file,
          )
          annotations.append(annotation)
          pan_png = id2rgb(pan_png)
  
      info = dict(
          date_created=str(datetime.datetime.now()),
          description="Coco json file converted by mmdet CocoPanopticMetric.",
      )
      coco_json = dict(
          info=info,
          images=image_infos,
          categories=categories,
          licenses=None,
      )
      if len(annotations) > 0:
          coco_json["annotations"] = annotations
      dump(coco_json, converted_json_path)
      return converted_json_path, gt_folder
  
imports: import datetime
  import itertools
  import os.path
  import tempfile
  from typing import Dict, Optional, Sequence, Tuple, Union
  import mmcv
  import numpy
  from mmengine.evaluator import BaseMetric
  from mmengine.fileio import dump, get_local_path, load
  from mmengine.logging import MMLogger, print_log
  from terminaltables import AsciiTable
  from mmdet.datasets.api_wrappers import COCOPanoptic
  from mmdet.registry import METRICS
  from ..functional import INSTANCE_OFFSET, pq_compute_multi_core, pq_compute_single_core
label_desc: Use image node_id 3 for calling the CocoPanopticMetric obj's underlying member method code with example usage: obj.gt_to_coco_json(gt_dicts, outfile_prefix) and returns: converted_json_path,  gt_folder