Understanding Convolutional Neural Networks
How machines process multi-channel images, extract spatial features, and power modern computer vision—from digit recognition to real-time object detection.
Spatial Hierarchy
Preserves 2D/3D pixel relationships instead of flattening images into 1D lists.
Feature Extraction
Automatically learns filters for edges, textures, shapes, and complex objects.
Parameter Sharing
Reuses small kernels across the entire input volume, drastically cutting parameters.
Why Not Standard Neural Networks (ANNs)?
⚠️ 1. Parameter Explosion
A tiny 28×28 grayscale digit image has 784 pixels. Connecting this to one hidden layer of 512 neurons requires 401,408 weights. For a 1000×1000×3 RGB photo, a single layer needs 3 billion parameters!
🧩 2. Loss of Spatial Structure
Flattening a 2D grid into a 1D vector destroys vital neighborhood context. Pixels adjacent vertically or diagonally are separated, making it hard to recognize patterns under translation.
Traditional ANN Approach: Flattening a 28×28 Image of Digit "9"
CNNs solve this by using local receptive fields—scanning small regions at a time!
The Convolution Operation (Interactive)
A small matrix called a Kernel (or Filter) slides across the Input Image. At each position, we compute the element-wise multiplication and sum the results to produce an Activation / Feature Map.
How Kernels Detect Visual Features
Different weights inside a kernel act as specialized feature detectors. Early CNN layers learn low-level filters (edges, corners), while deeper layers combine them into high-level shapes.
Hover over any cell in the 4×4 Output Map to highlight its 3×3 receptive field!
How a 3-Channel RGB Image is Processed
An RGB image has shape H × W × 3 (Red, Green, Blue). A single convolutional filter also has depth 3 (F × F × 3)—one kernel slice per color channel—whose dot products are summed element-wise (+ bias) into one 2D feature map.
H×W×3 → Conv (K filters) → O×O×K → ReLU → Pool → Flatten → Softmax.
Layer Parameters & Receptive Field
Number of Learnable Parameters per Layer
Understanding model complexity across CONV, POOL, and Fully Connected (FC) layers:
| Layer Type | Input → Output | Parameters Formula |
|---|---|---|
| CONV | I×I×C → O×O×K | (F × F × C + 1) · K |
| POOL | I×I×C → O×O×C | 0 (Fixed operation) |
| FC (Dense) | Nin → Nout | (Nin + 1) × Nout |
* "+ 1" accounts for the bias parameter per filter (CONV) or per neuron (FC).
Receptive Field (Rk)
The area Rk × Rk of the original input image that a single neuron in layer k can "see". Stacking small 3×3 layers expands the effective field of view with fewer parameters!
Activation Functions (ReLU & Variants)
Convolution is a linear operation (dot products). Applying a non-linear activation function element-wise after every CONV layer enables CNNs to learn complex, non-linear decision boundaries.
Fast, sparse activations; zeroes out negative values.
Small slope (ε ≈ 0.01) prevents "dying ReLU" neurons.
Smooth curve everywhere; pushes mean activations near 0.
Different Types of Pooling Layers
Click any pooling type on the left to see how it compresses the same 4×4 activation map:
How an End-to-End CNN Works (Live Demo)
Watch a 6×6 binary image pass through every single layer of a real CNN forward pass: Input (6×6) → Conv 3×3 + ReLU (4×4) → Max Pool 2×2 (2×2) → Flatten (4D) → Dense + Softmax.
[4, 4, 4, 4] → Softmax predicts Pattern "X" (94%).
Where CNNs Are Used in Computer Vision
Object Detection
Predicts both class probabilities and bounding box coordinates (bx, by, bh, bw) for multiple objects using architectures like YOLO and Faster R-CNN.
Face Verification
Uses Siamese Networks and Triplet Loss to encode faces into compact embeddings and measure similarity distance d(img₁, img₂) for one-shot recognition.
Famous CNN Backbones
Modern vision systems build upon landmark CNN designs that solved vanishing gradients and multi-scale feature extraction: