code: def _metrics_by_output_name(
      metrics: Dict[str, Any]
  ) -> Dict[str, Dict[str, Any]]:
      """Returns metrics grouped by output name."""
      # If an output (head) name is used in an estimator, the metric names are of
      # the form "<metric_name>/<head>". This code checks for the existence of a '/'
      # where the trailing suffix is shared by at least three metrics. This
      # seemingly random choice of three was choose to avoid standard cases such as
      # 'label/mean' and 'prediction/mean' that are used by estimators but are not
      # indicative of a multi-headed model.
      result = {}
      for name, value in metrics.items():
          index = name.rfind("/")
          if index == -1:
              return {"": metrics}
          output_name = name[index + 1 :]
          if output_name not in result:
              result[output_name] = {}
          result[output_name][name[:index]] = value
      for output_name, values in result.items():
          if len(values) <= 2:
              return {"": metrics}
      return result
  
imports: from typing import Any, Dict, Iterable, List, Optional
  import apache_beam
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_metrics_graph import eval_metrics_graph
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_model_analysis.utils import size_estimator
label_desc: Use image node_id 3 for calling a global function with example usage: _metrics_by_output_name(metrics) and returns: result, dict, dict