code: def adapt_to_remove_metrics(
      exporter: tf_estimator.Exporter,
      metrics_to_remove: Union[List[str], Callable[[str], bool]],
  ) -> tf_estimator.Exporter:
      """Modifies the given exporter to remove metrics before export.
  
      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
      adapt_to_remove_metrics on your TFMA exporter.
  
      Args:
        exporter: Exporter to modify. Will be mutated in place.
        metrics_to_remove: Which metrics to remove. Either a list of names, or a
          callable that returns true for names that should be removed.
  
      Returns:
        The mutated exporter, which will be modified in place. We also return it
        so that this can be used in an expression.
      """
  
      old_export = exporter.export
  
      def wrapped_export(
          unused_self,
          estimator: tf_estimator.Estimator,
          export_path: str,
          checkpoint_path: Optional[str],
          eval_result: Optional[bytes],
          is_the_final_export: bool,
      ) -> bytes:
          with _remove_metrics(estimator, metrics_to_remove):
              return old_export(
                  estimator,
                  export_path,
                  checkpoint_path,
                  eval_result,
                  is_the_final_export,
              )
  
      exporter.export = types.MethodType(wrapped_export, exporter)
      return exporter
  
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 2 for calling a global function with example usage: adapt_to_remove_metrics(exporter, metrics_to_remove) and returns: exporter, old_export