keras-team/keras · error · ValueError

Sequential model {self.name} cannot be built because it has

Error message

Sequential model {self.name} cannot be built because it has no layers. Call `model.add(layer)`.

What it means

Error "Sequential model {self.name} cannot be built because it has no layers. Call `model.add(layer)`." thrown in keras-team/keras.

Source

Thrown at keras/src/models/sequential.py:172

            input_shape = self._layers[0].input_shape
            self.build(input_shape)

    def _lock_state(self):
        # Unlike other layers, Sequential is mutable after build.
        pass

    def _obj_type(self):
        return "Sequential"

    def build(self, input_shape=None):
        try:
            input_shape = standardize_shape(input_shape)
        except:
            # Do not attempt to build if the model does not have a single
            # input tensor.
            return
        if not self._layers:
            raise ValueError(
                f"Sequential model {self.name} cannot be built because it has "
                "no layers. Call `model.add(layer)`."
            )
        if isinstance(self._layers[0], InputLayer):
            if self._layers[0].batch_shape != input_shape:
                raise ValueError(
                    f"Sequential model '{self.name}' has already been "
                    "configured to use input shape "
                    f"{self._layers[0].batch_shape}. You cannot build it "
                    f"with input_shape {input_shape}"
                )
        else:
            dtype = self._layers[0].compute_dtype
            self._layers = [
                InputLayer(batch_shape=input_shape, dtype=dtype)
            ] + self._layers

        # Build functional model

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/models/sequential.py:172 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/6c6c51dc7e22188d. Report an issue: GitHub.