Skip to main content
Open In Colab Batch normalization (BN) is a critical ingredient of modern residual networks. In this section we:
  1. Build a minimal ResNet block with and without batch normalization
  2. Train both variants on CIFAR-10 and compare convergence speed, final accuracy, and gradient health
  3. Visualize how BN stabilizes the distribution of intermediate activations across training
The canonical ResNet block from He et al. (2016) is: y=f(x)+x,f(x)=W2ReLU(BN(W1x))y = f(x) + x, \quad f(x) = W_2 * \text{ReLU}(\text{BN}(W_1 * x)) where * denotes convolution and BN\text{BN} normalizes the pre-activation tensor to have zero mean and unit variance, then scales and shifts with learnable γ\gamma and β\beta: x^=xμBσB2+ϵ,y=γx^+β\hat x = \frac{x - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}, \quad y = \gamma \hat x + \beta

CIFAR-10 data loaders

We use standard CIFAR-10 normalisation (channel mean and std computed from the training set).

ResNet building blocks

We implement two variants of the basic residual block:
  • ResBlock, with batch normalization (use_bn=True, default)
  • ResBlock, without batch normalization (use_bn=False)
The skip connection uses a 1×11\times 1 convolution when the spatial dimensions or channel count change (the projection shortcut).

Training loop

We train both variants for the same number of epochs with the same SGD + cosine-annealing schedule and compare:
  • Training loss and test accuracy per epoch
  • Gradient norms at the stem layer (a proxy for gradient health)

Results: training loss, test accuracy, and gradient norms

The three plots below summarise the effect of batch normalisation on a residual network trained on CIFAR-10.
Training loss, test accuracy, and stem gradient norms for ResNets with and without batch normalization on CIFAR-10

Activation distribution across training

To see why BN helps, we capture the distribution of activations at the output of layer1 at epochs 1, 15, and 30. Without BN the distribution drifts and widens; with BN it stays anchored near zero.
Layer 1 activation distributions at epochs 1, 15, and 30 for ResNets with and without batch normalization

Summary

These results confirm why every modern ResNet variant (ResNet-50, ResNeXt, Wide-ResNet) applies batch normalization after each convolution before the non-linearity.

PyTorch reference