docstr: This function gathers intersection and union metrics from different processes and converts to float.
docstr_tok: ["This","function","gathers","intersection","and","union","metrics","from","different","processes","and","converts","to","float","."]
code: def gather_metrics(
      self,
      prediction: Union[Tensor, Dict],
      target: Union[Tensor, Dict],
      extras: Dict[str, Any],
  ) -> Union[Tensor, Dict[str, Tensor]]:
      """
      This function gathers intersection and union metrics from different processes and converts to float.
      """
      if isinstance(prediction, Tensor) and isinstance(target, Tensor):
          inter, union = compute_miou_batch(
              prediction=prediction, target=target
          )
          return {"inter": inter, "union": union}
      # elif isinstance(prediction, Dict):
      #    logger.error("IOU metrics are not supported for a dictionary of predictions")
      # We will revisit it later, as per the use case.
  
      # inter_dict = {}
      # union_dict = {}
      # for k, v in prediction.items():
      #     inter, union = compute_miou_batch(prediction=v, target=target)
      #     inter = tensor_to_python_float(inter, is_distributed=is_distributed)
      #     union = tensor_to_python_float(union, is_distributed=is_distributed)
      #     inter_dict[k] = inter
      #     union_dict[k] = union
      # return inter_dict, union_dict
      else:
          logger.error("Metric monitor supports Tensor only for IoU")
  
file_path: ml-cvnets/metrics/intersection_over_union.py
imports: from numbers import Number
  from typing import Any, Dict, Optional, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from metrics import METRICS_REGISTRY
  from metrics.metric_base import AverageMetric
  from utils import logger
label_desc: Use image node_id 1 for calling the IOUMetric obj's underlying member method code with example usage: obj.gather_metrics(prediction, target, extras) and returns: dict