Keras Sequential models stack layers with one input and one output each
Answer: Pass a list of layers to keras.Sequential([...]), or build it with model.add(...), starting with keras.Input(shape=...). Use it for a plain stack of layers in which every layer has exactly one input tensor and one output tensor.
Example
import keras
from keras import layers
model = keras.Sequential(
[
keras.Input(shape=(4,)),
layers.Dense(2, activation="relu", name="layer1"),
layers.Dense(3, activation="relu", name="layer2"),
layers.Dense(4, name="layer3"),
],
name="my_sequential",
)
model.summary()
model.pop() # remove the last layer
print(len(model.layers))
When not to use it
A Sequential model is not appropriate when:
- the model or any layer has multiple inputs or multiple outputs
- you need layer sharing
- you want non-linear topology, such as a residual connection or a multi-branch model
Input shapes and weights
- Layers create their weights the first time they are called on an input, because the weight shapes depend on the input shape.
layers.Dense(3).weightsis empty at first. - Starting with
keras.Input(shape=...)gives the model weights and a defined output shape before seeing any data, and letssummary()show the current output shape while you add layers. - The
Inputobject is not part ofmodel.layers, since it isn't a layer. - Specifying the input shape in advance is a recommended best practice when you know it.
Other uses
- A Sequential model behaves very much like a list of layers:
model.layers,add()andpop(). - Once built, it behaves like a Functional API model, so every layer has
inputandoutputattributes for feature extraction. - For transfer learning, set
layer.trainable = Falseon every layer except the last, or stack a frozen pre-trained base model with new classification layers.
See also
Claims
- id: C1 claim: Sequential suits a plain stack of single-input, single-output layers. source: S2 evidence: "appropriate for a plain stack of layers"
- id: C2 claim: The Input object is not shown in model.layers. source: S2 evidence: "the
Inputobject is not displayed as part ofmodel.layers"
- id: C3 claim: Specifying input shape in advance is a recommended best practice. source: S1 evidence: "it's a recommended best practice to always specify the input shape"
Sources
- [S1] The Sequential model. Keras guides. https://keras.io/guides/sequential_model/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] guides/sequential_model.py (source page). keras-team/keras-io (GitHub). https://github.com/keras-team/keras-io/blob/master/guides/sequential_model.py . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Keras guides, The Sequential model; keras-team/keras-io (GitHub), guides/sequential_model.py (source page). Apache-2.0 (https://raw.githubusercontent.com/keras-team/keras-io/master/LICENSE). Copyright Keras authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Keras guides, The Sequential model; keras-team/keras-io (GitHub), guides/sequential_model.py (source page). Apache-2.0 (https://raw.githubusercontent.com/keras-team/keras-io/master/LICENSE). Copyright Keras authors.
Cite this
iinventedlight. 2026. "Keras Sequential models stack layers with one input and one output each." iinventedlight Library, iil:note:1f1ym458, version of 2026-11-18. https://iinventedlight.com/library/notes/keras-sequential/. License: CC-BY-4.0.
@misc{iil_note_1f1ym458,
author = {{iinventedlight}},
title = {{Keras Sequential models stack layers with one input and one output each}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/keras-sequential/},
note = {Permanent ID iil:note:1f1ym458. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/keras-sequential.md.