Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Learn the correction, not the whole answer
Researchers expected deeper networks to be at least as good as shallow ones: the extra layers could just copy their input. In practice, plain networks deeper than about 20 layers trained worse. ResNet’s fix: give every pair of layers a shortcut that adds their input to their output. The layers then only need to learn a correction to the input, and “do nothing” is easy (learn zero). With shortcuts, networks of 152 layers trained well and beat everything before them.
| stage | output C × H × W | parameters | multiply–adds |
|---|---|---|---|
| stem | 64 × 56 × 56 | 9.5 k | 118.01 M |
| stage2 | 256 × 56 × 56 | 215.8 k | 667.94 M |
| stage3 | 512 × 28 × 28 | 1.22 M | 1.03 G |
| stage4 | 1024 × 14 × 14 | 7.10 M | 1.46 G |
| stage5 | 2048 × 7 × 7 | 14.96 M | 809.24 M |
| head | 1000 × 1 × 1 | 2.05 M | 2.05 M |
| VGG-16 | 138.36 M parameters | 15.47 G MACs |
| ResNet-18 | 11.69 M parameters | 1.81 G MACs |
| ResNet-50 | 25.56 M parameters | 4.09 G MACs |
| ResNet-101 | 44.55 M parameters | 7.80 G MACs |
ResNet-18 and ResNet-50 are the default backbones for detection, segmentation and tracking on robots, cars, drones and satellites, and residual connections are in every transformer.
- 1. A residual block outputs…
- 2. Plain networks beyond ~20 layers…
- 3. 'Do nothing' for a residual block means…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Basic block: y = ReLU(x + BN(W₂ ReLU(BN(W₁ x)))), with two 3 × 3 convolutions. With 64 channels it has 2·(9·64² + 2·64) = 73,984 parameters including BatchNorm.
- Bottleneck block: 1 × 1 down to C/4, then 3 × 3, then 1 × 1 back up to C. For C = 256 it has 70,400 parameters, against about 1.18 million for two 3 × 3 convolutions at 256 channels.
- Projection shortcut: when the stride or channel count changes, the shortcut is a 1 × 1 convolution (with stride), y = W_s x + F(x).
- Depths: stem + 2 or 3 layers per block + classifier.
- ResNet-18 has 2, 2, 2, 2 basic blocks and ResNet-34 has 3, 4, 6, 3.
- ResNet-50 has 3, 4, 6, 3 bottleneck blocks; ResNet-101 has 3, 4, 23, 3; ResNet-152 has 3, 8, 36, 3.
- Gradient:
- through L blocks with shortcuts, ∂y/∂x = Π(1 + ∂F_l/∂x), which is near 1 when the corrections are small;
- without shortcuts it is Π ∂f_l/∂x, which for local derivatives of 0.5 over 10 layers gives 0.5¹⁰ ≈ 0.001.
- 1. ResNet-50 uses which block?
- 2. Depth formula for ResNet-50:
- 3. A projection shortcut is used when…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.ResNet in code
Exercise 1.
- With its second weight at zero, a basic block passed non-negative inputs through unchanged.
- A projection shortcut matched the new width.
- The bottleneck counts were 75,008 (64 → 256, with projection) and 70,400 (256 → 256).
- The depth formula gave 18, 34, 50, 101 and 152.
Practice.
- The standard ImageNet recipe:
- SGD with momentum 0.9 and weight decay 10⁻⁴, batch 256;
- learning rate 0.1, divided by 10 at plateaus (about epochs 30 and 60);
- no dropout.
- Initialising each block’s last BatchNorm scale γ to zero (“zero-γ”) makes every block start as the identity and helps large-batch training (Goyal et al., 2017).
- torchvision’s ResNet-50 v1.5 puts the stride-2 in the 3 × 3 convolution rather than the first 1 × 1. That is slightly more accurate and slightly more costly.
class Basic(nn.Module):
def __init__(self, c):
super().__init__(); self.f = nn.Sequential(nn.Conv2d(c, c, 3, 1, 1, bias=False), nn.BatchNorm2d(c), nn.ReLU(),
nn.Conv2d(c, c, 3, 1, 1, bias=False), nn.BatchNorm2d(c))
nn.init.zeros_(self.f[-1].weight) # zero-gamma: the block starts as the identity
def forward(self, x): return torch.relu(x + self.f(x))- 1. Zero-γ initialisation makes each block start as…
- 2. ResNet's ImageNet learning rate starts at…
- 3. ResNet-50 v1.5 puts stride 2 in…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
The degradation problem. On ImageNet, a plain 34-layer network had higher training error than a plain 18-layer network, although the deeper network contains the shallower one (set the extra layers to the identity). The problem is optimisation, not overfitting. With BatchNorm the gradients did not vanish, so the authors attributed it to slow, difficult convergence of deep plain stacks.
Why residuals help.
- Easy identity: the zero function is easy to learn, and near-identity mappings are a good starting point.
- Gradient highway: with y = x + F(x), ∂L/∂x = ∂L/∂y·(1 + ∂F/∂x), so every block passes at least the incoming gradient back.
- Ensemble view: Veit et al. (2016) showed ResNets behave like ensembles of many shallower paths; deleting a single block barely hurts.
- Smoother loss surface: Li et al. (2018) showed shortcuts make the loss landscape much less chaotic.
Limits.
- On CIFAR-10 a 1,202-layer ResNet trained but overfitted: 7.93% test error against 6.43% for 110 layers.
- Later work (pre-activation, E8-9; wide networks, E8-10) refined block design.
- 1. Degradation is a problem of…
- 2. With shortcuts, ∂L/∂x contains…
- 3. Veit et al. view ResNets as…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Can we reproduce the degradation problem?
History.
- K. He, X. Zhang, S. Ren and J. Sun (2016) introduced ResNet. It won ILSVRC 2015 classification (3.57% top-5 with an ensemble), detection and localisation, and the COCO 2015 detection and segmentation tasks.
- R. Srivastava, K. Greff and J. Schmidhuber (2015) proposed highway networks, with gated shortcuts.
- Residual connections became central to transformers (A. Vaswani et al., 2017).
Exercise 2. The data are three-class 2-D spirals, 300 points. The networks are 16 units wide with 4, 16 or 40 hidden layers, in two forms:
- plain;
- residual, in blocks of two layers whose second layer starts at zero.
Each is trained with full-batch Adam (learning rate 0.01) for 300 steps. Final training loss, where chance is log 3 = 1.099:
| hidden layers | plain (seeds 0, 1) | residual (seeds 0, 1) |
|---|---|---|
| 4 | 0.071, 0.014 | 0.016, 0.006 |
| 16 | 0.055, 0.050 | 0.004, 0.027 |
| 40 | 1.093, 1.097 | 0.198, 0.011 |
- Degradation reproduced. The 40-layer plain network never left chance-level loss, although the 4-layer network fits the data easily and the deep network could in principle copy it. Seed 2 gave the same result (1.097).
- Shortcuts fixed it. The 40-layer residual network trained, though seed 0 was slower than the shallow network.
- The learning rate matters. At learning rate 0.003 the plain 40-layer network did train (losses 0.29, 0.08, 0.29), but it stayed worse than the 4-layer plain network (0.08, 0.03, 0.03). The residual networks improved with depth (40 layers: 0.000, 0.014, 0.025). Degradation is a matter of how hard and fragile optimisation becomes, not a hard wall.
ResNet in AI, robotics and aerospace
- Backbones: Faster R-CNN, Mask R-CNN, RetinaNet and DeepLab (E9, E10) commonly use ResNet-50/101 backbones, including for satellite and aerial detection.
- Robot learning: ResNet-18 encoders are standard in visuomotor policies and visual odometry.
- Beyond vision: residual connections are used in speech, language, physics surrogates and reinforcement-learning networks.
References
- K. He, X. Zhang, S. Ren, J. Sun (2016). “Deep residual learning for image recognition.” Proc. CVPR.
- R. K. Srivastava, K. Greff, J. Schmidhuber (2015). “Training very deep networks.” Advances in NeurIPS.
- A. Veit, M. Wilber, S. Belongie (2016). “Residual networks behave like ensembles of relatively shallow networks.” Advances in NeurIPS.
- H. Li, Z. Xu, G. Taylor, C. Studer, T. Goldstein (2018). “Visualizing the loss landscape of neural nets.” Advances in NeurIPS.
- P. Goyal et al. (2017). “Accurate, large minibatch SGD: training ImageNet in 1 hour.” arXiv:1706.02677.