code: def get_keras_attr(
      model, attr, max_depth=3, default=sentinel_default_value
  ):
      """Retrieve specific Keras model attributes safely across different versions of Keras
  
      Parameters
      ----------
      model: Instance of :class:`keras.wrappers.scikit_learn.<KerasClassifier; KerasRegressor>`
          A compiled instance of a Keras model, made using the Keras `wrappers.scikit_learn` module
      attr: String
          Name of the attribute to retrieve from `model`
      max_depth: Integer, default=3
          Maximum number of times to check the "model" attribute of `model` for the target `attr` if
          `attr` itself is not in `model` before returning `default` or raising AttributeError
      default: Object, default=object()
          If given, `default` will be returned once `max_depth` attempts have been made to find `attr`
          in `model`. If not given and total attempts exceed `max_depth`, AttributeError is raised
  
      Returns
      -------
      Object
          Value of `attr` for `model` (or a nested `model` if necessary), or None
      """
      try:
          max_depth -= 1
          return getattr(model, attr)
      except (
          AttributeError
      ):  # Keras<2.2.0 has these attributes deeper in `model`
          if max_depth > 0 and hasattr(model, "model"):
              return get_keras_attr(
                  model.model,
                  attr,
                  max_depth=max_depth,
                  default=default,
              )
          elif default is not sentinel_default_value:
              return default
          raise
  
file_path: hyperparameter_hunter/hyperparameter_hunter/compat/keras_helper.py
imports: from hyperparameter_hunter.settings import G
  from hyperparameter_hunter.utils.general_utils import to_snake_case, subdict
  from inspect import signature, _empty
  from types import MethodType
  from typing import List, Tuple
label_desc: Use image node_id 7 for calling a global function with example usage: get_keras_attr(model, attr, max_depth, default) and returns: getattr, get_keras_attr, default