3.7 Residual networks
1. Learn
Section titled “1. Learn”- Understanding Deep Learning (Prince)chapter 11 Residual networks (pp. 186–206)
- He et al., Deep Residual Learning for Image Recognitionsections 1, 3.1–3.3 and figure 2
- PyTorch: Learn the Basicsthe first task in PyTorch beyond tensors: "Build the Neural Network", then "Automatic Differentiation" and "Optimizing Model Parameters" (the next two pages)
2. Bridge
Section titled “2. Bridge”Degradation. Stack more layers onto a working network and, past some depth, the training error gets worse. That is not overfitting, which would show up only on validation data. A deeper network could always copy the shallow one and set its extra layers to the identity, so the problem is that the optimizer cannot find such a solution (He et al. 2016). With BatchNorm the gradients do not vanish; in fact, at initialisation they grow towards the input of a deep plain network (Yang et al. 2019). Training is hard because the layers’ gradients differ by orders of magnitude and change chaotically from input to input (Balduzzi et al. 2017).
Residual connections make each block learn a correction, , instead of a whole new representation. Setting to zero gives the identity, so extra depth can do no harm. Backwards, the Jacobian of each block is : the gradient has a direct path through every block, which keeps gradient sizes similar across depth, and the loss surface becomes far smoother (UDL §11.2–11.3).
Inside a block. The CIFAR ResNet uses two 3×3 convolutions, each followed by BatchNorm, with a ReLU between them and another after the addition. When a block changes the number of channels or halves the resolution, the shortcut must change shape too, and this course uses a 1×1 convolution with the same stride to project it. He et al. instead pad the extra channels with zeros (their option A, no parameters); the projection is simpler to write and adds about 2,700 parameters. Three stages of blocks with 16, 32 and 64 channels, global average pooling and one linear layer make up ResNet-20, with about 0.27 million parameters (UDL §11.5; He et al. 2016, §4.2). Since 2016 residual connections have been in nearly every deep architecture, transformers included.
3. Explore
Section titled “3. Explore”Two parts. First, build the blocks and the network in PyTorch and pass the tests locally on a CPU: block shapes, projection shortcuts, the 272,474-parameter ResNet-20, and the gradient comparison from the widget on a real 56-layer ResNet.
Residual networks: edit exercises/stubs/m3_7_resnet.py on your own machine. This task needs PyTorch, which the in-page runner does not have.
pip install torch # CPU build is enough for the tests
mlc check 3.7Then train it on a GPU. Open notebooks/3.7-resnet-cifar10.ipynb on Kaggle as in module 0.3, paste in your finished file, turn the GPU on and run everything. It plots the plain-versus-residual gradients at 56 layers, then trains ResNet-20 for 30 epochs with data augmentation, a one-cycle schedule and mixed precision. The target is above 85% test accuracy in under 30 minutes. Without a GPU the notebook runs a one-minute smoke test on random images instead.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.