Convolutional Neural Networks
Convolutional Neural Networks (CNNs) are specialized neural architectures designed to process grid-structured data, such as images, by exploiting spatial hierarchies.
Convolutional Layers
Unlike fully connected layers where neurons connect to all inputs, convolutional layers connect only to a local receptive field.
Filters and Feature Maps
A layer applies learnable filters (kernels). As a filter slides, it computes dot products, producing a feature map.
Output Dimension Formula
Given input height , filter size , padding , and stride , the output height is:
- Padding (): Adding zero-pixels around the border to preserve spatial dimensions.
- Stride (): The step size of the filter as it slides across the input.
Translation Invariance
CNNs build translation invariance: if a pattern (like a cat’s ear) is learned in one part of the image, the convolutional filters can recognize it anywhere else. This parameter sharing significantly reduces model parameter counts compared to MLPs.
Pooling Layers
Pooling layers reduce the spatial size of feature maps to decrease parameter counts and build translation invariance.
- Max Pooling: Extracts the maximum value from each receptive patch.
- Average Pooling: Computes the average value of each patch.
ResNet and Residual Connections
Deep CNNs suffer from vanishing gradients. ResNet resolves this using Residual Connections (skip connections) that bypass layers:
This allows gradients to flow directly backward, enabling the training of deep networks.
Example: Output Shapes
The following example calculates the output dimensions of a convolutional layer:
Interactive Lab
Calculate the output dimensions of a Convolutional Layer based on input dimension, filter size, padding, and stride. Edit these parameters to see how layer sizes transition.
Exercise
Test your understanding of CNN operations:
What is the primary purpose of pooling layers in a CNN?
Receptive Fields and Hierarchies
Early layers detect simple edges, while deeper layers combine these features to recognize complex shapes and objects, building a hierarchical spatial representation.