keras-team/keras · error · AttributeError
Sequential model '{self.name}' has no defined input shape ye
Error message
Sequential model '{self.name}' has no defined input shape yet. What it means
The input_shape property only exists once the Sequential has a functional graph, i.e. after build() or after an InputLayer was supplied. Before that there is no input shape to report, so an AttributeError is raised.
Source
Thrown at keras/src/models/sequential.py:302
**kwargs,
) # Ignore mask
inputs = outputs
return outputs
def compute_output_shape(self, input_shape):
if self._functional:
return self._functional.compute_output_shape(input_shape)
# 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."
)View on GitHub (pinned to 7a34a03db6)
Solutions
- Call model.build(input_shape) first
- Construct with keras.Sequential([keras.Input(...), ...])
- Pass input_shape= to the Sequential constructor
Example fix
# before shape = model.input_shape # after model.build((None, 28, 28)) shape = model.input_shape
Defensive patterns
Strategy: try-catch
Validate before calling
has_input = bool(model._functional) or (
model._layers and isinstance(model._layers[0], keras.layers.InputLayer)) Try / catch
try:
shape = model.input_shape
except AttributeError:
model.build(input_shape)
shape = model.input_shape Prevention
- Pass an Input layer or input_shape when constructing the Sequential
- Call model.build(shape) before reading .input_shape
When it happens
Trigger: model = keras.Sequential([Dense(10)]); print(model.input_shape) before build or calling on data
Common situations: Introspection utilities, TensorBoard callbacks, or shape-logging code run before any data passes through the model
Related errors
- Sequential model '{self.name}' has already been configured t
- Sequential model '{self.name}' has no defined output shape y
- 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`.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/3900311fadb39307.
Report an issue: GitHub.