keras-team/keras · error · ValueError

Unknown layer

Error message

Unknown layer: {history[0]}

What it means

Raised while reviving serialized KerasTensors during Functional deserialization: a tensor's recorded keras_history references a layer name that is not present in the created_layers mapping built so far. The graph cannot reconnect the tensor to its producing layer, indicating an inconsistent or edited config.

Solutions

  1. Ensure all layers referenced by tensors exist in the model config with identical names
  2. Re-save the model to produce a self-consistent config instead of modifying it manually
  3. Check that custom layers keep stable names between save and load
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/models/functional.py:795 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/4c671a86b3e093ed. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/models/functional.py:795

                    f"inbound_node_index = {inbound_node_index}"
                )
            inbound_node = inbound_layer._inbound_nodes[inbound_node_index]
            input_tensors.append(
                inbound_node.output_tensors[inbound_tensor_index]
            )
        return [unpack_singleton(input_tensors)], kwargs

    args = serialization_lib.deserialize_keras_object(node_data["args"])
    kwargs = serialization_lib.deserialize_keras_object(node_data["kwargs"])

    def convert_revived_tensor(x):
        if isinstance(x, backend.KerasTensor):
            history = x._pre_serialization_keras_history
            if history is None:
                return x
            layer = created_layers.get(history[0], None)
            if layer is None:
                raise ValueError(f"Unknown layer: {history[0]}")
            inbound_node_index = history[1]
            inbound_tensor_index = history[2]
            if len(layer._inbound_nodes) <= inbound_node_index:
                raise IndexError(
                    "Layer node index out of bounds.\n"
                    f"inbound_layer = {layer}\n"
                    f"inbound_layer._inbound_nodes = {layer._inbound_nodes}\n"
                    f"inbound_node_index = {inbound_node_index}"
                )
            inbound_node = layer._inbound_nodes[inbound_node_index]
            return inbound_node.output_tensors[inbound_tensor_index]
        return x

    args = tree.map_structure(convert_revived_tensor, args)
    kwargs = tree.map_structure(convert_revived_tensor, kwargs)
    return args, kwargs

View on GitHub (pinned to 7a34a03db6)