Search

Search papers and lessons

Batch Normalization

Sergey Ioffe, Christian Szegedy · 2015

Batch normalization standardises each layer's inputs using mini-batch statistics, which lets Ioffe and Szegedy train an ImageNet network with far fewer steps and much higher learning rates.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Neural network basics
  • Linear algebra
  • Optimizers
  • Sampling
  • Sign in to see your progress

TL;DR

Training a deep network is hard because each layer's inputs keep shifting as the layers below it change. Ioffe and Szegedy call this internal covariate shift, and they fix it by standardising each layer's inputs using the mean and variance of the current mini-batch, followed by a learned scale and shift. The result is a network that trains with much higher learning rates and far fewer steps, and in some cases it removes the need for dropout.

Where you'll see it: almost every convolutional image network built since 2015 has a batch normalisation layer after most of its convolutions, and the same idea (under other names) appears in transformers and other architectures.

The problem

Stochastic gradient descent works well for shallow models, but a deep network makes it fragile. Each layer's input is the output of every layer below it, so a small change to early weights changes the input distribution of every later layer. Each layer then has to keep chasing a moving target.

The paper frames the problem through Covariate Shift: when the input distribution changes, a learner must adapt. Within a deep net, every hidden layer experiences a mild version of this. Saturating nonlinearities make it worse. A sigmoid has a derivative near zero when its input is large, so once inputs drift into the flat regions, gradients vanish and training stalls. The usual remedies were ReLU units, careful initialisation, and small learning rates. Each one trades speed for stability. The paper asks whether the input distributions could simply be kept stable during training.

Key idea

The obvious fix is to whiten each layer's inputs, which means removing their means, scaling them to unit variance and decorrelating them. Whitening is expensive (it needs a covariance matrix and its inverse square root) and, in the paper's words, not everywhere differentiable, so the paper takes two simplifications.

First, normalise each scalar feature on its own rather than decorrelating them jointly. Second, estimate the mean and variance from each mini-batch rather than from the whole dataset. Because the statistics are computed inside the forward pass, backpropagation can differentiate through them, so the optimiser knows the normalisation is happening.

The paper also notices that plain normalisation can remove what a layer is able to represent. Pushing sigmoid inputs to have zero mean and unit variance keeps them in the nearly linear part of the sigmoid. The fix is a learned scale γ\gamma and shift β\beta after normalisation. If the network sets γ\gamma and β\beta to undo the normalisation, it recovers the original activations, so nothing is lost.

flowchart LR
  A["layer input u"] --> B["x = Wu"]
  B --> C["subtract batch mean, divide by batch std"]
  C --> D["x-hat: mean 0, variance 1"]
  D --> E["y = gamma * x-hat + beta"]
  E --> F["nonlinearity g"]

The method

The batch normalising transform

Take one activation xx (one feature, one dimension) and a mini-batch B={x1,…,xm}\mathcal{B} = \{x_1, \dots, x_m\} of size mm. The transform, Algorithm 1 in the paper, is

μB=1m∑i=1mxi,σB2=1m∑i=1m(xi−μB)2,\mu_{\mathcal{B}} = \frac{1}{m}\sum_{i=1}^{m} x_i, \qquad \sigma_{\mathcal{B}}^2 = \frac{1}{m}\sum_{i=1}^{m} (x_i - \mu_{\mathcal{B}})^2, x^i=xi−μBσB2+ϵ,yi=γ x^i+β.\widehat{x}_i = \frac{x_i - \mu_{\mathcal{B}}}{\sqrt{\sigma_{\mathcal{B}}^2 + \epsilon}}, \qquad y_i = \gamma\,\widehat{x}_i + \beta.

Here μB\mu_{\mathcal{B}} is the mini-batch mean, σB2\sigma_{\mathcal{B}}^2 the mini-batch variance, and ϵ\epsilon a small constant that prevents division by zero. The output yiy_i is what the next layer sees. Note that yiy_i depends on the other examples in the batch, through μB\mu_{\mathcal{B}} and σB2\sigma_{\mathcal{B}}^2. The learned parameters γ\gamma and β\beta are trained by gradient descent like any other weight.

Before simplification, the backward pass uses the chain rule through μB\mu_{\mathcal{B}} and σB2\sigma_{\mathcal{B}}^2:

∂ℓ∂x^i=∂ℓ∂yi γ,∂ℓ∂γ=∑i=1m∂ℓ∂yi x^i,∂ℓ∂β=∑i=1m∂ℓ∂yi.\frac{\partial \ell}{\partial \widehat{x}_i} = \frac{\partial \ell}{\partial y_i}\,\gamma, \qquad \frac{\partial \ell}{\partial \gamma} = \sum_{i=1}^{m} \frac{\partial \ell}{\partial y_i}\,\widehat{x}_i, \qquad \frac{\partial \ell}{\partial \beta} = \sum_{i=1}^{m} \frac{\partial \ell}{\partial y_i}.

The gradients with respect to xix_i must include the paths through the batch mean and variance. The paper writes them out in full. Ignoring those paths, which the authors found caused the parameters to blow up, is exactly the mistake the paper warns about.

