Skip to content
ML Academy

Neural networks, deep learning, NLP · insight-0438

Compute CNN feature-map sizes on paper before writing the classifier head

Evidence type
documented fact
Difficulty
easy
Roles
ML engineer
Industries
manufacturing

Summary: situation, action, reason, boundary

  1. Situation

    You stack convolution and pooling layers for an image task and hard-code the input size of the first linear layer.

  2. Action

    Write out Hout=⌊(Hin+2p−d(k−1)−1)/s⌋+1H_{out} = \lfloor (H_{in} + 2p - d(k-1) - 1)/s \rfloor + 1 per layer, assert it with a dummy forward, and end the feature extractor with adaptive pooling so the head does not depend on input resolution.

  3. Reason

    The output size is fixed arithmetic of input size, kernel, padding, stride and dilation, so it can be checked before training.

  4. Boundary

    CNNs, pooling layers and 1D convolutions over sequences.

Symptom or risk

A size mismatch crashes at the first forward, or worse, a different input resolution later breaks serving or forces silent resizing.

Exceptions

Pretrained backbones already document their output shapes; still verify with a dummy input.

Trade-offs

Adaptive pooling discards spatial detail that some tasks need; segmentation keeps spatial maps.

Pitfalls

Forgetting that floor division drops a pixel at odd sizes, so a decoder no longer aligns with the encoder.

Example

224 x 224 input, kernel 7, stride 2, padding 3: floor((224 + 6 - 6 - 1)/2) + 1 = 112.

Lessons and concepts

Claims and their sources