Convolutional Neural Networks
Convolutional Neural Networks (ConvNets)
🔢 Review: From Neural Networks to ConvNets
Earlier lectures introduced the linear score function for classification. A neural network is created by stacking linear layers with non-linearities (e.g., ReLU) between them. This allows learning intermediate templates — for example, different types of cars (red car vs. yellow car) — which combine to produce final class scores. Today's topic extends this idea: convolutional layers explicitly preserve spatial structure in images.
📜 History of Neural Networks and ConvNets
Early Developments (1950s–1980s)
1957 – Frank Rosenblatt, Mark I Perceptron: First implementation of the perceptron algorithm. It computed a score function W×X+bias, outputting 1 or 0. Weights were updated via a simple rule (no backpropagation yet).
1960 – Widrow and Hoff, Adaline/Madaline: First stacking of linear layers into multilayer perceptrons. Still no principled training method.
1986 – Rumelhart, backpropagation: Introduced the chain rule and gradient-based weight updates, enabling principled training of multi-layer networks.
1980 – Fukushima, Neocognitron: Inspired by Hubel and Wiesel (below), this model used alternating simple cells (modifiable parameters) and complex cells (pooling for invariance). It was the first architecture with convolutional-like layers.
The Modern Era (2000s–2012)
2006 – Hinton & Salakhutdinov: Showed deep neural networks could be trained effectively using layer-wise pre-training with restricted Boltzmann machines, followed by backpropagation fine-tuning.
2012 – Speech recognition breakthrough: Work from Hinton’s lab achieved state-of-the-art results using neural networks for acoustic modeling.
2012 – ImageNet breakthrough (AlexNet): Alex Krizhevsky (with Hinton) introduced the first deep convolutional neural network that dramatically reduced error on the ImageNet benchmark. This kickstarted the widespread use of ConvNets. Key enablers: large datasets (ImageNet) and GPU parallel computing.
Key Inspiration: Hubel and Wiesel (1950s–1960s)
Experiments on cats measured neuron responses to visual stimuli. Two main discoveries:
Topographical mapping: Nearby neurons in the visual cortex represent nearby regions in the visual field.
Hierarchical organization of visual neurons:
Retinal ganglion cells: Responsive to circular spots.
Simple cells: Responsive to oriented edges.
Complex cells: Responsive to orientation and movement.
Hypercomplex cells: Responsive to moving endpoints (corners, blobs, etc.).
This hierarchy inspired the layered structure of ConvNets: early layers learn simple features (edges), mid-layers learn corners/blobs, higher layers learn complex concepts.
From Neocognitron to Modern ConvNets
1998 – Yann LeCun: Applied backpropagation to train convolutional neural networks for document recognition (zip code digits). Used for postal service but didn't scale to complex data.
2012 – AlexNet: Similar architecture to LeCun’s, but larger, deeper, and leveraging GPUs and massive web image data.
Modern Applications of ConvNets
Image classification (AlexNet on ImageNet)
Image retrieval: Learned features enable similarity matching (e.g., retrieving flowers)
Object detection: Localizing objects with bounding boxes (e.g., bus, boat)
Segmentation: Labeling every pixel (e.g., trees, people) — used in self-driving cars
Face recognition: Input face → identity
Video classification: Combining spatial and temporal information
Pose recognition: Identifying joints (shoulders, elbows, etc.)
Game playing: Reinforcement learning with ConvNets (Atari, Go)
Medical image diagnosis, galaxy classification, street sign recognition, whale recognition, aerial map analysis (roads, buildings)
Image captioning: Generating sentence descriptions from images
Artistic applications: Deep Dream (hallucinating objects), neural style transfer (re-rendering images in the style of famous artworks)
🧠 How Convolutional Neural Networks Work
Fully Connected Layer vs. Convolutional Layer
In a fully connected layer, the input (e.g., a 32x32x3 image) is stretched into a vector (3072 elements). The weight matrix is 10×3072, and each neuron is connected to every input element.
In a convolutional layer, spatial structure is preserved. The input is a 3D volume (width × height × depth). Weights are small filters (e.g., 5×5×3) that are slid over the input spatially, computing dot products at every location. This produces activation maps.
The Convolution Operation
Each filter spatially small but extends full depth of input volume (e.g., for a 32×32×3 input, a filter is 5×5×3).
At each spatial location, overlay the filter on a corresponding chunk of the input and compute the dot product (element-wise multiplication then sum) plus a bias term.
The dot product is effectively: WTX+b, where W and X are flattened to vectors.
Stretching the filter (5×5×3 = 75 values) and the input patch into vectors yields the dot product.
Sliding and Stride
The filter is centered at each pixel (or every
stridepixels) and moved across the entire spatial grid.Stride: The number of pixels the filter shifts between applications.
Stride = 1: filter moves one pixel at a time.
Stride = 2: filter jumps two pixels.
The output activation map size depends on input size N, filter size F, and stride S:
Example:
Input = 7×7, filter = 3×3, stride = 1 → output = 5×5.
Input = 7×7, filter = 3×3, stride = 2 → output = 3×3.
Stride = 3 would not fit evenly (non-integer result) → not used.
Padding
Zero padding adds zeros around the border of the input. This allows filters to be applied at edges/corners and helps control output spatial size.
For a padding of P on each side, the effective input dimension becomes N+2P.
Common padding choices to preserve spatial size:
3×3 filter: pad = 1 → output size = input size.
5×5 filter: pad = 2.
7×7 filter: pad = 3.
Output size with padding:
Multiple Filters and Output Volume
A convolutional layer typically uses multiple filters (e.g., 6 filters of size 5×5×3). Each filter produces one activation map. Stacking these gives an output volume of depth equal to the number of filters.
Example: Input 32×32×3, 6 filters of 5×5×3, stride 1, pad 2 → output volume = 32×32×6.
Parameter Calculation in a Convolutional Layer
Each filter has F×F×Din weights plus 1 bias (if depth included). Total parameters = (weights + bias) × number of filters.
Example: Input depth = 3, 10 filters of 5×5 → each filter: 5×5×3 = 75 weights + 1 bias = 76 parameters. Total = 760 parameters.
Common Hyperparameter Settings
Hyperparameter | Common Values |
|---|---|
Filter size F | 3×3, 5×5, 7×7 (odd numbers) |
Stride S | 1, 2 |
Padding P | (F-1)/2 to preserve size |
Number of filters K | Powers of 2 (32, 64, 128, 256, 512) |
1×1 Convolutions
A 1×1 filter still slides spatially, but performs a dot product across the full depth of the input volume. It effectively computes a weighted combination of depth slices. For example: input 56×56×64, 32 filters of 1×1 → output 56×56×32.
Convolution in Deep Learning Frameworks
Torch:
SpatialConvolutionlayer with arguments for input/output channels, kernel size, padding, stride.Caffe: Defined in
.prototxtfiles with fields likenum_output(number of filters),kernel_size,stride,pad.
Brain-Inspired Terminology
Each neuron has local connectivity (only sees a local spatial region) — unlike fully connected layers.
The receptive field is the size of the input region that affects a neuron (e.g., 5×5 for a filter).
Parameter sharing: The same filter (same weights) is applied across all spatial locations. This dramatically reduces the number of parameters compared to fully connected layers.
🔽 Pooling Layers
Purpose
Pooling layers downsample the spatial dimensions (width, height) of activation maps, making representations smaller and more manageable. They also provide invariance to small translations.
Input volume: e.g., 224×224×64 → output: 112×112×64 (depth unchanged).
Only spatial downsampling, no change in depth.
Max Pooling
A filter (e.g., 2×2) slides over the input with a given stride (often 2).
Instead of dot product, take the maximum value within each region.
Example:
Input region (2×2): max value becomes one output pixel.
Stride 2 ensures no overlap (typical).
Intuition: Max pooling captures "how much did this filter fire anywhere in this region?" — useful for detection.
Alternative: Average pooling (less common in modern networks).
Pooling Hyperparameters
Filter size (spatial extent): commonly 2×2 or 3×3.
Stride: usually equal to filter size (e.g., 2 for 2×2) to avoid overlap.
No zero padding for pooling — direct downsampling.
Pooling vs. Stride in Convolution
Stride in convolution also downsamples the output. Recent architectures often use strided convolutions instead of pooling layers for downsampling, which can yield better results.
🧩 Full ConvNet Architecture
A typical convolutional neural network stacks layers in the following pattern:
[Conv → ReLU] × N → [Pool] → [Conv → ReLU] × M → [Pool] → ... → [Fully Connected → ReLU] → SoftmaxConv: Convolutional layer (filters slide over input).
ReLU: Non-linearity (element-wise max(0, x)).
Pool: Max pooling (downsampling).
Fully Connected (FC): Standard neural network layer at the end, connected to all outputs of the last convolutional/pooling layer.
Softmax: Produces class scores (probabilities).
Why This Works
Early layers detect low-level features (edges). Mid-layers detect mid-level features (corners, blobs). Higher layers detect high-level concepts (object parts). This hierarchical feature learning is compatible with Hubel and Wiesel’s observations.
Visualizing Activations
First layer filters are interpretable (e.g., oriented edges) because they operate directly on the input image.
Higher layer activation maps are harder to interpret directly — each pixel represents how much a complex template fires at that location.
A demo by Andrej Karpathy (available online) allows training a ConvNet on CIFAR-10 and visualizing filters and activation maps at each layer.
Trends in Architecture Design
Smaller filters (3×3) and deeper networks (e.g., VGG, ResNet).
Removing pooling and fully connected layers: Some newer architectures (e.g., ResNet, GoogLeNet) use only convolutional layers with strides for downsampling, and global average pooling instead of FC layers.
Typical pattern: several
[Conv → ReLU]blocks (N = 2–5) followed by a pool, repeated 2–3 times, then a few FC layers, and finally softmax.
Key Takeaways
ConvNets preserve spatial structure by using local filters that slide across the image.
Each filter learns to detect a specific pattern (edge, texture, object part).
Stacking layers builds a hierarchy of features from simple to complex.
Pooling reduces spatial size and adds invariance.
The final fully connected layers combine high-level features for classification.

Ask anything
We've read this whole study set, so questions about it get the best answers.