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: Calculate evaluation metrics.
  
  Args:
      results (list): The processed results of each batch.
  
  Returns:
      Dict[str, np.ndarray]: per category evaluation metrics,
          shape (num_classes, ).
docstr_tok: ["Calculate","evaluation","metrics",".","Args",":","results","(","list",")",":","The","processed","results","of","each","batch",".","Returns",":","Dict","[","str",",","np.ndarray","]",":","per","category","evaluation","metrics",",","shape","(","num_classes",",",")","."]
code: def get_return_metrics(self, results: list) -> dict:
      """Calculate evaluation metrics.
  
      Args:
          results (list): The processed results of each batch.
  
      Returns:
          Dict[str, np.ndarray]: per category evaluation metrics,
              shape (num_classes, ).
      """
  
      def f_score(precision, recall, beta=1):
          """calculate the f-score value.
  
          Args:
              precision (float | torch.Tensor): The precision value.
              recall (float | torch.Tensor): The recall value.
              beta (int): Determines the weight of recall in the combined
                  score. Default: 1.
  
          Returns:
              [torch.tensor]: The f-score value.
          """
          score = (
              (1 + beta**2)
              * (precision * recall)
              / ((beta**2 * precision) + recall)
          )
          return score
  
      total_area_intersect = sum([r["area_intersect"] for r in results])
      total_area_union = sum([r["area_union"] for r in results])
      total_area_pred_label = sum(
          [r["area_pred_label"] for r in results]
      )
      total_area_label = sum([r["area_label"] for r in results])
  
      all_acc = total_area_intersect / total_area_label
      ret_metrics = OrderedDict({"aAcc": all_acc})
      for metric in self.metrics:
          if metric == "mIoU":
              iou = total_area_intersect / total_area_union
              acc = total_area_intersect / total_area_label
              ret_metrics["IoU"] = iou
              ret_metrics["Acc"] = acc
          elif metric == "mDice":
              dice = (
                  2
                  * total_area_intersect
                  / (total_area_pred_label + total_area_label)
              )
              acc = total_area_intersect / total_area_label
              ret_metrics["Dice"] = dice
              ret_metrics["Acc"] = acc
          elif metric == "mFscore":
              precision = total_area_intersect / total_area_pred_label
              recall = total_area_intersect / total_area_label
              f_value = torch.tensor(
                  [
                      f_score(x[0], x[1], self.beta)
                      for x in zip(precision, recall)
                  ]
              )
              ret_metrics["Fscore"] = f_value
              ret_metrics["Precision"] = precision
              ret_metrics["Recall"] = recall
  
      ret_metrics = {
          metric: value.cpu().numpy()
          for metric, value in ret_metrics.items()
      }
  
      return ret_metrics
  
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 5 for calling the SemSegMetric obj's underlying member method code with example usage: obj.get_return_metrics(results) and returns: ret_metrics, score