keras-team/keras · error · AttributeError

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

Error message

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

What it means

outputs returns the graph's output tensors; they exist only after the functional graph is materialized. Accessing it earlier raises AttributeError.

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)

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.