Convolutional Neural Network (CNN)
A convolutional neural network (CNN) learns image features with shared sliding filters. Covers its layers, properties, key models, and CNNs vs. ViTs.
A convolutional neural network (CNN) is a deep learning architecture that processes grid-shaped data, most often images, with small learnable filters that slide across the input. Each filter reuses the same weights at every position, so a CNN detects a pattern such as an edge or a wheel wherever it appears while using far fewer parameters than a fully connected network. Stacked layers build a hierarchy of features, from edges and textures in the first layers to object parts and whole objects in deeper ones. CNNs have driven most computer vision progress since AlexNet won the ImageNet challenge in 2012, and they remain the most common choice for real-time vision on edge hardware.
How a CNN Works#
A CNN repeats a few layer types in stages, with each stage working at a lower resolution than the one before:
- Convolution layers: Each layer slides a set of learnable filters, typically 3×3, over the input's height and width. Every filter produces one channel of the output feature map, so a layer with 64 filters outputs 64 channels.
- Normalization and activation: Batch normalization keeps each layer's outputs in a stable range during training, and a nonlinear activation function such as ReLU or SiLU lets stacked layers represent more than one linear transform.
- Downsampling: Max pooling or a stride-2 convolution halves the height and width, which enlarges the receptive field of later layers and cuts computation. Many modern designs downsample mostly with strided convolutions.
- Head: For image classification, global average pooling reduces each final channel to one number, and a fully connected layer maps those numbers to class scores. Detection and segmentation models replace this head with layers that predict boxes or per-pixel masks.
Key Properties of CNNs#
Three properties explain why convolutions suit images. Local connectivity means each output depends only on a small neighborhood of the input, matching the strong correlation between nearby pixels. Weight sharing means one filter serves the whole image, so the parameter count stays the same at any input size. Translation equivariance means shifting the input shifts the feature map by the same amount, so a pattern learned in one corner is recognized everywhere, and pooling layers add some tolerance to small shifts on top of that. Together these properties form the CNN's inductive bias, the built-in assumptions that let it learn from fewer images than a transformer needs.
The PyTorch snippet below compares a convolution layer with a fully connected layer applied to the same 224×224 RGB image.
import torch
from torch import nn
image = torch.randn(1, 3, 224, 224)
# 64 learnable 3x3 filters, each reused at every position of the RGB image
conv = nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1)
# A fully connected layer mapping the same flattened image to only 64 numbers
dense = nn.Linear(3 * 224 * 224, 64)
conv_params = sum(p.numel() for p in conv.parameters())
dense_params = sum(p.numel() for p in dense.parameters())
print(f"Conv2d: output {tuple(conv(image).shape)}, {conv_params:,} parameters")
print(f"Linear: output {tuple(dense(image.flatten(1)).shape)}, {dense_params:,} parameters")It prints Conv2d: output (1, 64, 224, 224), 1,792 parameters and Linear: output (1, 64), 9,633,856 parameters. Weight sharing lets the convolution produce 64 full-resolution feature maps from 1,792 parameters, and the fully connected layer needs 5,376 times as many to output only 64 numbers.
Landmark CNN Architectures#
- LeNet-5 (1998): Yann LeCun's network for reading handwritten digits set the pattern of alternating convolution and pooling layers followed by fully connected layers, and it was deployed commercially to read bank checks.
- AlexNet (2012): Trained on two GPUs with ReLU activations and dropout, it won the ILSVRC 2012 challenge with a 15.3% top-5 test error, against 26.2% for the second-best entry.
- VGG (2014): Showed that stacking small 3×3 convolutions to a depth of 16 to 19 weight layers substantially improves ImageNet accuracy.
- ResNet (2015): Residual connections made networks up to 152 layers deep trainable, and a ResNet ensemble won ILSVRC 2015.
- U-Net (2015): An encoder-decoder CNN with skip connections that became the standard architecture for biomedical image segmentation.
- ConvNeXt (2022): A ResNet modernized with transformer-era design choices that reaches 87.8% ImageNet top-1 accuracy and outperforms Swin Transformer on COCO detection.
Where CNNs Are Used#
- Object detection: Single-stage CNN detectors find and classify objects in one forward pass, fast enough for video on cameras, phones, and embedded boards.
- Medical image analysis: U-Net-style CNNs segment organs, tumors, and lesions in CT and MRI scans, where each pixel's label matters.
- Pose estimation: CNNs predict body keypoints for sports analysis, ergonomics, and fitness apps.
- Signals beyond images: One-dimensional convolutions process audio waveforms and sensor time series, and two-dimensional CNNs classify spectrograms in speech recognition.
CNNs vs. Vision Transformers#
A vision transformer (ViT) splits an image into patches and relates every patch to every other patch with self-attention, so it has global context from the first layer. Its weaker inductive bias has a cost: the original ViT trailed ResNets of similar size when trained on ImageNet alone and matched or beat them only after pretraining on 14 million to 300 million images. Attention cost also grows with the square of the number of patches, which makes high-resolution input expensive, and a convolution's cost grows only linearly with pixel count. Many current models therefore combine the two, keeping convolutional stages at high resolution and adding attention where the feature map is small. YOLO26 follows this pattern: Conv blocks (convolution, batch normalization, and SiLU) and C3k2 blocks do most of the work, and multi-head self-attention runs only on the stride-32 feature map, a 20×20 grid for a 640×640 image.










