keras-team/keras · error · AttributeError

Sequential model ' ' has no defined outputs yet.

Error message

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

What it means

Raised when a property or method that depends on the model's outputs is accessed on a Sequential model before any layers have been added (or before the model has been built/called). A Sequential model only has defined outputs after at least one layer is added and the model is built on an input, so operations requiring output shape/symbolic outputs fail until then.

Solutions

  1. Build the model or run one forward pass
  2. Add an InputLayer to define the graph eagerly
  3. Use compute_output_spec/compute_output_shape for symbolic probing

Example fix

# before
outs = model.outputs

# after
model.build((None, 28, 28))
outs = model.outputs
Defensive patterns

Strategy: try-catch

Validate before calling

has_outputs = bool(model._functional)

Try / catch

try:
    outs = model.outputs
except AttributeError:
    model.build(input_shape)
    outs = model.outputs

Prevention

When it happens

Trigger: Reading model.outputs on an unbuilt Sequential

Common situations: Grad-CAM style hooks, feature extraction code, or introspection before training

Related errors


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

Appendix: source

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

        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
        return super().input_dtype

    def _is_layer_name_unique(self, layer):
        for ref_layer in self._layers:
            if layer.name == ref_layer.name and ref_layer is not layer:
                return False
        return True

View on GitHub (pinned to 7a34a03db6)