C.W.K.
Stream
Lesson 04 of 07 · published

model.summary()

~9 min · sequential

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

Your model's X-ray

model.summary() prints the architecture as a table — layer names, output shapes, per-layer parameter counts, and trainable vs non-trainable totals. It's the first thing you run after building and before you ever call .compile(), because it surfaces structural mistakes in seconds that would otherwise cost you an entire training run to discover.

Read the table top to bottom and three things jump out (the Code section shows a real example). A (None, 128) output shape means the batch dimension is left as None — it gets filled in at fit time. A param count of 0 means a layer with no learnable weights, like Flatten or Dropout; that's expected, not a bug. And a non-zero non-trainable count points at frozen layers or BatchNormalization's moving statistics.

Where the parameter numbers come from

The param column isn't magic — you can derive it by hand, and doing so once cements how a layer actually works. A Dense layer mapping input size n to output size m has n × m weights plus m biases. So Dense(128) fed a 784-vector is 784 × 128 + 128 = 100,480 parameters. If your hand math and summary() disagree, your mental model of the shapes is wrong — and that's exactly the bug you want to catch before training, not after.

Code

model.summary() output, annotated·python
model.summary()
# Output:
# ┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
# ┃ Layer (type)           ┃ Output Shape     ┃    Param # ┃
# ┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
# │ dense (Dense)          │ (None, 128)      │    100,480 │
# │ dropout (Dropout)      │ (None, 128)      │          0 │
# │ dense_1 (Dense)        │ (None, 10)       │      1,290 │
# └───────────────────────┴──────────────────┴────────────┘

External links

Exercise

Build a CNN with 2 Conv2D + 2 Dense layers. Read model.summary(). Verify your math: # parameters in each Conv = (kernel_h × kernel_w × in_channels + 1) × out_channels.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.