Why the statistics are not a cheat

The normalised values have mean 0 and variance 1 within each batch, because ∑ix^i=0\sum_i \widehat{x}_i = 0 and 1m∑ix^i2=1\frac{1}{m}\sum_i \widehat{x}_i^2 = 1 (ignoring ϵ\epsilon). So each layer always sees inputs with the same first two moments during training, regardless of how the layers below have shifted. That is the stabilisation the paper is after.

Inference

At test time there is no meaningful mini-batch, and the output should depend only on the input. The paper replaces the batch statistics with population estimates. It averages the mini-batch means and uses the unbiased variance estimate mm−1 EB[σB2]\frac{m}{m-1}\,\mathbb{E}_{\mathcal{B}}[\sigma_{\mathcal{B}}^2], with the expectation taken over training mini-batches (the paper mentions moving averages as a way to track accuracy during training). With those frozen, the transform is a fixed affine map, which can be folded into the weights of the layer.

Convolutional layers

The paper applies the transform before the nonlinearity, to x=Wu\mathbf{x} = W\mathbf{u}, and drops the bias b\mathbf{b} because the mean subtraction cancels it. For convolutional layers, the normalisation should treat every spatial location of a feature map the same way. So statistics are computed over the mini-batch and over all spatial positions of each feature map, and there is one γ\gamma and β\beta per feature map. For a batch of size mm and feature maps of size p×qp \times q, each statistic is computed from m p qm\,p\,q values.

Higher learning rates and scale invariance

Batch normalisation makes the layer output insensitive to the scale of its weights. For any positive scalar aa,

BN(Wu)=BN((aW)u),\text{BN}(W\mathbf{u}) = \text{BN}((aW)\mathbf{u}),

and the paper shows that the gradient with respect to the input is unchanged, while the gradient with respect to the weights scales as 1/a1/a. Large weights therefore produce small gradients, which damps the runaway weight growth that high learning rates otherwise cause. The paper also conjectures that the layer Jacobians end up with singular values near 1, which is the condition vanishing and exploding gradients need to be avoided. This is stated as a conjecture, and the paper says its precise effect is still open.

Regularisation

Each example is normalised using the other examples in its batch, so its output is no longer a fixed function of its own input during training. This acts as noise, and the paper finds it regularises the model. In their experiments dropout could be removed or weakened.

Results

MNIST (Section 4.1). A small network with three sigmoid hidden layers of 100 units each was trained on MNIST for 50,000 steps with batch size 60. Batch normalisation made the test accuracy rise faster and end higher. The distributions of a typical sigmoid input stayed stable over training with batch normalisation and drifted in the baseline.

ImageNet (Section 4.2). The base model is a variant of Inception, a deep convolutional network with 13.6×10613.6 \times 10^6 parameters and no fully connected layers other than the softmax, trained with SGD with momentum and mini-batches of 32. Inception (initial learning rate 0.0015) reached 72.2% single-crop validation accuracy after 31×10631 \times 10^6 training steps. The variants, as the paper's text describes them:

