title: Batch Normalization in ResNets description: PyTorch implementation showing how batch normalization enables deeper residual networks, with CIFAR-10 training experiments comparing models with and without BN.
Batch normalization (BN) is a critical ingredient of modern residual networks. In this section we:- Build a minimal ResNet block with and without batch normalization
- Train both variants on CIFAR-10 and compare convergence speed, final accuracy, and gradient health
- Visualize how BN stabilizes the distribution of intermediate activations across training
Code
Code
CIFAR-10 data loaders
We use standard CIFAR-10 normalisation (channel mean and std computed from the training set).Code
Code
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)
Code
Code
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)
Code
Code
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.Code
Code
Activation distribution across training
To see why BN helps, we capture the distribution of activations at the output oflayer1 at epochs 1, 15, and 30. Without BN the distribution drifts and widens; with BN it stays anchored near zero.
Code
Code
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
Found an error on this page? Report an issue.

