Blame

12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
1
# 5. Convolutional networks
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
2
3
A dense layer treats an image as a flat vector, so it must learn a separate weight for every pixel and forgets that nearby pixels belong together. Convolutional networks replace that dense connectivity with a small filter that slides across the grid, reusing the same weights everywhere. This module introduces the convolution as a structured layer for grid data, then builds up stride, padding, channels, and pooling.
4
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
5
## 5.1 Why not a dense layer
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
6
7
Consider a modest $224 \times 224$ RGB image. Flattened it has $224 \times 224 \times 3 \approx 150{,}000$ inputs, so a single dense layer with even $1{,}000$ units carries about $150$ million weights. Three facts about images make almost all of them wasteful.
8
9
- **Locality**: a pixel is explained by its neighbours (an edge, a corner, a texture), not by pixels on the far side of the image.
10
- **Translation equivariance**: an edge is an edge wherever it appears, so the same detector should apply at every position. Shifting the input shifts the response by the same amount.
11
- **Parameter sharing**: because the detector is position independent, one small set of weights can be reused across the whole image instead of learning fresh weights per pixel.
12
13
A convolutional layer bakes all three in. It uses a small filter (the shared weights) applied at every location (locality and equivariance), which is why it needs orders of magnitude fewer parameters than the dense layer above.
14
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
15
![A dense layer against a convolutional layer on the same image](/en/Deep%20Learning/05%20Convolutional%20networks/a/dense-vs-conv.svg)
16
17
*The dense layer flattens the image and pays one private weight per pixel and per unit, about $150$ million in this example. The convolutional filter carries $27$ weights and one bias, and is simply reused at every position.*
18
19
The payoff in numbers, this time on a smaller $32 \times 32 \times 3$ input with a layer of $16$ filters (filter banks and channels are made precise in section 5.4, only the counting matters here):
20
21
| Layer | Weights | Biases | Total parameters |
22
| --- | --- | --- | --- |
23
| Convolution ($3\times3$, $16$ filters) | $3 \cdot 3 \cdot 3 \cdot 16 = 432$ | $16$ | $448$ |
24
| Equivalent dense layer | $(32\cdot32\cdot3)\cdot(32\cdot32\cdot16) \approx 5.0\times10^{10}$ | $16{,}384$ | $\approx 5.0\times10^{10}$ |
25
26
A few hundred parameters against about fifty billion, and the convolution generalizes better, because the same feature detector is reused everywhere rather than relearned per position.
27
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
28
*Remark:* recall the notation from the Introduction. A layer $l$ computes $z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}$ and $a^{[l]} = g^{[l]}(z^{[l]})$, with explicit bias $b^{[l]}$. A convolution is just a structured $W^{[l]}$ whose entries are tied together and mostly zero, so the same layer equation still holds.
29
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
30
## 5.2 The 2D convolution
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
31
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
32
### 5.2.1 Cross-correlation
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
33
34
Let $I$ be a 2D input (one channel of an image) and $K$ a kernel of size $k \times k$. The operation used in deep learning slides $K$ over $I$ and takes, at each position $(i, j)$, the sum of elementwise products between the kernel and the patch it covers:
35
36
$$\boxed{ (I * K)_{i,j} = \sum_{m}\sum_{n} I_{i+m,\, j+n}\, K_{m,n} }$$
37
38
Each output value is one dot product between the kernel and a local window of the input, so a small $3 \times 3$ kernel looks at nine pixels regardless of image size.
39
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
40
![Convolution sliding a kernel over the input](/en/Deep%20Learning/05%20Convolutional%20networks/a/convolution.svg)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
41
42
*A convolution slides a small kernel across the input, and each position produces one cell of the output feature map.*
43
44
*Remark:* this is technically cross-correlation. The mathematical convolution flips the kernel first, but deep learning libraries do not flip and still call it convolution, because the learned kernel simply absorbs the flip. We follow that convention throughout.
45
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
46
### 5.2.2 The layer output
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
47
48
A convolutional layer applies this operation, adds the explicit bias $b$, and passes the result through the activation $g$:
49
50
$$\boxed{ a^{[l]}_{i,j} = g\!\left( (a^{[l-1]} * K)_{i,j} + b \right) }$$
51
52
The bias is a single scalar shared across every position of the output, exactly one more instance of parameter sharing.
53
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
54
## 5.3 Stride, padding, and output size
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
55
56
Two hyperparameters control how the kernel sweeps the input.
57
58
- **Stride** $s$: the step in pixels between successive kernel positions. A larger stride skips positions and shrinks the output.
59
- **Padding** $p$: a border of $p$ zeros added around the input. It lets the kernel reach the edges and controls the output size.
60
61
For a 1D input of size $n$ (the same formula applies per axis for 2D), the output size is:
62
63
$$\boxed{ o = \left\lfloor \frac{n + 2p - k}{s} \right\rfloor + 1 }$$
64
65
*Remark:* two common choices have names. "Valid" padding uses $p = 0$, so the output shrinks by $k - 1$ at stride $1$. "Same" padding picks $p$ so that $o = n$ at stride $1$, which for an odd kernel means $p = (k - 1)/2$.
66
67
For example, with $n = 32$, $k = 5$, $p = 0$, $s = 1$ the output is $\lfloor (32 - 5)/1 \rfloor + 1 = 28$. Adding $p = 2$ ("same") gives $\lfloor (32 + 4 - 5)/1 \rfloor + 1 = 32$.
68
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
69
![Stride and padding on a six by six input with a three by three kernel](/en/Deep%20Learning/05%20Convolutional%20networks/a/stride-padding.svg)
70
71
*The same $3 \times 3$ kernel on a $6 \times 6$ input, three ways. Stride $1$ visits four positions per row, stride $2$ skips every other one, and one ring of zero padding ($p = 1$) lets the kernel cover the border so the output keeps the input size.*
72
73
## 5.4 Channels and feature maps
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
74
75
Real images have channels (three for RGB), and a kernel spans all of them. A filter for an input with $C_\text{in}$ channels has shape $k \times k \times C_\text{in}$, and its convolution sums over spatial positions and channels to produce one 2D output, called a **feature map**.
76
77
To detect many patterns a layer stacks $C_\text{out}$ such filters, so the layer has $C_\text{out}$ feature maps and its output is a volume of shape $o \times o \times C_\text{out}$. Each feature map responds to one learned pattern (an edge orientation, a colour blob, later a texture) at every position.
78
79
$$\boxed{ W^{[l]} \in \mathbb{R}^{\,k \times k \times C_\text{in} \times C_\text{out}}, \qquad b^{[l]} \in \mathbb{R}^{\,C_\text{out}} }$$
80
81
*Remark:* the output channel count $C_\text{out}$ of one layer becomes the input channel count $C_\text{in}$ of the next, so depth grows as spatial size shrinks. There is one bias per output channel, which is why $b^{[l]}$ has $C_\text{out}$ entries.
82
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
83
## 5.5 Pooling
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
84
85
Pooling downsamples a feature map by summarising each small window with a single number, using a fixed rule and no learned weights. The two common rules are the maximum and the average over each $k \times k$ window:
86
87
$$\boxed{ \text{max}: \max_{m,n} a_{i+m,\, j+n} \qquad \text{avg}: \frac{1}{k^2}\sum_{m,n} a_{i+m,\, j+n} }$$
88
89
Pooling with stride $s = k$ (non-overlapping windows) shrinks each spatial dimension by a factor of $k$, which cuts computation for later layers. It also grants small **translation invariance**: a max over a window returns the same value if the strong response shifts within that window.
90
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
91
![Max pooling over 2x2 windows](/en/Deep%20Learning/05%20Convolutional%20networks/a/pooling.svg)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
92
93
*Max pooling downsamples each region to its largest value, shrinking the feature map and adding small translation invariance.*
94
95
*Remark:* pooling has no parameters and reduces resolution, which is why modern architectures often replace it with strided convolutions instead. Convolution is equivariant to translation (the response moves with the input), whereas pooling adds a little invariance (the response ignores small moves).
96
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
97
## 5.6 A convolutional stage
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
98
99
A typical stage chains convolution, activation, and pooling, turning the raw image into a stack of feature maps that later stages refine.
100
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
101
![A convolutional stage from image to feature maps](/en/Deep%20Learning/05%20Convolutional%20networks/a/conv-pipeline.svg)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
102
103
*A convolutional stage: convolution, activation, then pooling, repeated to build feature maps.*
104
105
*Remark:* stacking such stages makes the receptive field (the input region that influences one output value) grow with depth, so early layers see edges and deep layers see whole objects, all built from the same local operation.
106
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
107
## 5.7 From layers to architectures
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
108
109
The landmark convolutional networks all share one shape: a stack of convolution and pooling stages that extracts features, then a small fully connected head that classifies them.
110
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
111
![A deep CNN as feature-map blocks feeding into fully connected layers](/en/Deep%20Learning/05%20Convolutional%20networks/a/cnn-stack.svg)
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
112
113
*A deep CNN progressively reduces spatial size while increasing channel depth, then flattens into fully connected layers.*
114
115
Each generation contributed one idea to the same question, how to stack more layers without the training signal decaying:
116
117
- **LeNet**, the original, alternates a handful of convolution and pooling stages for digit recognition.
118
- **AlexNet** scaled that skeleton to large images and GPUs, made trainable by ReLU activations and dropout.
119
- **VGG** made every convolution $3 \times 3$ and got its depth by stacking: two $3 \times 3$ layers see the same region as one $5 \times 5$ with fewer parameters ($18c^2$ against $25c^2$) and one more nonlinearity.
120
- **Inception** runs branches of several filter sizes in parallel and concatenates them, kept affordable by $1 \times 1$ convolutions, per-position channel maps that squeeze a thick feature map down before the expensive filters.
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
121
- **ResNet** lets each block learn a correction around an identity skip connection: the skip gives the gradient a backward route that never shrinks, the direct remedy to the [vanishing gradient](/en/Deep%20Learning/02%20Activation%20functions) of lesson 2, and networks of hundreds of layers train reliably.
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
122
123
| Architecture | Approx. depth | Key idea |
124
| --- | --- | --- |
125
| LeNet | 5 to 7 layers | conv and pool stack |
126
| AlexNet | 8 layers | ReLU and dropout at scale |
127
| VGG | 16 to 19 layers | stacks of $3 \times 3$ convolutions |
128
| Inception | 22 layers | parallel branches, $1 \times 1$ bottleneck |
129
| ResNet | 50 to 152 layers | residual skip connections |
130
131
*Remark:* the trend is monotonic in depth, and each jump was unlocked by a specific fix: better activations, smaller filters, channel bottlenecks, and finally skip connections.
132
133
*These deep stacks learn feature maps whose deeper activations behave as reusable representations, the entry point of the next module on embeddings and representation learning.*
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
134
135
---
12d21f lugonthier 2026-07-24 11:49:19
Remove unused SVG files and update Markdown content for clarity and accuracy in MLOps and Machine Learning modules. Adjust references to optimization techniques and activation functions, and enhance explanations in the mathematical refresher section.
136
Next: [Embeddings and representation learning](/en/Deep%20Learning/06%20Embeddings%20and%20representation%20learning) · [Course overview](/en/Deep%20Learning)