code: def _remove_metrics(
      estimator: tf_estimator.Estimator,
      metrics_to_remove: Union[List[str], Callable[[str], bool]],
  ):
      """Modifies the Estimator to make its model_fn return less metrics in EVAL.
  
      Note that this only removes the metrics from the
      EstimatorSpec.eval_metric_ops. It does not remove them from the graph or
      undo any side-effects that they might have had (e.g. modifications to
      METRIC_VARIABLES collections).
  
      This is useful for when you use py_func, streaming metrics, or other metrics
      incompatible with TFMA in your trainer. To keep these metrics in your trainer
      (so they still show up in Tensorboard) and still use TFMA, you can call
      remove_metrics on your Estimator before calling export_eval_savedmodel.
  
      This is a context manager, so it can be used like:
        with _remove_metrics(estimator, ['streaming_auc']):
          tfma.export.export_eval_savedmodel(estimator, ...)
  
      Args:
        estimator: tf.estimator.Estimator to modify. Will be mutated in place.
        metrics_to_remove: List of names of metrics to remove.
  
      Yields:
        Nothing.
      """
      old_call_model_fn = (
          estimator._call_model_fn
      )  # pylint: disable=protected-access
  
      def wrapped_call_model_fn(
          unused_self, features, labels, mode, config
      ):
          result = old_call_model_fn(features, labels, mode, config)
          if mode == tf_estimator.ModeKeys.EVAL:
              filtered_eval_metric_ops = {}
              for k, v in result.eval_metric_ops.items():
                  if isinstance(metrics_to_remove, abc.Iterable):
                      if k in metrics_to_remove:
                          continue
                  elif callable(metrics_to_remove):
                      if metrics_to_remove(k):
                          continue
                  filtered_eval_metric_ops[k] = v
              result = result._replace(
                  eval_metric_ops=filtered_eval_metric_ops
              )
          return result
  
      estimator._call_model_fn = (
          types.MethodType(  # pylint: disable=protected-access
              wrapped_call_model_fn, estimator
          )
      )
  
      yield
  
      estimator._call_model_fn = old_call_model_fn
  
imports: from collections import abc
  import contextlib
  import os
  import types
  from typing import Callable, Dict, List, Optional, Union
  from tensorflow import estimator
  from tensorflow_model_analysis.eval_saved_model import export
  from tensorflow_model_analysis.utils import util
  from tensorflow.python.estimator import gc
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.platform import gfile
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 1 for calling a global function with example usage: _remove_metrics(estimator, metrics_to_remove) and returns: result