code: def metric_op(metric):
      """Converts Keras metrics into a metric op tuple.
  
      NOTE: If this method is called in for loop, the runtime is O(n^2). However
      the number of eval metrics at any given time should be small enough that
      this does not affect performance. Any impact is only during graph construction
      time, and therefore has no effect on steps/s.
  
      Args:
        metric: Either a `tf.keras.metric.Metric` instance or a tuple of Tensor
          value and update op.
  
      Returns:
        A tuple of metric Tensor value and update op.
      """
  
      if not isinstance(metric, tf.keras.metrics.Metric):
          return metric
      vars_to_add = {}
      for var in metric.variables:
          vars_to_add[_hashable_var_key(var)] = var
      metric = (metric.result(), metric.updates[0])
      _update_variable_collection(
          v1.GraphKeys.LOCAL_VARIABLES, vars_to_add
      )
      _update_variable_collection(
          v1.GraphKeys.METRIC_VARIABLES, vars_to_add
      )
      return metric
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from distutils.version import LooseVersion
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow.python import tf2
  from tensorflow.python.keras.metrics import Metric
  from tensorflow.python.tpu import tpu_function
  from tensorflow_estimator.python.estimator.head import regression_head
label_desc: Use image node_id 5 for calling a global function with example usage: metric_op(metric) and returns: metric, metric