Convolutional Neural Networks
In this section of the course, weโll learn about some of the most famous neural network architectures. These paved the way to modern-day AI.
This Lesson Will Cover
- ๐๏ธ The fundamental architecture of Convolutional Neural Networks (CNNs)
- ๐ผ๏ธ How CNNs process image data through convolution and pooling operations
- ๐ Key historical developments in CNN architectures
- ๐งฎ Practical examples of CNN computations
- ๐ Modern applications and relevance of CNNs
Introduction to CNNs
CNNs (Convolutional Neural Networks) are designed for processing structured grid-like data, like images.
- Introduced in the late 1980s by Yann LeCun with LeNet architecture
- LeNet-5 was designed for handwritten digit recognition and pioneered the use of convolutional layers
- It had a simple architecture of two convolutional layers followed by three fully connected layers
- CNNs had a landmark success in 2012 with AlexNet
- Created by Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton
- Achieved groundbreaking performance in the ImageNet competition
- AlexNet was much deeper than LeNet, with five convolutional layers and three fully connected layers
- It used ReLU activation functions and dropout regularization to prevent overfitting
CNNs are great for computer vision tasks, like identifying objects in an image, e.g. recognizing faces, or detecting medical anomalies in scans.
They are the backbone of modern visual data processing.
Why CNNs Work for Images
Images are fundamentally two-dimensional data structures composed of pixels.
Each pixel has numerical values representing intensity and color channels.
For example, an RGB image with transparency (e.g., PNG) would be composed of four such 2D grids of pixel intensitiesโone for each color channel and one for the opacity channel.
A CNN processes these pixel grids by applying mathematical operations called convolutions.
As we look at how these work, consider their benefits for image recognition tasks:
- Spatial Hierarchy: Convolutions allow the network to capture patterns like edges, textures, and complex shapes across layers.
- Parameter Efficiency: Instead of learning a separate weight for every pixel, CNNs learn small filter kernels that are shared across the image.
How CNNs Work
At a high level, a CNN consists of three main building blocks:
-
Convolutional Layers:
-
These layers slide filters (or kernels) across the image to create feature maps.
Input Image: [1, 2, 0, 1] [0, 1, 3, 1] [1, 0, 2, 0] [2, 1, 0, 3] Kernel: [1, 0, -1] [0, 1, -1] [1, -1, 0]The convolution operation slides this kernel across the image, applying element-wise multiplication and summing up the results. With a 4x4 input image and a 3x3 kernel, the output feature map would be 2x2 in size.
-
-
Pooling Layers:
- These layers reduce the spatial size of feature maps to make computations more efficient and to focus on dominant features.
-
Fully Connected Layers:
- After extracting features, these layers map them to the final output, such as classification labels.
Simple Example with Data
- Convolutional Layer
Imagine we have a grayscale image:
We apply a filter:
After convolution (8x8 output):
We arrived at this result by:
- Sliding the Filter: The filter was slid across the input image, computing a dot product at each valid position.
- Summation: For each position, the element-wise products of the filter and corresponding image region were summed to get a scalar result.
- Reduction in Size: The output size is due to the convolution over the original image without padding.
For example, consider the top-left region of the input:
The convolution is computed as:
This value () is placed in the top-left corner of the output.
- Pooling Layer
Letโs continue working through this example to demonstrate how pooling works.
Taking the feature map above and applying 2x2 max pooling:
- Fully Connected Layer
Finally, letโs consider how we could map this pooling layer into classification probabilities, using a fully-connected layer with the following parameters:
We first flatten the pooled output into a 16-element vector:
And then calculate the logits , , and by performing the dot product of the flattened vector with the weights for each class, then adding the respective biases:
Class 1 ():
Class 2 ():
Class 3 ():
Passing these logits through a softmax activation:
- Compute exponentials:
- Compute the sum of exponentials:
- Compute probabilities:
We arrive at our final output, representing the predicted probabilities of each classification label for our image:
Relevance of CNNs Today
CNNs remain highly relevant, especially for image processing tasks.
Advanced architectures such as ResNet, Inception, and EfficientNet have further refined their accuracy and computational efficiency, making them benchmarks in many applications.
Recently, Transformer models (e.g., Vision Transformers) have demonstrated significant success in computer vision tasks:
- Transformers excel at capturing global dependencies in data
- CNNs, on the other hand, with their convolutional operations, are optimized for learning localized patterns
Many state-of-the-art models now combine CNNs and Transformers, leveraging CNNs for efficient local feature extraction and Transformers for capturing global contextual relationships.
Conclusion
If you want to go deeper on CNNs and treat yourself to an enjoyable 10 minutes of learning, I recommend watching the Futurology โCNN Visualizedโ YouTube video[1].
Key Takeaways
๐ผ๏ธ CNNs are specialized neural networks designed for processing grid-like data, particularly images.
๐ Key components include convolutional layers, pooling layers, and fully connected layers.
๐๏ธ Convolutional layers use filters to detect features like edges, textures, and shapes.
๐ Pooling layers reduce spatial dimensions and help focus on dominant features.
๐๏ธ CNNs achieve parameter efficiency through weight sharing across the image.
๐๏ธ Landmark architectures include LeNet (1980s) and AlexNet (2012).
๐ Modern applications combine CNNs with Transformers for both local and global feature detection.
๐ฏ CNNs remain fundamental to computer vision tasks like object detection and image classification.
Next: Recurrent Neural Networks (RNNs)
Like CNNs revolutionized image processing, RNNs (Recurrent Neural Networks) revolutionized sequential data processing.
As weโll see, they can be used to extract semantic meaning from text, where each wordโs meaning depends on the words that came before it.
Footnotes
Futurology - Convolutional Neural Networks Explained (CNN Visualized) YouTube video โฉ๏ธ
Comments (0)
No comments yet.