# https://github.com/keras-team/keras/blob/v3.10.0/keras/src/saving/serialization_lib.py
def deserialize_keras_object(config, custom_objects=None, safe_mode=True, **kwargs):
# Step 1: Handle simple types
if config in PLAIN_TYPES or not isinstance(config, dict):
return config
# Step 2: Extract serialization fields
module = config.get("module") # "keras.layers"
class_name = config.get("class_name") # "Dense", "Lambda", etc.
registered_name = config.get("registered_name")
inner_config = config.get("config", {})
# Step 3: Resolve the class/function
cls = _retrieve_class_or_fn(
class_name,
registered_name,
module,
obj_type="class",
full_config=config,
custom_objects=custom_objects,
)
# Step 4: Instantiate object with config
instance = cls(**inner_config) #
return instance