Recipe
Count a layer's parameters and its output size
Use when: you're given a convolutional or pooling layer's kernel size, channel counts, and stride/padding, and asked how many parameters it has or what shape it outputs
Goal: the layer's total parameter count and the spatial size of its output
Taught in Convolution as a learned operation, pooling, and receptive fields
Quick recipe
-
1
Write down the kernel size k, input channels C_{in}, output channels C_{out} (the number of learned filters), stride S, and total padding P.
Example
A first convolutional layer on a 28\times28 grayscale image: k=3, C_{in}=1, C_{out}=8 (8 filters), S=1, P=2 (same-size padding, one pixel per side).
Why: every later step is arithmetic on these six numbers -- none of them are learned, they're architecture choices made before training starts.
-
2
Each of the C_{out} filters owns its own k\times k\times C_{in} weights plus one bias, so \text{params} = C_{out}\left(k^2C_{in}+1\right). A pooling layer has \text{params}=0 -- it has no filters at all.
Example
8\left(3^2(1)+1\right) = 8(9+1) = 8(10) = 80 parameters.
Why: a filter has to reach into every one of its C_{in} input channels to combine them into one output value, and every filter is trained completely independently of every other one.
-
3
Apply the recalled formula O=\lfloor(N-k+P)/S\rfloor+1 to the input's height and width (identical for a square input).
Example
O = \lfloor(28-3+2)/1\rfloor + 1 = \lfloor27\rfloor + 1 = 28 -- same-size padding kept the grid at 28\times28, now with 8 channels instead of 1.
Why: this is exactly the recalled formula above -- a convolution's output size depends on stride and padding, not just how many filters it has.
-
4
The next layer's C_{in} is this layer's C_{out}; the next layer's N is this layer's O. Repeat Steps 1–3 layer by layer until reaching a flatten-and-dense step.
- the next layer is a pooling layer — same Step 3 formula, but skip Step 2 entirely (params=0).
- the next layer is a dense (fully connected) layer — flatten the final C\times H\times W feature map into one length-CHW vector first (Section 1's own flattening idea, at CNN scale), then count the dense layer's parameters as (\text{inputs})(\text{outputs})+\text{outputs}.
Why: a CNN's total parameter count is the sum across every layer. Every layer's own input size depends on every earlier layer's stride and padding choices -- not just the layer directly before it.
Common mistakes
- Forgetting the +1 per filter for its bias, undercounting every layer by exactly C_{out}.
- Using the previous layer's channel count as C_{out} instead of C_{in} -- C_{in} is what's coming IN to this layer, not how many filters this layer has.
- Applying the output-size formula to a pooling layer's kernel/stride but then also trying to count pooling parameters — pooling never has any, regardless of window size.
- Forgetting to flatten before a dense layer's parameter count, and multiplying by only one of the three flattened dimensions.