class_docstr: mIoU evaluation metric.
  
  Args:
      iou_metrics (list[str] | str): Metrics to be calculated, the options
          includes 'mIoU', 'mDice' and 'mFscore'.
      beta (int): Determines the weight of recall in the combined score.
          Default: 1.
      collect_device (str): Device name used for collecting results from
          different ranks during distributed training. Must be 'cpu' or
          'gpu'. Defaults to 'cpu'.
      output_dir (str): The directory for output prediction. Defaults to
          None.
      format_only (bool): Only format result for results commit without
          perform evaluation. It is useful when you want to save the result
          to a specific format and submit it to the test server.
          Defaults to False.
      backend_args (dict, optional): Arguments to instantiate the
          corresponding backend. Defaults to None.
      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: ["mIoU","evaluation","metric",".","Args",":","iou_metrics","(","list","[","str","]","|","str",")",":","Metrics","to","be","calculated",",","the","options","includes","'mIoU","'",",","'mDice","'","and","'mFscore","'",".","beta","(","int",")",":","Determines","the","weight","of","recall","in","the","combined","score",".","Default",":","1.","collect_device","(","str",")",":","Device","name","used","for","collecting","results","from","different","ranks","during","distributed","training",".","Must","be","'cpu","'","or","'gpu","'",".","Defaults","to","'cpu","'",".","output_dir","(","str",")",":","The","directory","for","output","prediction",".","Defaults","to","None",".","format_only","(","bool",")",":","Only","format","result","for","results","commit","without","perform","evaluation",".","It","is","useful","when","you","want","to","save","the","result","to","a","specific","format","and","submit","it","to","the","test","server",".","Defaults","to","False",".","backend_args","(","dict",",","optional",")",":","Arguments","to","instantiate","the","corresponding","backend",".","Defaults","to","None",".","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: Process one batch of data and data_samples.
  
  The processed results should be stored in ``self.results``, which will
  be used to compute the metrics when all batches have been processed.
  
  Args:
      data_batch (dict): A batch of data from the dataloader.
      data_samples (Sequence[dict]): A batch of outputs from the model.
docstr_tok: ["Process","one","batch","of","data","and","data_samples",".","The","processed","results","should","be","stored","in","``","self.results","``",",","which","will","be","used","to","compute","the","metrics","when","all","batches","have","been","processed",".","Args",":","data_batch","(","dict",")",":","A","batch","of","data","from","the","dataloader",".","data_samples","(","Sequence","[","dict","]",")",":","A","batch","of","outputs","from","the","model","."]
code: def process(
      self, data_batch: dict, data_samples: Sequence[dict]
  ) -> None:
      """Process one batch of data and data_samples.
  
      The processed results should be stored in ``self.results``, which will
      be used to compute the metrics when all batches have been processed.
  
      Args:
          data_batch (dict): A batch of data from the dataloader.
          data_samples (Sequence[dict]): A batch of outputs from the model.
      """
      num_classes = len(self.dataset_meta["classes"])
      for data_sample in data_samples:
          pred_label = data_sample["pred_sem_seg"]["sem_seg"].squeeze()
          # format_only always for test dataset without ground truth
          if not self.format_only:
              label = (
                  data_sample["gt_sem_seg"]["sem_seg"]
                  .squeeze()
                  .to(pred_label)
              )
              ignore_index = data_sample["pred_sem_seg"].get(
                  "ignore_index", 255
              )
              self.results.append(
                  self._compute_pred_stats(
                      pred_label, label, num_classes, ignore_index
                  )
              )
  
          # format_result
          if self.output_dir is not None:
              basename = osp.splitext(
                  osp.basename(data_sample["img_path"])
              )[0]
              png_filename = osp.abspath(
                  osp.join(self.output_dir, f"{basename}.png")
              )
              output_mask = pred_label.cpu().numpy()
              output = Image.fromarray(output_mask.astype(np.uint8))
              imwrite(
                  output, png_filename, backend_args=self.backend_args
              )
  
imports: import os.path
  from collections import OrderedDict
  from typing import Dict, Optional, Sequence, Union
  import numpy
  import torch
  from mmcv import imwrite
  from mmengine.dist import is_main_process
  from mmengine.evaluator import BaseMetric
  from mmengine.logging import MMLogger, print_log
  from mmengine.utils import mkdir_or_exist
  from PIL import Image
  from mmdet.registry import METRICS
label_desc: Use image node_id 2 for calling the SemSegMetric obj's underlying member method code with example usage: obj.process(data_batch, data_samples) without return types