CNN Output Shapes: Calculate Every Convolution and Pooling Dimension by Hand

Learn a repeatable axis-by-axis method, then follow a 32 x 32 x 3 tensor through two convolutions, max pooling and global average pooling.

KnowledgeGate Team

Exam prep & CS education

Updated 25 Nov 20266 min read
CNN Output Shapes: Calculate Every Convolution and Pooling Dimension by Hand

A CNN layer can look correct while one wrong assumption about stride, padding, dilation or filter count breaks later tensor shapes. Use a repeatable method. Catch errors before they spread. A 32 x 32 x 3 input passes through a convolution, max pooling, a second convolution and global average pooling. Rectangular, dilated and SAME cases require separate checks. Solve each spatial axis independently; channels follow another rule.

1. CNN output-shape formula: separate space from channels

Write input as H_in x W_in x C_in. A convolution specifies kernel K_h, K_w, stride S_h, S_w, dilation D_h, D_w, four padding values and F filters. Batch is preserved and omitted. Libraries may display NHWC or NCHW; the axes are identical.

First find K_eff,h = D_h(K_h - 1) + 1 and K_eff,w = D_w(K_w - 1) + 1. Then use:

H_out = floor[(H_in + P_top + P_bottom - K_eff,h) / S_h] + 1

W_out = floor[(W_in + P_left + P_right - K_eff,w) / S_w] + 1

Axis

Changed by

Not changed by

Height

K_h, S_h, D_h, top/bottom padding

Width values, F

Width

K_w, S_w, D_w, left/right padding

Height values, F

Channels

F for convolution; preserved by max/average pool

Spatial values

Batch

Nothing here

Everything here

Each kernel spans all C_in channels, which are absent from the spatial formula. Skill Development Courses lists related skill tracks; Approaches to AI gives broader context.

2. CNN convolution output: work 32 x 32 x 3 to 16 x 16 x 8

Use input 32 x 32 x 3, 8 filters, kernel 3 x 3, stride 2 x 2, padding 1 per side and dilation 1 x 1. Both effective kernels are 1(3 - 1) + 1 = 3.

H_out = floor[(32 + 1 + 1 - 3)/2] + 1

= floor(31/2) + 1 = 15 + 1 = 16

Width is identical, so W_out = 16. Eight filters set depth, giving 16 x 16 x 8.

Shape is not parameter count. Each filter has 3 x 3 x 3 = 27 weights. One bias each gives 27 x 8 + 8 = 224 trainable parameters, not a tensor dimension.

Pipeline diagram tracing a 32 x 32 x 3 input through Conv1, max pooling, Conv2 and global average pooling to length 16.

3. CNN pooling and a second convolution: finish the shape pipeline

Max-pool 16 x 16 x 8 with a 2 x 2 window, stride 2, zero padding and dilation 1:

H_out = W_out = floor[(16 - 2)/2] + 1 = 7 + 1 = 8

Pooling acts inside each channel, producing 8 x 8 x 8, not 8 x 8 x 1 or 8 x 8 x 16.

Conv2 takes 8 x 8 x 8 with 16 filters, kernel 5 x 5, stride 1, zero padding and dilation 1:

H_out = W_out = floor[(8 - 5)/1] + 1 = 4

Filter count gives 4 x 4 x 16. Global average pooling reduces each 4 x 4 map to one scalar, producing 1 x 1 x 16, or length 16 after flattening.

The chain is 32 x 32 x 3 -> 16 x 16 x 8 -> 8 x 8 x 8 -> 4 x 4 x 16 -> 16.

4. Rectangular CNN inputs: calculate height and width independently

Take input 31 x 27 x 3, 12 filters, kernel 5 x 3, stride 2 x 1, dilation 1 x 1, padding 2 above and below, and 1 left and right.

Axis

Calculation

Output

Height

K_eff,h = 5; floor[(31 + 2 + 2 - 5)/2] + 1 = floor(30/2) + 1

16

Width

