class_docstr: CityScapes metric for instance segmentation.
  
  Args:
      outfile_prefix (str): The prefix of txt and png files. The txt and
          png file will be save in a directory whose path is
          "outfile_prefix.results/".
      seg_prefix (str, optional): Path to the directory which contains the
          cityscapes instance segmentation masks. It's necessary when
          training and validation. It could be None when infer on test
          dataset. 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.
      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.
      dump_matches (bool): Whether dump matches.json file during evaluating.
          Defaults to False.
      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.
class_docstr_tok: ["CityScapes","metric","for","instance","segmentation",".","Args",":","outfile_prefix","(","str",")",":","The","prefix","of","txt","and","png","files",".","The","txt","and","png","file","will","be","save","in","a","directory","whose","path","is","``","outfile_prefix.results\/","''",".","seg_prefix","(","str",",","optional",")",":","Path","to","the","directory","which","contains","the","cityscapes","instance","segmentation","masks",".","It","'s","necessary","when","training","and","validation",".","It","could","be","None","when","infer","on","test","dataset",".","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",".","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",".","dump_matches","(","bool",")",":","Whether","dump","matches.json","file","during","evaluating",".","Defaults","to","False",".","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","."]
code: def __init__(
      self,
      outfile_prefix: str,
      seg_prefix: Optional[str] = None,
      format_only: bool = False,
      collect_device: str = "cpu",
      prefix: Optional[str] = None,
      dump_matches: bool = False,
      file_client_args: dict = None,
      backend_args: dict = None,
  ) -> None:
      if not HAS_CITYSCAPESAPI:
          raise RuntimeError(
              "Failed to import `cityscapesscripts`."
              "Please try to install official "
              "cityscapesscripts by "
              '"pip install cityscapesscripts"'
          )
      super().__init__(collect_device=collect_device, prefix=prefix)
  
      self.tmp_dir = None
      self.format_only = format_only
      if self.format_only:
          assert (
              outfile_prefix is not None
          ), "outfile_prefix must be not"
          "None when format_only is True, otherwise the result files will"
          "be saved to a temp directory which will be cleaned up at the end."
      else:
          assert (
              seg_prefix is not None
          ), "`seg_prefix` is necessary when "
          "computing the CityScapes metrics"
  
      if outfile_prefix is None:
          self.tmp_dir = tempfile.TemporaryDirectory()
          self.outfile_prefix = osp.join(self.tmp_dir.name, "results")
      else:
          # the directory to save predicted panoptic segmentation mask
          self.outfile_prefix = osp.join(outfile_prefix, "results")  # type: ignore # yapf: disable # noqa: E501
  
      dir_name = osp.expanduser(self.outfile_prefix)
  
      if osp.exists(dir_name) and is_main_process():
          logger: MMLogger = MMLogger.get_current_instance()
          logger.info("remove previous results.")
          shutil.rmtree(dir_name)
      os.makedirs(dir_name, exist_ok=True)
  
      self.backend_args = backend_args
      if file_client_args is not None:
          raise RuntimeError(
              "The `file_client_args` is deprecated, "
              "please use `backend_args` instead, please refer to"
              "https://github.com/open-mmlab/mmdetection/blob/main/configs/_base_/datasets/coco_detection.py"  # noqa: E501
          )
  
      self.seg_prefix = seg_prefix
      self.dump_matches = dump_matches
  
file_path: mmdetection/mmdet/evaluation/metrics/cityscapes_metric.py
imports: import os
  import os.path
  import shutil
  import tempfile
  from collections import OrderedDict
  from typing import Dict, Optional, Sequence
  import mmcv
  import numpy
  from mmengine.dist import is_main_process
  from mmengine.evaluator import BaseMetric
  from mmengine.logging import MMLogger
  from mmdet.registry import METRICS
label_desc: Use image node_id 1 to create a new CityScapesMetric object from inherited base classes: BaseMetric with example: obj = CityScapesMetric(outfile_prefix, seg_prefix, format_only, collect_device, prefix, dump_matches, file_client_args, backend_args)