Algorithm selectorConvolutional Neural Network (CNN)

[Deep Learning]

Convolutional Neural Network (CNN).

Neural network designed for processing grid-like data, especially images.

Image classificationFace detectionMedical imaging

SPEC SHEET

FamilyDeep Learning
InterpretabilityLow
Training speedSlow
Data neededLarge
ComplexityHigh

FIG — THE MECHANISM, LIVE

Convolutions change what is learned, not how - the optimiser is still walking a loss surface like this one.

C — How it actually works

Slide small learned filters across the image; each filter lights up where its pattern appears. Early layers learn edges, middle layers textures and parts, late layers whole objects. Weight sharing means "an edge is an edge anywhere", slashing parameters and baking translation tolerance into the architecture itself.

D — The math

Convolution: (X ∗ K)ᵢⱼ = Σₘₙ Xᵢ₊ₘ,ⱼ₊ₙ·Kₘₙ, giving a feature map per filter. Pooling (or strides) downsample; residual connections (ResNet) let gradients flow through very deep stacks.

Training

O(n · Σ HᵢWᵢCᵢₙCₒᵤₜk²) per epoch - GPU territory

Inference

same per image; from milliseconds (MobileNet) to much more

E — When NOT to use it

  • Tabular data - convolution assumes spatial locality your columns do not have
  • Tiny image datasets trained from scratch - fine-tune a pretrained backbone instead
  • Global-relationship-dominated vision tasks with big data budgets - ViTs now compete or win

F — Tuning that matters

  • Never train from scratch first: fine-tune ResNet/EfficientNet/ConvNeXt weights
  • Augmentation (flips, crops, colour jitter, mixup) is worth more than architecture tweaks
  • Freeze the backbone, train the head, then unfreeze with a 10x lower learning rate
  • Match input resolution to what the labels need - counting rivets needs pixels, cats do not

G — Production pitfalls

  • Data leakage through augmentation applied before the train/val split
  • Metric myopia: 99% accuracy while every rare-class image is wrong
  • Ignoring inference cost until deploy - a 500ms model behind a 50ms SLA
  • Training on clean stock photos, deploying on blurry warehouse CCTV

H — Minimal starting point

PYTHON
import torchvision.models as models, torch.nn as nn

net = models.resnet50(weights="IMAGENET1K_V2")
net.fc = nn.Linear(net.fc.in_features, n_classes)
# freeze backbone first, fine-tune head, then unfreeze at lr/10

I — The interview question

What do weight sharing and pooling each buy you?

Weight sharing reuses one filter across all positions: far fewer parameters and translation equivariance - a pattern is detected wherever it occurs. Pooling adds local translation invariance and grows the receptive field, so deeper layers see more of the image with less computation.

J — In the wild

Diabetic-retinopathy screening systems run fine-tuned CNNs on retinal photos at clinic scale - flagging gradeable disease with ophthalmologist-level sensitivity in places with no ophthalmologist within a hundred kilometres.

K — Consider instead