Convolutional Neural Networks
CNNs
Convolutional Neural Networks (CNNs) are the backbone of object-detection algorithms and modern image processing.
They are a specialized class of Artificial Neural Networks primarily designed to process data that has a grid-like topology, with the most famous application being image processing (two-dimensional pixel matrices).
Before the advent of CNNs, using traditional (Fully Connected) networks to read images was impractical, as they would require colossal amounts of parameters, totally ignoring spatial organization (like knowing that a neighboring pixel is related to another).
Architecture of a CNN
The essence of a CNN is built by stacking specialized layers designed to gradually extract features (spatial patterns) from the image, from the simplest edges to the most complex concepts (like eyes, wheels, or entire faces).
1. Convolutional Layers
The mathematical heart of the CNN. Instead of connecting all neurons to the entire image, small “filters” or kernel matrices (e.g., ) slide over the image performing a discrete 2D Convolution operation.
Eq. 1: 2D Convolution of an image by a kernel.
Where:
- : resulting pixel value at position of the generated feature map.
- : input image matrix (or feature map from the previous layer).
- : filter matrix (kernel) of trainable weights.
- : spatial indices iterating over the height and width of the kernel.
Each filter is trained to activate when it “sees” a specific spatial pattern, regardless of where it is in the image (Translation Invariance). Different filters generate different Feature Maps.
2. Activation Functions (Non-Linearity)
After convolution, the values pass through a non-linear function, almost always ReLU (Rectified Linear Unit).
Eq. 2: ReLU Activation Function.
Where:
- : activated output signal.
- : original scalar value generated by the convolutional step (preserved if , zeroed out otherwise).
Without this non-linearity, no matter how many layers existed, the entire network would be nothing more than a single gigantic linear regression model.
3. Pooling Layers (Subsampling)
Inserted to brutally decrease the spatial resolution (width and height) of the Feature Maps generated by the convolutions, maintaining the depth (channels). Max Pooling slides a window (e.g., ) and passes only the largest value to the next stage. This makes the network faster, more robust against micro-noise, and decreases the chance of Overfitting by forcing the throttling of spatial information, promoting Scale and Position Invariance.
4. Fully Connected Layers (FC)
At the end of the extraction operations (convolutions and poolings), the spatial volumetric feature tensor is flattened into a gigantic one-dimensional vector (Flattening) and injected into traditional densely connected neurons (MLP - Multi-Layer Perceptron). The role of these layers is to read the high-level abstract features raised by the CNN and give the final verdict (e.g., “there is a 95% chance of being a dog and a 5% chance of being a cat”).