ModelWhat changedReported result (text)
Inceptionbaseline72.2% after 31×10631 \times 10^6 steps
BN-Baselinebatch normalisation onlymatches 72.2% in less than half the steps
BN-x5BN plus the changes below, learning rate 5 times higher (0.0075)reaches 72.2% in 14 times fewer steps, about 31/14≈2.2×10631/14 \approx 2.2 \times 10^6 (derived here)
BN-x30like BN-x5, learning rate 0.045 (30 times Inception's)slower early on, then 74.8% after 6×1066 \times 10^6 steps (5 times fewer steps than Inception needs for 72.2%)
BN-x5-SigmoidBN-x5 with sigmoid instead of ReLU69.8%

The "BN-x5" changes beyond batch normalisation and the higher learning rate were: remove dropout, cut the L2L_2 weight penalty by a factor of 5, decay the learning rate 6 times faster, remove local response normalisation, shuffle examples more thoroughly within shards (about 1% validation gain), and distort images less. The same 5 times learning rate on the original Inception drove its parameters to machine infinity. Inception with sigmoid and no batch normalisation never rose above chance (1/10001/1000).

The paper's Figure 3 also tabulates steps to 72.2% and peak accuracy per network. The step counts above follow the paper's prose, and the BN-x5 figure of 2.2×1062.2 \times 10^6 is derived by division rather than quoted directly.

Ensemble (Section 4.2.3). Six networks, each based on BN-x30 with variations (larger initial weights, dropout at 5% or 10% instead of Inception's 40%, per-activation batch normalisation on the last hidden layers), averaged their class probabilities. The result was 4.9% top-5 validation error and 4.82% on the test server (the abstract rounds the test figure to 4.8%). The previous best reported by the ILSVRC server was 4.94% (He et al., 2015). The authors say it exceeded the estimated accuracy of human raters. The margin over 4.94% is small, so "best published" here is a narrow win.

The abstract's headline, "14 times fewer training steps", is the BN-x5 comparison. It is a comparison of steps to a fixed accuracy, not of wall-clock time, and it depends on the modified training recipe, not on batch normalisation alone. The introduction states the same result as "only 7% of the training steps", which is the same number seen the other way round (1/14≈7%1/14 \approx 7\%).

Why it mattered

Batch normalisation became a default component of image networks within a year or two. Residual networks, Inception variants and most efficient convolutional designs used it. It made large learning rates practical, which in turn shortened training runs and made large-batch distributed training more usable.

The mechanism was debated for years. The paper's explanation was internal covariate shift. A 2018 study by Santurkar and colleagues argued that the main benefit is a smoother optimisation landscape, not stable input distributions, and they found that batch normalisation can help even when the covariate shift is not reduced. The current view is that the effect is mostly about optimisation geometry and gradient scale, and the original explanation is at best incomplete.

Batch normalisation also created a lasting problem. Its statistics depend on the batch, which causes trouble for small batches, for recurrent networks and for models that run one example at a time. Later methods such as layer normalisation, group normalisation and RMS normalisation keep the stabilising effect while computing statistics per example, and transformer models mostly use layer normalisation for this reason.

Reading guide

Read the paper in this order and use these lessons for each part:

  1. Section 1, Introduction. Needs Stochastic Gradient Descent, Covariate Shift and Vanishing Gradient Problem. The sigmoid saturation argument depends on the derivative picture from the last one.
  2. Section 2, Towards Reducing Internal Covariate Shift. Needs Covariate Shift and Backpropagation. The bias-cancellation example is an argument about how gradient steps interact with normalisation, so the backpropagation lesson is what makes it precise.
  3. Section 3, Normalization via Mini-Batch Statistics. Needs the batch normalisation idea, Gradient Descent and Chain Rule. The backward equations in Section 3 are the chain rule applied through the batch statistics.
  4. Section 3.1, Training and Inference. Needs Stochastic Gradient Descent. The difference between batch and population statistics only matters once you know mini-batch training.
  5. Section 3.2, Convolutional Networks. Needs Convolutional Neural Network. The per-feature-map statistics are the convolutional property in action.
  6. Section 3.3, Higher Learning Rates. Needs Vanishing Gradient Problem and Chain Rule for the scale-invariance computation.
  7. Section 3.4, Regularisation. Needs Dropout for the comparison.
  8. Section 4, Experiments. The MNIST and Inception results need no extra prerequisites beyond the ones above. Skim the Inception details in the appendix only if you need the architecture.

Check yourself

QuestionWhy did the paper compute the normalisation statistics per mini-batch instead of over the whole training set?Show answer

Normalising with whole-dataset statistics would require a full pass over the data after every parameter update, which is far too expensive for stochastic training. Mini-batch statistics are cheap, and because they are computed inside the forward pass, backpropagation can differentiate through them. They also give each step a noisy estimate of the true statistics, which the paper notes can help regularise the model.

QuestionA batch of four activations is {1,3,5,7}\{1, 3, 5, 7\}. Take ϵ=0\epsilon = 0, γ=2\gamma = 2 and β=1\beta = 1. What are the outputs yiy_i?Show answer

The mean is μ=4\mu = 4 and the variance is σ2=14(9+1+1+9)=5\sigma^2 = \tfrac{1}{4}(9 + 1 + 1 + 9) = 5. The normalised values are (xi−4)/5(x_i - 4)/\sqrt{5}, which are −3/5-3/\sqrt{5}, −1/5-1/\sqrt{5}, 1/51/\sqrt{5} and 3/53/\sqrt{5}, approximately −1.342-1.342, −0.447-0.447, 0.4470.447 and 1.3421.342. Then yi=2x^i+1y_i = 2\widehat{x}_i + 1, giving approximately −1.683-1.683, 0.1060.106, 1.8941.894 and 3.6833.683. The outputs have mean 1 and variance 44, which is exactly β\beta and γ2\gamma^2.

QuestionAt test time, the population statistics from training are μ=4\mu = 4 and σ2=5\sigma^2 = 5, with γ=2\gamma = 2, β=1\beta = 1 and ϵ=0\epsilon = 0. An input of 6 arrives. What is the output, and why does the network not compute batch statistics here?Show answer

The output is y=2×(6−4)/5+1=2×0.894+1≈2.789y = 2 \times (6 - 4)/\sqrt{5} + 1 = 2 \times 0.894 + 1 \approx 2.789. The network uses the frozen population statistics because a single test example has no meaningful batch. Using a batch at test time would also make the output for one input depend on which other inputs happened to be in the batch, which the paper says is neither necessary nor desirable.

QuestionThe paper says batch normalisation makes the output insensitive to the scale of the weights. Why does that help with high learning rates?Show answer

Because BN(Wu)=BN((aW)u)\text{BN}(W\mathbf{u}) = \text{BN}((aW)\mathbf{u}) for a>0a \gt 0, the layer output does not change when the weights are scaled. The gradient with respect to the weights scales as 1/a1/a, so large weights get small updates. Without normalisation, a large learning rate tends to inflate the weights, which amplifies gradients in the next step and can make training diverge. Batch normalisation stops this feedback loop, so the learning rate can be raised without that risk.

Sources

Read the full paper

Sergey Ioffe, Christian Szegedy, 2015. arXiv:1502.03167