keras-team/keras · error · ValueError

Could not interpret serialized

Error message

Could not interpret serialized {printable_module_name}: {identifier}

What it means

Terminal guard in the generic deserialize function: the identifier could not be resolved to any object. After checking the custom_objects dicts (call-scoped, thread-local, global) and module objects, no callable or class matched the identifier, and the identifier itself was neither a config dict nor a resolvable string name, so deserialization cannot continue.

Solutions

  1. Pass custom_objects mapping the identifier to the actual class/function
  2. Use keras.utils.custom_object_scope or register the object with @keras.saving.register_keras_serializable
  3. Fix typos in the identifier string; verify it matches the registered name exactly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/legacy/saving/serialization.py:549 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/c2e435f507ec9a58. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/legacy/saving/serialization.py:549

                raise ValueError(
                    f"Unknown {printable_module_name}: '{object_name}'. "
                    "Please ensure you are using a "
                    "`keras.utils.custom_object_scope` "
                    "and that this object is included in the scope. See "
                    "https://www.tensorflow.org/guide/keras/save_and_serialize"
                    "#registering_the_custom_object for details."
                )

        # Classes passed by name are instantiated with no args, functions are
        # returned as-is.
        if inspect.isclass(obj):
            return obj()
        return obj
    elif inspect.isfunction(identifier):
        # If a function has already been deserialized, return as is.
        return identifier
    else:
        raise ValueError(
            "Could not interpret serialized "
            f"{printable_module_name}: {identifier}"
        )


def validate_config(config):
    """Determines whether config appears to be a valid layer config."""
    return (
        isinstance(config, dict) and _LAYER_UNDEFINED_CONFIG_KEY not in config
    )


def is_default(method):
    """Check if a method is decorated with the `default` wrapper."""
    return getattr(method, "_is_default", False)

View on GitHub (pinned to 7a34a03db6)