code: def metric_instance(
      metric_config: config_pb2.MetricConfig,
      tfma_metric_classes: Optional[
          Dict[str, Type[metric_types.Metric]]
      ] = None,
  ) -> metric_types.Metric:
      """Creates instance of metric associated with config."""
      if tfma_metric_classes is None:
          tfma_metric_classes = metric_types.registered_metrics()
      if metric_config.class_name in tfma_metric_classes:
          return _deserialize_tfma_metric(
              metric_config, tfma_metric_classes
          )
      elif not metric_config.module:
          return _deserialize_tf_metric(
              metric_config, {}
          )  # pytype: disable=bad-return-type  # typed-keras
      else:
          cls = getattr(
              importlib.import_module(metric_config.module),
              metric_config.class_name,
          )
          if issubclass(cls, tf.keras.metrics.Metric):
              return _deserialize_tf_metric(
                  metric_config, {metric_config.class_name: cls}
              )  # pytype: disable=bad-return-type  # typed-keras
          elif issubclass(cls, tf.keras.losses.Loss):
              return _deserialize_tf_loss(
                  metric_config, {metric_config.class_name: cls}
              )  # pytype: disable=bad-return-type  # typed-keras
          elif issubclass(cls, metric_types.Metric):
              return _deserialize_tfma_metric(
                  metric_config, {metric_config.class_name: cls}
              )
          else:
              raise NotImplementedError(
                  "unknown metric type {}: metric={}".format(
                      cls, metric_config
                  )
              )
  
imports: import collections
  import importlib
  import json
  import re
  from typing import Any, Dict, FrozenSet, Iterable, Iterator, List, NamedTuple, Optional, Tuple, Type, Union
  import tensorflow
  from tensorflow_model_analysis.metrics import aggregation
  from tensorflow_model_analysis.metrics import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import calibration
  from tensorflow_model_analysis.metrics import calibration_plot
  from tensorflow_model_analysis.metrics import confusion_matrix_metrics
  from tensorflow_model_analysis.metrics import confusion_matrix_plot
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics import multi_class_confusion_matrix_plot
  from tensorflow_model_analysis.metrics import tf_metric_wrapper
  from tensorflow_model_analysis.metrics import weighted_example_count
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 9 for calling a global function with example usage: metric_instance(metric_config, tfma_metric_classes) and returns: _deserialize_tfma_metric, _deserialize_tf_metric, _deserialize_tf_metric, _deserialize_tf_loss, _deserialize_tfma_metric