code: def mean_iou(
      results,
      gt_seg_maps,
      num_labels,
      ignore_index: bool,
      nan_to_num: Optional[int] = None,
      label_map: Optional[Dict[int, int]] = None,
      reduce_labels: bool = False,
  ):
      """Calculate Mean Intersection and Union (mIoU).
  
      Args:
          results (`ndarray`):
              List of prediction segmentation maps, each of shape (height, width).
          gt_seg_maps (`ndarray`):
              List of ground truth segmentation maps, each of shape (height, width).
          num_labels (`int`):
              Number of categories.
          ignore_index (`int`):
              Index that will be ignored during evaluation.
          nan_to_num (`int`, *optional*):
              If specified, NaN values will be replaced by the number defined by the user.
          label_map (`dict`, *optional*):
              Mapping old labels to new labels. The parameter will work only when label is str.
          reduce_labels (`bool`, *optional*, defaults to `False`):
              Whether or not to reduce all label values of segmentation maps by 1. Usually used for datasets where 0 is used for background,
              and background itself is not included in all classes of a dataset (e.g. ADE20k). The background label will be replaced by 255.
  
      Returns:
          `Dict[str, float | ndarray]` comprising various elements:
          - *mean_iou* (`float`):
              Mean Intersection-over-Union (IoU averaged over all categories).
          - *mean_accuracy* (`float`):
              Mean accuracy (averaged over all categories).
          - *overall_accuracy* (`float`):
              Overall accuracy on all images.
          - *per_category_accuracy* (`ndarray` of shape `(num_labels,)`):
              Per category accuracy.
          - *per_category_iou* (`ndarray` of shape `(num_labels,)`):
              Per category IoU.
      """
      (
          total_area_intersect,
          total_area_union,
          total_area_pred_label,
          total_area_label,
      ) = total_intersect_and_union(
          results,
          gt_seg_maps,
          num_labels,
          ignore_index,
          label_map,
          reduce_labels,
      )
  
      # compute metrics
      metrics = dict()
  
      all_acc = total_area_intersect.sum() / total_area_label.sum()
      iou = total_area_intersect / total_area_union
      acc = total_area_intersect / total_area_label
  
      metrics["mean_iou"] = np.nanmean(iou)
      metrics["mean_accuracy"] = np.nanmean(acc)
      metrics["overall_accuracy"] = all_acc
      metrics["per_category_iou"] = iou
      metrics["per_category_accuracy"] = acc
  
      if nan_to_num is not None:
          metrics = dict(
              {
                  metric: np.nan_to_num(metric_value, nan=nan_to_num)
                  for metric, metric_value in metrics.items()
              }
          )
  
      return metrics
  
file_path: evaluate/metrics/mean_iou/mean_iou.py
imports: from typing import Dict, Optional
  import datasets
  import numpy
  import evaluate
label_desc: Use image node_id 3 for calling a global function with example usage: mean_iou(results, gt_seg_maps, num_labels, ignore_index, nan_to_num, label_map, reduce_labels) and returns: metrics