code: def _compute_loss_and_metrics(
      losses, metrics, labels, outputs, sample_weights=None
  ):
      """Computes total loss and (loss value, loss name) pairs for metrics.
  
      Args:
        losses: List of `_LossWrapper` objects to be evaluated on corresponding
          outputs. Must have the same length as `labels` and `outputs`.
        metrics: List of list of (metric fn, metric name) pairs, for additional
          metrics to report for each output. Must have the same length as `outputs`.
          If set to `None`, no additional metrics will be reported.
        labels: List of `Tensor` objects of ground truth targets. Must have the same
          length as `losses` and `outputs`.
        outputs: List of `Tensor` objects of predicted targets. Must have the same
          length as `losses` and `labels`.
        sample_weights: (optional) `Tensor` of weight for the loss of each sample.
  
      Returns:
        total_loss: Weighted sum of losses on all outputs.
        metrics: List of (value, aggregation, name) tuples for metric reporting.
      """
      outputs = tf.nest.flatten(outputs)
      total_loss, output_metrics = [], []
      if metrics is None:
          metrics = [[]] * len(losses)
      for label, output, loss, per_output_metrics in zip(
          labels, outputs, losses, metrics
      ):
          loss_value = loss(label, output, sample_weights)
          total_loss.append(loss.weight * loss_value)
          output_metrics.append((loss_value, "mean", loss.name))
          for metric_fn, metric_name in per_output_metrics:
              value = metric_fn(label, output)
              # Metric objects always return an aggregated result, and shouldn't be
              # aggregated again.
              if isinstance(metric_fn, tf.keras.metrics.Metric):
                  aggregation = None
              else:
                  aggregation = "mean"
              output_metrics.append((value, aggregation, metric_name))
      return tf.add_n(total_loss), output_metrics
  
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 6 for calling a global function with example usage: _compute_loss_and_metrics(losses, metrics, labels, outputs, sample_weights) and returns: tf,  output_metrics