Blame
|
1 | # 11. CNN architectures |
||||||
| 2 | ||||||||
| 3 | The layers and operations of the previous module compose into full networks, and a handful of landmark architectures shaped how those pieces are assembled. This module surveys LeNet, AlexNet, VGG, Inception, and ResNet, extracting the one idea each contributed. The through-line is a search for depth: how to stack more layers without the training signal decaying, which ties directly back to the vanishing-gradient problem of lesson 7. |
|||||||
| 4 | ||||||||
| 5 | **Objectives** |
|||||||
| 6 | - Trace the progression from the early convolutional stacks of LeNet and AlexNet. |
|||||||
| 7 | - Explain why VGG replaced large filters with deep stacks of small $3 \times 3$ convolutions. |
|||||||
| 8 | - Read an Inception module as parallel branches and understand the $1 \times 1$ convolution as a channel bottleneck. |
|||||||
| 9 | - Write the residual block $y = F(x, W) + x$ and connect the skip connection to gradient flow. |
|||||||
| 10 | - Compare the five architectures by depth, key idea, and contribution. |
|||||||
| 11 | ||||||||
| 12 | All of these architectures share the same overall shape: a stack of convolution and pooling layers that extract features, followed by a small fully connected head that classifies them. |
|||||||
| 13 | ||||||||
| 14 |  |
|||||||
| 15 | ||||||||
| 16 | *A deep CNN progressively reduces spatial size while increasing channel depth, then flattens into fully connected layers.* |
|||||||
| 17 | ||||||||
| 18 | ## 11.1 Early convolutional stacks |
|||||||
| 19 | ||||||||
| 20 | ### 11.1.1 LeNet |
|||||||
| 21 | ||||||||
| 22 | LeNet is the original convolutional network, built for handwritten-digit recognition. It alternates convolution and pooling layers to extract features, then finishes with fully connected layers for classification. A layer $l$ still computes $z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}$ followed by $a^{[l]} = g^{[l]}(z^{[l]})$, but $W^{[l]}$ is now a bank of small shared filters rather than a dense matrix. The activation $g^{[l]}$ was a saturating sigmoid or $\tanh$, and the whole network was only a handful of layers deep. |
|||||||
| 23 | ||||||||
| 24 | ### 11.1.2 AlexNet |
|||||||
| 25 | ||||||||
| 26 | AlexNet kept the convolution-then-pool skeleton but scaled it to large natural images and trained it on GPUs. Two ideas from this course made deep training practical at that scale. First, the ReLU activation |
|||||||
| 27 | ||||||||
| 28 | $$\boxed{\ g(z) = \max(0, z)\ }$$ |
|||||||
| 29 | ||||||||
| 30 | replaced the saturating sigmoid, so the gradient is $1$ wherever $z > 0$ and does not vanish for large positive inputs. Second, dropout randomly zeroes a fraction $p$ of activations during training, which regularizes the large fully connected layers: |
|||||||
| 31 | ||||||||
| 32 | $$\boxed{\ a^{[l]} \leftarrow \frac{1}{1-p}\, m \odot a^{[l]}, \quad m_j \sim \text{Bernoulli}(1-p)\ }$$ |
|||||||
| 33 | ||||||||
| 34 | *Remark:* the mask $m$ is applied elementwise with the Hadamard product $\odot$, and the $1/(1-p)$ factor keeps the expected activation unchanged so that no rescaling is needed at test time. |
|||||||
| 35 | ||||||||
| 36 | ## 11.2 VGG: depth from small filters |
|||||||
| 37 | ||||||||
| 38 | VGG made one design choice and pushed it hard: every convolution is $3 \times 3$, and depth comes from stacking many of them. Two stacked $3 \times 3$ convolutions see the same input region as one $5 \times 5$ convolution, and three stacked see the same region as one $7 \times 7$. The stack is cheaper and more expressive, because it inserts a nonlinearity between each layer while using fewer parameters. |
|||||||
| 39 | ||||||||
| 40 | For a filter of side $k$ mapping $c_{\text{in}}$ input channels to $c_{\text{out}}$ output channels, the weight count is |
|||||||
| 41 | ||||||||
| 42 | $$\boxed{\ \#\text{params} = k^2 \cdot c_{\text{in}} \cdot c_{\text{out}} \ }$$ |
|||||||
| 43 | ||||||||
| 44 | so with $c_{\text{in}} = c_{\text{out}} = c$ a single $5 \times 5$ layer costs $25 c^2$ weights, while two $3 \times 3$ layers cost $2 \cdot 9 c^2 = 18 c^2$. The deeper stack is both smaller and adds an extra ReLU. |
|||||||
| 45 | ||||||||
| 46 | *Remark:* the regular structure is what made VGG a favourite backbone. The trade is cost, because its wide fully connected head holds most of the parameters. |
|||||||
| 47 | ||||||||
| 48 | ## 11.3 Inception: parallel branches and the 1x1 convolution |
|||||||
| 49 | ||||||||
| 50 | Instead of choosing a single filter size, an Inception module (GoogLeNet) runs several in parallel and concatenates their outputs along the channel axis. One branch is $1 \times 1$, one is $3 \times 3$, one is $5 \times 5$, and one is a pooling branch, so the network learns which scale matters at each stage rather than fixing it by hand. |
|||||||
| 51 | ||||||||
| 52 | The key trick is the $1 \times 1$ convolution. It has no spatial extent, so it does not mix neighbouring pixels. Instead it acts as a per-position linear map across channels, computing at each spatial location $(i, j)$ |
|||||||
| 53 | ||||||||
| 54 | $$\boxed{\ y_{ij} = W\, a_{ij} + b, \quad W \in \mathbb{R}^{c_{\text{out}} \times c_{\text{in}}}\ }$$ |
|||||||
| 55 | ||||||||
| 56 | Choosing $c_{\text{out}} < c_{\text{in}}$ makes it a channel bottleneck: it projects a thick feature map down to fewer channels before an expensive $3 \times 3$ or $5 \times 5$ convolution, cutting the cost of that convolution sharply. This is why Inception can be both wide and affordable. |
|||||||
| 57 | ||||||||
| 58 | *Remark:* a $1 \times 1$ convolution followed by a ReLU is exactly a small fully connected network applied identically at every spatial position, sharing one weight matrix $W$ across the whole feature map. |
|||||||
| 59 | ||||||||
| 60 | ## 11.4 ResNet: residual connections |
|||||||
| 61 | ||||||||
| 62 | ### 11.4.1 The residual block |
|||||||
| 63 | ||||||||
| 64 | Very deep plain stacks train worse than shallow ones, not because they overfit but because the signal degrades. ResNet fixes this by having each block learn a residual and adding the input back through a skip connection: |
|||||||
| 65 | ||||||||
| 66 | $$\boxed{\ y = F(x, W) + x\ }$$ |
|||||||
| 67 | ||||||||
| 68 | Here $F$ is a short stack of convolutions with weights $W$, and the term $+x$ is the identity skip. If the optimal map for a block is close to the identity, the network only has to drive $F$ toward zero, which is far easier than learning the identity from scratch through several nonlinear layers. |
|||||||
| 69 | ||||||||
| 70 |  |
|||||||
| 71 | ||||||||
| 72 | *A residual block adds an identity skip connection around the convolution path, so the layer only has to learn a correction F(x).* |
|||||||
| 73 | ||||||||
| 74 | ### 11.4.2 Why gradients flow |
|||||||
| 75 | ||||||||
| 76 | Differentiating the block, the skip contributes an identity term to the Jacobian: |
|||||||
| 77 | ||||||||
| 78 | $$\boxed{\ \frac{\partial y}{\partial x} = \frac{\partial F}{\partial x} + I\ }$$ |
|||||||
| 79 | ||||||||
| 80 | During backpropagation the upstream gradient is multiplied by this factor at every block. The $+I$ term gives the gradient a direct route backward that never shrinks, so even when the $\partial F / \partial x$ contributions are small the product across many blocks does not collapse toward zero. This is the direct remedy to the vanishing-gradient problem from lesson 7, where repeated multiplication by small Jacobians in a plain deep stack drives early-layer gradients to nothing. With skip connections, networks of hundreds of layers train reliably. |
|||||||
| 81 | ||||||||
| 82 | *Remark:* when $F$ changes the number of channels or the spatial size, the skip uses a $1 \times 1$ convolution to match shapes so the sum $F(x, W) + x$ is well defined. |
|||||||
| 83 | ||||||||
| 84 | ## 11.5 Comparison |
|||||||
| 85 | ||||||||
| 86 | | Architecture | Approx. depth | Key idea | Contribution | |
|||||||
| 87 | | --- | --- | --- | --- | |
|||||||
| 88 | | LeNet | 5 to 7 layers | conv and pool stack | first working CNN for digits | |
|||||||
| 89 | | AlexNet | 8 layers | ReLU and dropout at scale | deep CNNs on large images and GPUs | |
|||||||
| 90 | | VGG | 16 to 19 layers | stacks of $3 \times 3$ convolutions | depth from uniform small filters | |
|||||||
| 91 | | Inception | 22 layers | multi-branch modules, $1 \times 1$ bottleneck | width and efficiency together | |
|||||||
| 92 | | ResNet | 50 to 152 layers | residual block $y = F(x, W) + x$ | trains very deep networks | |
|||||||
| 93 | ||||||||
| 94 | *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. |
|||||||
| 95 | ||||||||
| 96 | *These architectures learn hierarchical feature maps whose deeper activations behave as reusable representations, which is the entry point to the next module on embeddings and representation learning.* |
|||||||
| 97 | ||||||||
| 98 | --- |
|||||||
| 99 | Next: [Embeddings and representation learning](/en/Deep%20Learning/12%20Embeddings%20and%20representation%20learning) · [Course overview](/en/Deep%20Learning) |
|||||||