K_eff,w = 3; floor[(27 + 1 + 1 - 3)/1] + 1 = 26 + 1

27

Twelve filters make 16 x 27 x 12. Here, 5 x 3 describes two kernel axes, 2 x 1 gives independent strides, and padding is per side. Input depth 3 must match each kernel's depth, but cannot turn 12 filters into 36 channels.

5. Dilation and SAME padding: replace labels with numbers

For length 15, kernel 3, dilation 2, stride 2 and padding 1 per side, K_eff = 2(3 - 1) + 1 = 5. Output is floor[(15 + 1 + 1 - 5)/2] + 1 = floor(12/2) + 1 = 7. A common shortcut skips the dilation step and uses K_eff = 3: floor[(15 + 2 - 3)/2] + 1 = 8, which is wrong.

Under the explicit SAME convention output = ceil(input/stride), calculate P_total = max[(output - 1)S + K_eff - input, 0].

For input 8, kernel 3, dilation 1, stride 2, output is ceil(8/2) = 4. Padding totals (4 - 1)2 + 3 - 8 = 1, split 0 before and 1 after. Input 7 also outputs 4, but padding totals 2, split 1 and 1.

Two 1D strips comparing SAME padding for length 8 and length 7 with kernel 3 and stride 2, each producing four windows.

Use numeric padding directly and zero for VALID. For SAME, state the convention and derive each side. It need not be symmetric or preserve size when stride exceeds 1.

6. CNN output-shape mistakes: catch them before the next layer

Mistake

Wrong consequence

Repair

Omit final +1

One fewer position

Add after floor

Divide before subtracting K_eff

Wrong rounding

Finish numerator

Round instead of floor

Count partial window

Floor quotient

Use K, not K_eff

Output too large

Expand dilation

Multiply channels by F

Inflate depth

Depth equals F

Reduce channels in pooling

Lose maps

Preserve depth

Make stride 2 x 1 scalar 2

Reduce width

Separate axes

Assume symmetric SAME

Misplace padding

Derive and split

Checks: Conv1 depth is 8, max pool keeps 8, and Conv2 depth is 16. Spatial sizes cannot be negative; each floored window count is an integer. A negative numerator means no fit.

Conv1's padded length is 32 + 2 = 34. Width-3 starts 0, 2, ..., 30 give 16 legal windows; start 32 crosses the boundary.

7. CNN output-shape questions: three exact checks

A. 28 x 28 x 1, 6 filters, kernel 5, stride 1, padding 0 gives 24 x 24 x 6. A following 2 x 2, stride-2 pool gives 12 x 12 x 6.

B. 64 x 48 x 16, 32 filters, kernel 3 x 5, stride 2 x 2, symmetric padding 1 x 2, dilation 1 gives 32 x 24 x 32. Height is floor[(64 + 2 - 3)/2] + 1 = floor(63/2) + 1 = 32; width is floor[(48 + 4 - 5)/2] + 1 = floor(47/2) + 1 = 24. Flooring discards the half-window.

C. Length 10, kernel 3, dilation 2, stride 1, padding 0 has effective kernel 5 and output (10 - 5)/1 + 1 = 6.

Use Artificial Neural Networks MCQs for broader practice. To compare image tensors with sequence-based concepts, use the adjacent Introduction to Natural Language Processing MCQs.

8. CNN output shapes: the short version and next step

  1. Write the input axes.

  2. Expand dilation into the effective kernel.

  3. Calculate height and width separately.

  4. Floor only after the complete division.

  5. Set channels from filters, or preserve them through ordinary pooling.

The result to recover is 32 x 32 x 3 -> Conv1 16 x 16 x 8 -> MaxPool 8 x 8 x 8 -> Conv2 4 x 4 x 16 -> global average pool length 16. Hide it, derive the chain including K_eff, then change Conv1 stride from 2 to 1 and repeat.

Before writing model code, draw each layer's shape. For a structured broader AI and machine-learning path, explore Artificial Intelligence (AI).