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: Compute the metrics from processed results.
  
  Args:
      results (list): The processed results of each batch. There
          are two cases:
  
          - When ``outfile_prefix`` is not provided, the elements in
            results are pq_stats which can be summed directly to get PQ.
          - When ``outfile_prefix`` is provided, the elements in
            results are tuples like (gt, pred).
  
  Returns:
      Dict[str, float]: The computed metrics. The keys are the names of
          the metrics, and the values are corresponding results.
docstr_tok: ["Compute","the","metrics","from","processed","results",".","Args",":","results","(","list",")",":","The","processed","results","of","each","batch",".","There","are","two","cases",":","-","When","``","outfile_prefix","``","is","not","provided",",","the","elements","in","results","are","pq_stats","which","can","be","summed","directly","to","get","PQ",".","-","When","``","outfile_prefix","``","is","provided",",","the","elements","in","results","are","tuples","like","(","gt",",","pred",")",".","Returns",":","Dict","[","str",",","float","]",":","The","computed","metrics",".","The","keys","are","the","names","of","the","metrics",",","and","the","values","are","corresponding","results","."]
code: def compute_metrics(self, results: list) -> Dict[str, float]:
      """Compute the metrics from processed results.
  
      Args:
          results (list): The processed results of each batch. There
              are two cases:
  
              - When ``outfile_prefix`` is not provided, the elements in
                results are pq_stats which can be summed directly to get PQ.
              - When ``outfile_prefix`` is provided, the elements in
                results are tuples like (gt, pred).
  
      Returns:
          Dict[str, float]: The computed metrics. The keys are the names of
              the metrics, and the values are corresponding results.
      """
      logger: MMLogger = MMLogger.get_current_instance()
  
      if self.tmp_dir is None:
          # do evaluation after collect all the results
  
          # split gt and prediction list
          gts, preds = zip(*results)
  
          if self._coco_api is None:
              # use converted gt json file to initialize coco api
              logger.info("Converting ground truth to coco format...")
              coco_json_path, gt_folder = self.gt_to_coco_json(
                  gt_dicts=gts, outfile_prefix=self.outfile_prefix
              )
              self._coco_api = COCOPanoptic(coco_json_path)
          else:
              gt_folder = self.seg_prefix
  
          self.cat_ids = self._coco_api.get_cat_ids(
              cat_names=self.dataset_meta["classes"]
          )
          self.cat2label = {
              cat_id: i for i, cat_id in enumerate(self.cat_ids)
          }
          self.img_ids = self._coco_api.get_img_ids()
          self.categories = self._coco_api.cats
  
          # convert predictions to coco format and dump to json file
          json_filename, pred_folder = self.result2json(
              results=preds, outfile_prefix=self.outfile_prefix
          )
  
          if self.format_only:
              logger.info(
                  "results are saved in "
                  f"{osp.dirname(self.outfile_prefix)}"
              )
              return dict()
  
          imgs = self._coco_api.imgs
          gt_json = self._coco_api.img_ann_map
          gt_json = [
              {
                  "image_id": k,
                  "segments_info": v,
                  "file_name": imgs[k]["segm_file"],
              }
              for k, v in gt_json.items()
          ]
          pred_json = load(json_filename)
          pred_json = dict(
              (el["image_id"], el) for el in pred_json["annotations"]
          )
  
          # match the gt_anns and pred_anns in the same image
          matched_annotations_list = []
          for gt_ann in gt_json:
              img_id = gt_ann["image_id"]
              if img_id not in pred_json.keys():
                  raise Exception(
                      "no prediction for the image"
                      " with id: {}".format(img_id)
                  )
              matched_annotations_list.append(
                  (gt_ann, pred_json[img_id])
              )
  
          pq_stat = pq_compute_multi_core(
              matched_annotations_list,
              gt_folder,
              pred_folder,
              self.categories,
              backend_args=self.backend_args,
              nproc=self.nproc,
          )
  
      else:
          # aggregate the results generated in process
          if self._coco_api is None:
              categories = dict()
              for id, name in enumerate(self.dataset_meta["classes"]):
                  isthing = (
                      1
                      if name in self.dataset_meta["thing_classes"]
                      else 0
                  )
                  categories[id] = {
                      "id": id,
                      "name": name,
                      "isthing": isthing,
                  }
              self.categories = categories
  
          pq_stat = PQStat()
          for result in results:
              pq_stat += result
  
      metrics = [("All", None), ("Things", True), ("Stuff", False)]
      pq_results = {}
  
      for name, isthing in metrics:
          pq_results[name], classwise_results = pq_stat.pq_average(
              self.categories, isthing=isthing
          )
          if name == "All":
              pq_results["classwise"] = classwise_results
  
      classwise_results = None
      if self.classwise:
          classwise_results = {
              k: v
              for k, v in zip(
                  self.dataset_meta["classes"],
                  pq_results["classwise"].values(),
              )
          }
  
      print_panoptic_table(pq_results, classwise_results, logger=logger)
      results = parse_pq_results(pq_results)
  
      return results
  
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 9 for calling the CocoPanopticMetric obj's underlying member method code with example usage: obj.compute_metrics(results) and returns: results, dict