Keras Sequential API in Depth

Deep Learning with Keras and TensorFlow 10 min min read Updated: Nov 16, 2026 Beginner
Keras Sequential API in Depth
Beginner Topic 1 of 8

What is the Sequential API?

A Sequential model is a simple stack of layers, one after the other, where each layer has exactly one input and one output. It is the easiest way to build a network in Keras and is perfect for most beginner projects.

Two Ways to Create a Sequential Model

python import keras from keras import layers # Way 1: pass a list model = keras.Sequential([ keras.Input(shape=(20,)), layers.Dense(64, activation="relu"), layers.Dense(32, activation="relu"), layers.Dense(1, activation="sigmoid"), ]) # Way 2: add layers one by one model = keras.Sequential(name="my_model") model.add(keras.Input(shape=(20,))) model.add(layers.Dense(64, activation="relu")) model.add(layers.Dense(32, activation="relu")) model.add(layers.Dense(1, activation="sigmoid"))
Always define the input shape: Start with keras.Input(shape=...). Then Keras knows the size of every layer immediately, and model.summary() works right away.

Reading model.summary()

python model.summary()
Result

A table listing each layer, its output shape and the number of parameters, followed by the total parameters.

For the model above, the first Dense layer has 20 x 64 weights plus 64 biases, which is 1,344 parameters.

text Dense(64) parameters = inputs x units + units = 20 x 64 + 64 = 1344 Dense(32) parameters = 64 x 32 + 32 = 2080 Dense(1) parameters = 32 x 1 + 1 = 33 Total = 3457

Useful Dense Layer Options

OptionMeaning
unitsNumber of neurons
activationActivation function
use_biasAdd the bias term (default True)
kernel_initializerHow weights start, e.g. he_normal
kernel_regularizerL1 or L2 penalty
nameA readable layer name

Looking Inside the Weights

python first_layer = model.layers[0] weights, biases = first_layer.get_weights() print(weights.shape) # (20, 64) print(biases.shape) # (64,) # Number of layers and trainable parameters print(len(model.layers)) print(model.count_params())

Freezing Layers

python model.layers[0].trainable = False # its weights will not be updated model.compile(optimizer="adam", loss="binary_crossentropy") # compile again after changing trainable

Plot the Model

python keras.utils.plot_model(model, show_shapes=True, to_file="model.png")

This needs the pydot and graphviz tools to be installed. It is optional but nice for documentation.

Limitations of Sequential

  • No multiple inputs or outputs
  • No branches or skip connections
  • No layer sharing

For these cases we use the Functional API, which is the next lesson.

Conclusion

Sequential is the fastest way to build a plain stack of layers. Use summary() often, and count parameters to understand the size of your model.

Quick Summary: Sequential stacks layers. Start with Input, use summary() to inspect and get_weights() to look inside.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators