Skip to content
mlmentorship

CNN architecture

Calculate convolution shapes, shared parameters, arithmetic, and receptive fields, then distinguish spatial information from channel capacity.

Published · 10 min read ·Specialist ·Intermediate
Reading depth

Summary

A convolution reuses one local linear operator across spatial positions; a CNN composes these operators with nonlinearities and other layers. Weight sharing ties parameters, while stride, padding, dilation, and channel counts determine shapes and information loss. The architectural bias does not by itself guarantee invariance, semantic hierarchy, or superior sample efficiency.

The building block: convolutional layer

Use channels-last notation here, with input . An ungrouped layer has weights and optionally biases. Along either spatial axis,

Here are padding, dilation, and stride; require valid positive output dimensions.

For unit stride and dilation, omitting boundary indexing, the common cross-correlation implementation computes:

For a numerical fixture, use input , sixteen filters, stride one, padding one, and dilation one. Output is ; parameters total . There are multiply-accumulates, excluding biases. Counting one multiply and one add per MAC gives FLOPs under that convention. The diagram uses different illustrative channel counts: thirty-two, then sixty-four.

Learning objective

Pooling collapses space while keeping one output per channel

Spatial pooling keeps the channel axisGlobal average pooling reduces every spatial channel map to one number. It does not merge all channels into one scalar.Collapse space, not channelsChannel 10202202002022020/ 161Channel 21313313113133131/ 162Channel 32424424224244242/ 163Sixteen spatial values become one perchannelThree channels still produce threeoutputs.
Derivation
CNN spatial and channel feature pyramid Four numbered stages run left to right. A 32 by 32 RGB input becomes a 32 by 32 stack of 32 local feature maps, then a downsampled 16 by 16 stack of 64 feature maps, and finally 64 values after global average pooling. The drawn squares become spatially smaller while their offset stacks become deeper. Labels below state that spatial resolution decreases, channel count increases, and receptive field grows. 1 Input 2 Local features 3 Downsample 4 Pool 32 × 32 × 3 32 × 32 × 32 16 × 16 × 64 1 × 1 × 64 same filter at every location spatial resolution decreases: 32 → 16 → 1 channels and receptive field increase
Read it this way: follow the stated grid and channel dimensions from left to right. These illustrated layers preserve, then downsample, the grid while changing channel width. Global average pooling produces one value per channel. The spatial choices determine which locations remain distinguishable.
Check: Why does spatial pooling produce 1x1x64 rather than one scalar for the entire image?
Read it this way: Global average pooling reduces every spatial channel map to one number. It does not merge all channels into one scalar.
How many outputs remain when only the spatial axes are averaged?

Standard CNN ingredients

  • Spatial convolution: shared local feature computation.
  • ReLU/GELU: nonlinear composition rather than one collapsed affine map.
  • Normalization: an implementation choice, not a prerequisite for every trainable CNN.
  • Pooling/strided convolution: different downsampling operators with distinct aliasing and information effects.
  • Global average pooling: one spatial mean per channel, not universal input-transformation invariance.
  • convolution: channel mixing at each location.

Receptive field

Track receptive-field extent and input-coordinate spacing , starting from . One layer gives and per axis. Two stride-one layers therefore span five input positions, not an exponential extent. Boundary handling and strided sampling qualify translation equivariance; arbitrary one-pixel shifts need not produce one-cell output shifts.

Change the Requirement

Preserve Fine Spatial Evidence

New task: Retain small-object or boundary information that downsampling removes.

Picture and change: Consider higher-resolution paths, suitable dilation, or multiscale features rather than merely widening channels.

Check: Two patches with one active pixel in different locations have the same average, . More channels after that scalar average cannot reconstruct which location was active.

Use when: Localization matters; measure compute, aliasing, and dense-task performance together.

Reduce Channel Work

New task: Replace full convolution with depthwise spatial filtering followed by pointwise mixing.

Picture and change: For the fixture, weight counts become , ignoring biases.

Check: Arithmetic becomes MACs, but the restricted factorization cannot represent every full convolution.

Use when: Measured hardware cost binds; fewer MACs do not guarantee lower latency.

Architectural eras

EraArchitectureKey idea
2012AlexNetFirst major win; ReLU + dropout + GPU
2014VGGAll convs, very deep
2014GoogLeNet / InceptionMulti-scale modules, dim reduction
2015ResNetResidual connections enable 50+ layers
2016DenseNetDense feature reuse
2017MobileNetDepthwise separable convs for efficiency
2019EfficientNetCompound scaling depth × width × resolution
2020ViTTransformers replace CNN backbones
2022ConvNeXtModernized ResNet matching ViT performance

The table names historical design examples, not a measured ranking or deployment census.

ConvNeXt and the modern CNN

ConvNeXt (Liu et al., 2022) modernized ResNet-50 by adopting transformer-era design choices:

  • LayerNorm instead of BatchNorm.
  • GELU instead of ReLU.
  • Larger kernels ( depthwise).
  • Inverted bottleneck (channels-up then down).

Compare complete training recipes, workloads, quality targets, and hardware before attributing a result solely to convolution versus attention.

Common pitfalls

  • Shape assumptions. A valid convolution need not shrink the grid; stride and padding must be declared.
  • Axis confusion. Distinguish the chosen tensor layout from the library’s default and physical memory layout.
  • Invariance claims. Pooling averages feature positions; it does not make every input transformation irrelevant.
  • Theoretical versus effective context. A receptive-field bound lists possible dependencies, not equal influence from every input pixel.