Learn Before
Example

LeNet-5 Layer-by-Layer Shape Trace

Passing a single-channel 28×2828 \times 28 image through LeNet-5 produces the following shapes at each layer:

  1. Conv2d (5×55 \times 5, padding 22, 66 channels): output 1×6×28×281 \times 6 \times 28 \times 28
  2. Sigmoid: output 1×6×28×281 \times 6 \times 28 \times 28
  3. AvgPool2d (2×22 \times 2, stride 22): output 1×6×14×141 \times 6 \times 14 \times 14
  4. Conv2d (5×55 \times 5, no padding, 1616 channels): output 1×16×10×101 \times 16 \times 10 \times 10
  5. Sigmoid: output 1×16×10×101 \times 16 \times 10 \times 10
  6. AvgPool2d (2×22 \times 2, stride 22): output 1×16×5×51 \times 16 \times 5 \times 5
  7. Flatten: output 1×4001 \times 400
  8. Linear (120120) + Sigmoid: output 1×1201 \times 120
  9. Linear (8484) + Sigmoid: output 1×841 \times 84
  10. Linear (1010): output 1×101 \times 10

The first convolutional layer uses 22 pixels of padding to preserve the spatial dimensions of the 28×2828 \times 28 input, compensating for the reduction that a 5×55 \times 5 kernel would otherwise cause. The second convolutional layer uses no padding, reducing height and width by 44 pixels each. As the stack deepens, the number of channels increases (16161 \to 6 \to 16) while spatial dimensions shrink, until flattening yields a 400400-element vector.

Image 0

0

1

Updated 2026-06-29

Tags

D2L

Dive into Deep Learning @ D2L