Quiz: initialisation, normalisation and residual connections
Before this unit: Optimisers and learning rates (previous unit); Day 36: Neural networks.
See also: Day 38: Evaluation and statistics.
Short questions on signals in deep stacks, initial weights, normalisation layers and residual connections. Try each on paper first, then open the answer.
Q1. Every layer of a 40-layer network multiplies the size of the signal by 0.8. How large is the signal at the top, for an input of size 1?
0.8^{10} \approx 0.1.
0.8^{40} \approx 0.0001. The gradient on the way back shrinks in the same way, so the first layers hardly learn.
Q2. Why do ReLU layers need initial weights \sqrt2 times larger than linear layers?
What does ReLU do to half of its inputs?
ReLU sets the negative half of its inputs to 0, which halves the mean square. Weights with variance 2/\text{fan-in} double it again, so the size stays the same from layer to layer.
Q3. Batch norm or layer norm: which one normalises each unit over the examples of the batch? Which one works for a single image at test time without stored statistics?
Rows and columns of the batch matrix.
Batch norm normalises each unit over the batch, and needs stored (running) statistics at test time. Layer norm normalises each example over its units, so it works the same way for one image.
Q4. A segmentation network with batch norm gives good results on batches of 16 test images, but nonsense when you run it on one image at a time. What is the likely cause?
Which statistics does batch norm use in training mode?
The network is still in training mode, so batch norm normalises with the statistics of the current batch. With one image (or one pixel position per unit), it removes the image’s own mean and contrast, or everything. Switch to evaluation mode, which uses the statistics stored during training.
Q5. The same network, in evaluation mode, fails on images from a new microscope that are brighter and have less contrast. Name a fix that needs no new annotations.
What do the stored statistics describe?
Re-estimate the stored batch-norm statistics on unlabelled images of the new microscope; or normalise every input image (e.g. to mean 0 and sd 1) before the network; or retrain with intensity augmentation.
Q6. A 56-layer plain network has a higher training loss than a 20-layer one. Is it overfitting?
Overfitting shows on which data?
No: overfitting means a low training loss and a high validation loss. A higher training loss is the degradation problem: the deeper plain network is harder to optimise. Residual connections fix it.
Q7. A residual block computes y = x + F(x). What must its layers learn so that the block does nothing at all? Why does that help in a very deep network?
Compare with a plain block y = F(x).
F = 0, e.g. all weights of its last layer 0: easy, and close to where small initial weights start. A plain block would have to learn the identity exactly. So extra residual blocks cannot make the network worse, and the identity path passes the gradient unchanged through all of them.
Q8. A U-Net copies encoder maps to the decoder; a ResNet adds x around each block. Which of the two brings back fine detail lost by downsampling?
Where do the two connections start and end?
The U-Net skip connection: it carries a high-resolution encoder map across to the decoder at the same resolution and concatenates it. A residual connection only spans one block, at one resolution; its job is the gradient flow and learning changes.
Q9. (math) Ten residual blocks, each with local derivative 0.2 through its layers. How much of the gradient at the top reaches the bottom? Without the residual connections?
Each residual block passes 1 + 0.2.
With residual connections 1.2^{10} \approx 6.2; without, 0.2^{10} \approx 10^{-7}.