Fundamentals of Convolutional Neural Networks
Convolutional Neural Networks have become the cornerstone of modern computer vision and many other domains that involve grid‑like data. This course will walk you through the fundamental…

In a CNN architecture, what is the primary effect of increasing the stride value during convolution?
Which of the following best describes the role of padding (rembourrage) in a convolutional layer?
When stacking multiple convolutional layers, what is the main reason for doing so?
What is the main advantage of using max‑pooling over average‑pooling in a CNN?
Why is a fully connected (dense) network impractical for processing a 24‑megapixel image on a mobile device?
In the context of CNNs, what does the term 'kernel' refer to?
What is the purpose of flattening (mise à plat) the data after the final pooling layer in a CNN?
Which historical figure is credited with inventing CNNs in 1990, according to the text?
Why can't Scikit‑learn implement CNNs, as mentioned in the document?
Introduction to Convolutional Neural Networks (CNNs)
Convolutional Neural Networks have become the cornerstone of modern computer vision and many other domains that involve grid‑like data. This course will walk you through the fundamental concepts that underpin CNNs, explaining why they are efficient, how they are built, and what design choices affect their behavior. By the end of the lesson you will understand the role of kernels, padding, stride, pooling, and the transition from convolutional layers to fully‑connected classifiers.
Why Convolutional Layers Reduce Parameters
When an image is fed into a traditional fully‑connected (dense) layer, each pixel is treated as an independent input feature. For a 24‑megapixel image (≈ 24,000,000 pixels) with three color channels, a single dense neuron would require 72 million weights. Scaling this to even a modest number of neurons quickly leads to billions of parameters, which is infeasible for mobile devices.
Convolutional layers avoid this explosion by sharing the same kernel weights across all spatial locations. A kernel (also called a filter) is a small matrix—commonly 3×3 or 5×5—that slides over the image. The same set of weights is reused at every position, so the total number of learnable parameters equals kernel height × kernel width × input channels × number of filters, independent of the input size.Key take‑away:
- Weight sharing dramatically cuts the parameter count.
- Fewer parameters mean lower memory usage, faster training, and reduced risk of over‑fitting.
Understanding Stride
The stride determines how many pixels the kernel moves after each convolution operation. Increasing the stride value causes the kernel to skip positions, which reduces the spatial dimensions of the output feature map. For example, a stride of 2 on a 32×32 input reduces the output to roughly 16×16 (assuming no padding). This down‑sampling effect is useful for:
- Decreasing computational load in deeper layers.
- Increasing the receptive field of each neuron without adding extra layers.
However, a larger stride also discards fine‑grained information, so designers must balance resolution against efficiency.
The Role of Padding
Padding adds extra rows and columns of zeros (or other values) around the input before convolution. The primary purpose is to keep the output size equal to the input size when using a stride of 1, a technique often called “same” padding. Benefits include:
- Preserving edge information that would otherwise be lost.
- Enabling deeper networks without rapidly shrinking spatial dimensions.
- Facilitating the design of architectures where each layer’s output can be directly added to a later layer (as in residual connections).
Without padding, each convolution reduces the height and width by kernel size − 1, which can quickly lead to very small feature maps.
Stacking Convolutional Layers: Hierarchical Feature Learning
One of the most powerful ideas behind CNNs is the ability to learn hierarchical features. Early layers tend to detect simple patterns such as edges and textures. As we stack more convolutional layers, the network combines these low‑level cues into higher‑level concepts like shapes, object parts, and eventually whole objects.
This hierarchy mirrors the visual processing pipeline of the human brain and explains why deeper networks achieve superior accuracy on complex tasks.
- First layer: edge detectors (horizontal, vertical, diagonal).
- Middle layers: motifs, corners, and texture patterns.
- Later layers: object parts and semantic concepts.
Pooling: Max‑Pooling vs. Average‑Pooling
Pooling layers reduce the spatial size of feature maps while retaining the most important information. Max‑pooling selects the highest activation within a window, preserving the most salient feature. This has two major advantages over average‑pooling:
- It emphasizes strong responses, which often correspond to distinctive visual cues.
- It provides a form of translational invariance, as the exact location of the strongest activation becomes less critical.
Average‑pooling, by contrast, smooths activations and can dilute important signals, making it less popular for classification tasks.
Why Fully Connected Layers Are Impractical for Large Images
Returning to the earlier example of a 24‑megapixel image, a dense layer would need to learn billions of parameters. This requirement exceeds the memory capacity of most mobile devices and leads to prohibitive computational cost. Convolutional layers, with their weight‑sharing property, keep the parameter count manageable, allowing CNNs to run efficiently on limited hardware.
In practice, designers often combine the strengths of both approaches: convolutional layers extract spatial features, and a small set of fully‑connected layers at the end performs classification.
What Is a Kernel?
In the context of CNNs, a kernel (or filter) is a small matrix of learnable weights that slides over the input tensor. At each position, the kernel performs an element‑wise multiplication with the underlying patch and sums the results, producing a single value in the output feature map. Multiple kernels operate in parallel, each learning to detect a different pattern.
Typical kernel sizes are 3×3, 5×5, or 7×7. Smaller kernels are preferred because they require fewer parameters and can be stacked to achieve a larger effective receptive field while preserving non‑linearities between layers.
Flattening: Transition from Convolutional to Dense Layers
After the final pooling layer, the data is still a multi‑dimensional tensor (height × width × channels). To feed this representation into a fully‑connected classifier, we must flatten it—i.e., reshape it into a one‑dimensional vector. This operation does not alter the learned features; it simply prepares them for the dense layers that compute class scores.
Flattening is a crucial step because dense layers expect a vector input. Without it, the network would be unable to perform the final decision‑making stage.
Putting It All Together: A Typical CNN Workflow
- Input Layer: Receive raw image data (e.g., 224×224×3).
- Convolution + Padding: Apply several kernels with appropriate padding to preserve spatial dimensions.
- Activation: Use a non‑linear function such as ReLU to introduce non‑linearity.
- Pooling: Reduce spatial size with max‑pooling, gaining translational invariance.
- Repeat: Stack additional conv‑+‑pool blocks to learn deeper, more abstract features.
- Flatten: Convert the final feature map into a vector.
- Fully Connected Layers: Perform classification or regression using dense layers.
- Output Layer: Produce probabilities (via softmax) or other predictions.
Key Takeaways
- Weight sharing in convolutional layers drastically reduces the number of learnable parameters.
- Increasing stride downsamples feature maps, lowering computational cost.
- Padding preserves spatial dimensions and helps retain edge information.
- Stacking layers enables hierarchical feature learning—from edges to complex objects.
- Max‑pooling keeps the strongest activations, offering better feature preservation than average‑pooling.
- Fully connected layers are memory‑intensive for high‑resolution images; CNNs mitigate this with convolution.
- A kernel is a small, learnable matrix that slides over the input to create feature maps.
- Flattening prepares the final convolutional output for dense classification layers.
Further Reading and Resources
To deepen your understanding, explore the following resources:
- CS231n Convolutional Neural Networks – Stanford lecture notes with visual explanations.
- Very Deep Convolutional Networks for Large‑Scale Image Recognition – The VGG paper, illustrating the power of stacked small kernels.
- PyTorch CIFAR‑10 Tutorial – Hands‑on code for building a simple CNN.
By mastering these core concepts, you will be equipped to design efficient, high‑performing CNN architectures for a wide range of applications, from mobile vision to large‑scale image classification.
