keras-team/keras · error · AttributeError

Sequential model '{self.name}' has no defined output shape y

Error message

Sequential model '{self.name}' has no defined output shape yet.

What it means

output_shape requires the model to be built (functional graph present). An unbuilt Sequential has undefined output shape, hence the AttributeError.

Source

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

        # Direct application
        for layer in self.layers:
            output_shape = layer.compute_output_shape(input_shape)
            input_shape = output_shape
        return output_shape

    @property
    def input_shape(self):
        if self._functional:
            return self._functional.input_shape
        raise AttributeError(
            f"Sequential model '{self.name}' has no defined input shape yet."
        )

    @property
    def output_shape(self):
        if self._functional:
            return self._functional.output_shape
        raise AttributeError(
            f"Sequential model '{self.name}' has no defined output shape yet."
        )

    @property
    def inputs(self):
        if self._functional:
            return self._functional.inputs
        raise AttributeError(
            f"Sequential model '{self.name}' has no defined inputs yet."
        )

    @property
    def outputs(self):
        if self._functional:
            return self._functional.outputs
        raise AttributeError(
            f"Sequential model '{self.name}' has no defined outputs yet."
        )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Build the model (build() or a forward pass on real data)
  2. Add an InputLayer first
  3. Use model.compute_output_shape(input_shape) to probe without building

Example fix

# before
out = model.output_shape

# after
model.build((None, 28, 28))
out = model.output_shape
Defensive patterns

Strategy: try-catch

Validate before calling

has_output = bool(model._functional) or len(model._layers) > 0

Try / catch

try:
    shape = model.output_shape
except AttributeError:
    model.build(input_shape)
    shape = model.output_shape

Prevention

When it happens

Trigger: Accessing model.output_shape on a Sequential that has never been built or called

Common situations: Asserting output dimensions in tests, wiring heads to matching shapes, plotting model summaries before fitting

Related errors


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