keras-team/keras · error · AttributeError
Sequential model ' ' has no defined output shape yet.
Error message
Sequential model '{self.name}' has no defined output shape yet. What it means
Raised when the `output_shape` property of a `Sequential` model is accessed before the model has produced any outputs. Build the model by calling it on an input (or calling `build()`) before accessing `output_shape`.
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 ' ' has no defined input shape yet.
- Sequential model ' ' has no defined inputs yet.
- Sequential model ' ' has no defined outputs yet.
- A Sequential model configuration must be a dictionary…
- Argument `input_tensors` must contain a single tensor.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/e270075c6bc6cdfc.
Report an issue: GitHub.
Appendix: 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)