code: def add_mean_callback(features_dict, predictions_dict, labels_dict):
      """Callback to add our custom post-export metrics."""
      del features_dict
  
      metric_ops = {}
  
      # Adding a tf.metrics metric.
      all_values = list(labels_dict.values()) + list(
          predictions_dict.values()
      )
      metric_ops["tf_metric_mean"] = tf.compat.v1.metrics.mean(
          all_values
      )
  
      # Defining and adding a py_func metric
      # Note that for py_func metrics, you must still store the metric state in
      # tf.Variables.
      total_label = tf.compat.v1.Variable(
          initial_value=0.0,
          dtype=tf.float64,
          trainable=False,
          collections=[
              tf.compat.v1.GraphKeys.METRIC_VARIABLES,
              tf.compat.v1.GraphKeys.LOCAL_VARIABLES,
          ],
          validate_shape=True,
          name="total_label",
      )
  
      def my_func(x):
          return np.sum(x, dtype=np.float64)
  
      value_op = tf.identity(total_label)
      update_op = tf.compat.v1.assign_add(
          total_label,
          tf.compat.v1.py_func(my_func, [all_values], tf.float64),
      )
  
      metric_ops["py_func_total_label"] = value_op, update_op
  
      return metric_ops
  
file_path: model-analysis/tensorflow_model_analysis/model_agnostic_eval/model_agnostic_evaluate_graph_test.py
imports: import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  from tensorflow_model_analysis.api import model_eval_lib
  from tensorflow_model_analysis.api import tfma_unit
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.evaluators import legacy_metrics_and_plots_evaluator
  from tensorflow_model_analysis.extractors import slice_key_extractor
  from tensorflow_model_analysis.model_agnostic_eval import model_agnostic_evaluate_graph
  from tensorflow_model_analysis.model_agnostic_eval import model_agnostic_extractor
  from tensorflow_model_analysis.model_agnostic_eval import model_agnostic_predict
  from tensorflow_model_analysis.slicer import slicer_lib
label_desc: Use image node_id 1 for calling a global function with example usage: add_mean_callback(features_dict, predictions_dict, labels_dict) and returns: metric_ops, np