code: def _prepare_metric_fns(metrics, output_names, loss_wrappers):
      """Converts `metrics` into a list of per-output list of metrics.
  
      Args:
        metrics: List of metrics to be evaluated during training and testing. Each
          metric can be specified using a string (e.g. `'accuracy'`) or a
          `tf.keras.metrics.Metric` object. For multi-output model, this can also be
          a dictionary like `{'output1': ['metric'], 'output2': ['metric2']}`.
          See the `metrics` argument in `tf.keras.Model.compile`.
        output_names: List of names of the model's output. If `metrics` is a
          dictionary, the names in this list will be taken as lookup keys.
        loss_wrappers: List of `_LossWrapper` objects corresponding to each output.
  
      Returns:
        A list of the same length as `output_names`, where each element is a list of
        callables representing the metrics to be evaluated on the corresponding
        output.
      """
      if metrics is None:
          return [[] for _ in output_names]
  
      if not isinstance(metrics, (list, collections.abc.Mapping)):
          raise TypeError(
              "`metrics` must be a list or a dict, got {}".format(
                  str(metrics)
              )
          )
  
      to_list = lambda x: x if isinstance(x, list) else [x]
  
      if isinstance(metrics, collections.abc.Mapping):
          # Converts `metrics` from a dictionary to a list of lists using the order
          # specified in `output_names`.
          metrics = [
              to_list(metrics.get(name, [])) for name in output_names
          ]
  
      if not any(isinstance(m, list) for m in metrics):
          # Replicates `metrics` to be a list of lists if it is a plain list of
          # metrics, so that all metrics can be applied to each output.
          metrics = [metrics] + [
              _clone_metrics(metrics) for _ in output_names[1:]
          ]
  
      # Here `metrics` is a list of lists, and each sub-list corresponds to metrics
      # to be applied on an output.
      if len(metrics) != len(output_names):
          raise ValueError(
              "The number of sub-lists in `metrics` should be the "
              "same as model output."
          )
  
      metric_fns = []
      for per_output_metrics, loss_wrapper in zip(
          metrics, loss_wrappers
      ):
          metric_fns.append(
              [
                  tf.keras.metrics.get(
                      loss_wrapper.resolve_metric(metric)
                  )
                  for metric in to_list(per_output_metrics)
              ]
          )
      return metric_fns
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import functools
  import types
  import attr
  import neural_structured_learning.configs
  from neural_structured_learning.lib import adversarial_neighbor
  import six
  import tensorflow
label_desc: Use image node_id 5 for calling a global function with example usage: _prepare_metric_fns(metrics, output_names, loss_wrappers) and returns: metric_fns, unknown