keras-team/keras · error · IndexError

Layer node index out of bounds. inbound_layer =

Error message

Layer node index out of bounds.
inbound_layer = {layer}
inbound_layer._inbound_nodes = {layer._inbound_nodes}
inbound_node_index = {inbound_node_index}

What it means

Raised while reviving serialized tensors: the recorded keras_history node index exceeds the number of inbound nodes the reconstructed layer actually has. This means the layer was called fewer times during reconstruction than when the model was originally built (e.g. because calls were skipped or the config was edited).

Solutions

  1. Re-save the model to regenerate a consistent config
  2. Avoid editing node indices or removing layer calls from the config
  3. Ensure custom layers recreate all their original call invocations when deserialized
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/models/functional.py:799 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/05b8e94c4752e29e. Report an issue: GitHub.

Appendix: source

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

                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


def is_input_keras_tensor(x):
    (
        operation,
        node_index,

View on GitHub (pinned to 7a34a03db6)