Convolutional Neural Networks
CNNs are the foundational architecture for vision. They exploit spatial locality and translation equivariance through parameter-shared convolutional filters, enabling efficient learning of visual features across all spatial locations.
The Convolution Operation
A 2D convolution applies a learned filter $W \in \mathbb{R}^{k \times k \times C_\text{in}}$ to an input feature map $X \in \mathbb{R}^{H \times W \times C_\text{in}}$:
where $s$ is the stride and $c \in {0, \ldots, C_\text{out}-1}$ indexes output channels.
Key properties:
- Local connectivity: each output element depends on a $k \times k$ spatial region (the receptive field).
- Weight sharing: the same filter is applied at every spatial location. Reduces parameters from $O(H \cdot W \cdot C^2)$ to $O(k^2 \cdot C^2)$.
- Translation equivariance: shifting the input shifts the output by the same amount.
Padding and Stride
Padding: add zeros around the input border to control output spatial size.
valid(no padding): output shrinks by $k-1$.samepadding: $p = \lfloor k/2 \rfloor$; output has same spatial size as input (for stride 1).
Output size:
Stride $s > 1$: downsamples the output. Alternative to pooling.
Pooling
Reduces spatial resolution; provides limited translation invariance.
Max pooling: $\max$ over a $k \times k$ window.
Average pooling: mean over the window.
Global average pooling (GAP): collapse the entire spatial map to a single value per channel. $\mathbb{R}^{H \times W \times C} \to \mathbb{R}^C$. Used as the final spatial reduction before classification.
Depthwise Separable Convolutions
Factor standard convolution into two steps to reduce compute.
Depthwise convolution: apply one filter per input channel independently.
Pointwise convolution: $1 \times 1$ convolution mixes channels.
FLOPs reduction:
For $k=3$: ~9$\times$ fewer multiply-adds. Used in MobileNet, Xception, EfficientNet.
Receptive Field
The receptive field (RF) of a neuron is the region in the input image that influences its output.
After $L$ convolutional layers with kernel size $k$ and stride 1:
With stride $s > 1$ or pooling, the RF grows faster. With dilated convolutions:
where $d$ is the dilation factor.
Dilated (atrous) convolution: insert $d-1$ zeros between filter elements. Expands the RF without increasing parameters or reducing resolution. Used in DeepLab, WaveNet.
Classic CNN Architectures
LeNet-5 (1998)
First successful CNN. Two conv layers + pooling + three FC layers. Input: 32×32 grayscale. Designed for digit recognition.
AlexNet (2012)
Won ImageNet 2012 by a large margin. 5 conv layers + 3 FC layers; ReLU activations; dropout; data augmentation; trained on 2 GPUs. Demonstrated that deep CNNs with GPU training could solve large-scale visual recognition.
VGG (2014)
Systematic use of $3 \times 3$ convolutions only; depth from 11 to 19 layers. Simple, uniform architecture; strong features; widely used as a backbone. High memory usage from large FC layers.
GoogLeNet / Inception (2014)
Inception module: apply $1 \times 1$, $3 \times 3$, $5 \times 5$ convolutions and $3 \times 3$ max pooling in parallel; concatenate output feature maps. Multi-scale feature extraction; $1 \times 1$ bottleneck reduces computation.
ResNet (2015)
Residual connection: the output of a block is $F(x) + x$, not $F(x)$.
If the block is an identity, the gradient flows directly: $\partial \mathcal{L}/\partial x = \partial \mathcal{L}/\partial y$. Solves the degradation problem: deeper networks no longer perform worse on training data. Enabled 50, 101, 152, and 1000-layer networks.
Bottleneck block: $1 \times 1$ (reduce channels) → $3 \times 3$ → $1 \times 1$ (expand channels). Reduces FLOPs.
DenseNet (2017)
Each layer receives feature maps from all previous layers: $x_l = H_l([x_0, x_1, \ldots, x_{l-1}])$. Maximum feature reuse; fewer parameters. Strong for segmentation tasks.
EfficientNet (2019)
Compound scaling: simultaneously scale depth $d$, width $w$, and resolution $r$ with a fixed ratio under a compute constraint. Found via neural architecture search (NAS).
EfficientNet-B7 achieves state-of-the-art ImageNet accuracy with significantly fewer parameters than prior models.
ConvNeXt (2022)
Redesigns ResNet to incorporate design choices from Vision Transformers (larger kernels $7 \times 7$, depthwise conv, GeLU, LayerNorm, fewer activations). Competitive with ViT while maintaining the simplicity of CNNs.
Normalization in CNNs
Batch Normalization: normalize over the batch and spatial dimensions for each channel:
Standard for image classification. Reduces sensitivity to initialization; allows higher learning rates.
Layer Norm / Group Norm: alternatives when batch size is small (detection, segmentation). Group Norm normalizes over groups of channels per sample; independent of batch size.
Spatial Attention and Channel Attention
SE (Squeeze-and-Excitation) block: globally pool each channel; learn channel-wise scaling weights via a small FC bottleneck. Recalibrates channel importance.
CBAM (Convolutional Block Attention Module): sequential channel attention then spatial attention. Applied in many detection and classification backbones.