1. Motivation¶
Fully connected neural networks for images have two key issues:
Lose spatial structure: Flattening an image into a vector destroys the 2D spatial relationships between pixels.
Too many parameters: For a image, a single fully connected layer to 1000 neurons has million weights.
CNNs preserve spatial structure and use weight sharing to dramatically reduce parameters.
2. Convolutional Layer¶
Core Operation¶
A convolutional layer applies a set of learnable filters (kernels) to the input. Each filter slides spatially over the input and computes dot products.
For a filter of size applied to an input of size :
At each spatial location, compute: (a dot product over the patch).
The result is a single number in the output activation map.
Hyperparameters¶
A convolutional layer has 4 hyperparameters:
| Hyperparameter | Symbol | Description |
|---|---|---|
| Number of filters | How many different filters to learn | |
| Filter size | Spatial size of each filter (e.g., , ) | |
| Stride | Step size when sliding the filter | |
| Zero padding | Number of pixels to pad around the border |
Output Size Formula¶
Given input :
The output volume is .
Common settings:
, , (preserves spatial size)
, , (preserves spatial size)
, , chosen to fit
, ,
Number of Parameters¶
Each filter has weights plus 1 bias. With filters:
Example: Input , filters of size , stride 1, pad 2.
Output size:
Parameters per filter:
Total parameters:
Intuition¶
Each filter learns to detect a specific pattern:
Early layers: edges, blobs, colors
Deeper layers: textures, shapes, object parts
When a patch of the image matches the filter pattern, the dot product yields a large value.
3. Pooling Layer¶
Pooling reduces spatial dimensions, making representations smaller and more manageable.
Max Pooling¶
For each region (typical), output the maximum value.
Operates independently on each activation map.
No learnable parameters.
Introduces translation invariance.
Common setup: filters with stride 2, which halves the spatial dimensions.
4. Fully Connected Layer¶
After several convolutional and pooling layers, the final feature maps are flattened and fed into one or more fully connected layers.
Connects every neuron to all activations in the previous layer.
The final layer’s size and activation depend on the task (e.g., softmax for classification).
5. Typical CNN Architecture¶
A CNN is typically a sequence of:
Key properties:
Hierarchical feature learning: Early layers extract low-level features; deeper layers combine them into high-level patterns.
Parameter efficiency: Convolution layers share weights spatially, drastically reducing parameters compared to fully connected networks.
Translation equivariance: Shifting the input shifts the output correspondingly (before pooling).
6. Classic Architectures (Overview)¶
| Network | Year | Key Innovation |
|---|---|---|
| LeNet | 1998 | First successful CNN for digit recognition |
| AlexNet | 2012 | Reinvigorated deep learning with GPU training, ReLU, dropout |
| VGGNet | 2014 | Showed that depth matters; used small filters exclusively |
| ResNet | 2015 | Introduced skip connections to enable very deep networks |