code: def infer_metric_direction(metric):
      # Handle str input and get canonical object.
      if isinstance(metric, six.string_types):
          metric_name = metric
  
          if metric_name.startswith("val_"):
              metric_name = metric_name.replace("val_", "", 1)
  
          if metric_name.startswith("weighted_"):
              metric_name = metric_name.replace("weighted_", "", 1)
  
          # Special-cases (from `keras/engine/training_utils.py`)
          if metric_name in {"loss", "crossentropy", "ce"}:
              return "min"
          elif metric_name == "acc":
              return "max"
  
          try:
              if (
                  "use_legacy_format"
                  in inspect.getfullargspec(
                      keras.metrics.deserialize
                  ).args
              ):
                  metric = (
                      keras.metrics.deserialize(  # pragma: no cover
                          metric_name, use_legacy_format=True
                      )
                  )
              else:
                  metric = (
                      keras.metrics.deserialize(  # pragma: no cover
                          metric_name
                      )
                  )
          except ValueError:
              try:
                  if (
                      "use_legacy_format"
                      in inspect.getfullargspec(
                          keras.losses.deserialize
                      ).args
                  ):
                      metric = (
                          keras.losses.deserialize(  # pragma: no cover
                              metric_name, use_legacy_format=True
                          )
                      )
                  else:
                      metric = (
                          keras.losses.deserialize(  # pragma: no cover
                              metric_name
                          )
                      )
              except Exception:
                  # Direction can't be inferred.
                  return None
  
      # Metric class, Loss class, or function.
      if isinstance(metric, (keras.metrics.Metric, keras.losses.Loss)):
          name = metric.__class__.__name__
          if name == "MeanMetricWrapper":
              name = metric._fn.__name__  # pragma: no cover
      elif isinstance(metric, str):
          name = metric
      else:
          name = metric.__name__
  
      if name in _MAX_METRICS or name in _MAX_METRIC_FNS:
          return "max"
      elif hasattr(keras.metrics, name) or hasattr(keras.losses, name):
          return "min"
  
      # Direction can't be inferred.
      return None
  
imports: import inspect
  import numpy
  import six
  from keras_tuner import protos
  from keras_tuner.api_export import keras_tuner_export
  from keras_tuner.backend import keras
label_desc: Use image node_id 1 for calling a global function with example usage: infer_metric_direction(metric) and returns: None, str, str, str, str, None