keras-team/keras · error · ValueError

No such layer: . Existing layers are: .

Error message

No such layer: {name}. Existing layers are: {list(layer.name for layer in self.layers)}.

What it means

Raised by Model.get_layer when a name lookup finds no matching layer. Only one of index/name is allowed; after the index path returns, a name that matches no layer in self.layers falls through to this error, which lists the model's actual layer names to make typos or wrong-model references obvious.

Solutions

  1. Check the layer name against the list of existing layers printed in the error message
  2. Use model.summary() to inspect the model's top-level layer names
  3. If the layer is nested, access the sub-model first, then call get_layer on it
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/models/model.py:218 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/9d199712d4f10a81. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/models/model.py:218

            raise ValueError(
                "Provide only a layer name or a layer index. Received: "
                f"index={index}, name={name}."
            )
        if index is not None:
            if len(self.layers) <= index:
                raise ValueError(
                    f"Was asked to retrieve layer at index {index}"
                    f" but model only has {len(self.layers)}"
                    " layers."
                )
            else:
                return self.layers[index]

        if name is not None:
            for layer in self.layers:
                if layer.name == name:
                    return layer
            raise ValueError(
                f"No such layer: {name}. Existing layers are: "
                f"{list(layer.name for layer in self.layers)}."
            )
        raise ValueError(
            "Provide either a layer name or layer index at `get_layer`."
        )

    @traceback_utils.filter_traceback
    def summary(
        self,
        line_length=None,
        positions=None,
        print_fn=None,
        expand_nested=False,
        show_trainable=False,
        layer_range=None,
    ):
        """Prints a string summary of the network.

View on GitHub (pinned to 7a34a03db6)