code: def get_metric(identifier, y_true, y_pred):
      if identifier is None:
          return None  # Ok to have no metric for an output.
  
      # Convenience feature for selecting b/t binary, categorical,
      # and sparse categorical.
      if str(identifier).lower() not in ["accuracy", "acc"]:
          metric_obj = metrics_module.get(identifier)
      else:
          (
              is_binary,
              is_sparse_categorical,
          ) = is_binary_or_sparse_categorical(y_true, y_pred)
          if is_binary:
              metric_obj = metrics_module.BinaryAccuracy(
                  name=str(identifier)
              )
          elif is_sparse_categorical:
              metric_obj = metrics_module.SparseCategoricalAccuracy(
                  name=str(identifier)
              )
          else:
              metric_obj = metrics_module.CategoricalAccuracy(
                  name=str(identifier)
              )
  
      if isinstance(identifier, str):
          metric_name = identifier
      else:
          metric_name = get_object_name(metric_obj)
  
      if not isinstance(metric_obj, metrics_module.Metric):
          metric_obj = metrics_module.MeanMetricWrapper(metric_obj)
  
      metric_obj.name = metric_name
      return metric_obj
  
imports: import tree
  from keras import backend
  from keras import losses
  from keras import metrics
  from keras import ops
  from keras.utils.naming import get_object_name
label_desc: Use image node_id 3 for calling a global function with example usage: get_metric(identifier, y_true, y_pred) and returns: metric_obj, None