keras-team/keras · error · AttributeError

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

Error message

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

What it means

The inputs property returns the input KerasTensors of the functional graph; without build or an InputLayer there are none, so access fails.

Source

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

        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."
        )

    @property
    def input_dtype(self):
        # Sequential.__call__ will try to convert its inputs
        # to the dtype expected by its input layer, if any.
        layers = self._layers
        if layers and isinstance(layers[0], InputLayer):
            return layers[0].dtype

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Build the model first
  2. Construct with an explicit Input layer
  3. Derive inputs yourself from your data pipeline if the model is unbuilt

Example fix

# before
ins = model.inputs

# after
model.build((None, 28, 28))
ins = model.inputs
Defensive patterns

Strategy: try-catch

Validate before calling

has_inputs = bool(model._functional)

Try / catch

try:
    ins = model.inputs
except AttributeError:
    model.build(input_shape)
    ins = model.inputs

Prevention

When it happens

Trigger: model = keras.Sequential(); model.inputs before any build/InputLayer

Common situations: Keras 3 migrations where code assumed graph-mode inputs were always available

Related errors


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