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
- Build the model (build() or a forward pass on real data)
- Add an InputLayer first
- 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
- Build the model or pass an Input layer first
- Feed one batch through the model to build it before querying .output_shape
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
- Sequential model '{self.name}' has no defined input shape ye
- Sequential model '{self.name}' has no defined inputs yet.
- Sequential model '{self.name}' has no defined outputs yet.
- You must build the layer before accessing `kernel`.
- Cannot enable lora on a layer that isn't yet built.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/e270075c6bc6cdfc.
Report an issue: GitHub.