- Introduced by
- Ioffe, S. & Szegedy, C.
- Year
- 2015
- Type
- Normalization technique (applied per mini-batch during training)
What does it do?
Batch Normalization is a training technique introduced by Sergey Ioffe and Christian Szegedy in 2015.
It normalizes the pre-activation outputs of a layer using the mean and variance computed over the current mini-batch, then applies two learnable parameters, gamma and beta, so the layer keeps its representational flexibility. The method was originally motivated by reducing internal covariate shift, but that explanation is debated.
The intuition behind the method
When training a deep network, the distribution of activations flowing into each layer keeps shifting as the earlier layers update their weights. Every layer must therefore continuously adapt to a moving target, which slows learning and can force the use of small, cautious learning rates. Batch Normalization solves this by pausing at each layer and asking: what is the mean and variance of these activations across the current mini-batch? It then re-centres and re-scales those activations to have zero mean and unit variance, before allowing two learnable parameters to restore any expressive power that might be lost. The result is that each layer sees a much steadier distribution, allowing the whole network to train faster and with greater stability.
History
Batch Normalization was introduced by Sergey Ioffe and Christian Szegedy and published at the 32nd International Conference on Machine Learning (ICML 2015); an arXiv preprint (arXiv:1502.03167) is also available. The method was reported to make deep networks train faster and more stably, and it became a common component of deep learning pipelines, particularly convolutional networks. Follow-on work produced alternatives for other settings, including Layer Normalization (Ba et al., 2016) for recurrent networks, Group Normalization (Wu & He, 2018) for small-batch settings, and Spectral Normalization for generative adversarial networks. The original explanation in terms of reduced internal covariate shift is debated.
When to use it
Batch Normalization suits feedforward and convolutional neural networks trained with stochastic gradient descent on mini-batches, and it is widely used in convolutional image models. It is normally placed between hidden layers, after a linear or convolutional transformation, rather than at the output layer. It works best when mini-batches are large enough for the batch mean and variance to be reliable estimates of the population statistics. As a rough rule of thumb, batches of roughly 16 examples or fewer make these estimates noisy, while batches of about 32 or more are often more comfortable. These figures are heuristics rather than fixed thresholds, so the effect of batch size should be checked empirically for the task and architecture. Choose a different normalisation when batches must be small, or when the architecture is recurrent with sequence lengths that vary across examples, since Batch Normalization is less effective in that setting and Layer Normalization is the usual alternative.
Limitations and considerations
- Requires reasonably large mini-batches. With small batches (as a rough rule of thumb, roughly 16 examples or fewer) the batch statistics become noisy, and the regularising noise can hurt rather than help.
- Training and inference use different statistics: batch statistics during training and running estimates at inference. This mismatch must be managed when fine-tuning, transferring or evaluating models, particularly if the running statistics were accumulated on a different data distribution.
- Not directly suited to recurrent or autoregressive architectures where sequence lengths vary across examples in a batch.
- Adds two learnable parameters per feature in each normalised layer and stores running mean and variance estimates, which slightly increases memory use.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- By keeping each layer's input distribution steadier during training, it allows larger learning rates and often faster convergence.
- The noise introduced by estimating statistics from each mini-batch acts as a mild regularising effect, which in some convolutional networks reduces the need for other regularisers such as dropout; this is not guaranteed.
- Because normalisation removes the effect of the overall scale of each layer's pre-activations, training is less sensitive to the choice of initial weight scale.
- It helps train deeper networks in which gradients would otherwise vanish or explode, by keeping activations in a controlled range.
- It adds only two learnable parameters per feature and a per-batch mean and variance calculation, so its computational cost is small relative to the convergence gains.
Applications
- Convolutional neural networks for image classification, object detection and segmentation, where it appears in many standard architectures such as ResNet, Inception and Xception.
- Generative adversarial networks, where it is used to help stabilise discriminator and generator training, although alternatives such as Spectral Normalization are also common.
- Transfer learning, where pretrained models are fine-tuned on downstream tasks; whether normalisation statistics are frozen or updated must be chosen deliberately.
- Deep feedforward networks in which vanishing or exploding gradients or slow convergence are observed.
How it works
How it works
For each mini-batch of size m, the mean of the pre-activation values is computed across all m examples independently for each feature dimension. This per-feature, per-batch mean is the reference point from which each activation is re-centred.
Formula
\mu_\mathcal{B} = \frac{1}{m}\sum_{i=1}^{m} x_iThe variance of the pre-activation values within the mini-batch is computed around the batch mean, again independently per feature dimension. Both the mean and variance are computed purely from the current mini-batch during training — no global running statistics are needed at this step.
Formula
\sigma_\mathcal{B}^2 = \frac{1}{m}\sum_{i=1}^{m}(x_i - \mu_\mathcal{B})^2Each activation is standardised by subtracting the batch mean and dividing by the batch standard deviation (with a small constant epsilon added to the denominator to avoid division by zero). The result is a zero-mean, unit-variance activation within the mini-batch.
Formula
\hat{x}_i = \frac{x_i - \mu_\mathcal{B}}{\sqrt{\sigma_\mathcal{B}^2 + \epsilon}}The normalised activation is then linearly transformed by two learnable scalar parameters — gamma (scale) and beta (shift) — both initialised to 1 and 0 respectively. These parameters are learned by backpropagation alongside the network weights, allowing the layer to recover any representation that pure normalisation would destroy. If gamma equals the original standard deviation and beta equals the original mean, the transformation is the identity, so the network can learn to undo normalisation when it is not helpful.
Formula
y_i = \gamma\,\hat{x}_i + \betaAt inference time there is no mini-batch to compute statistics from, so the running estimates of the population mean and variance accumulated during training (an exponential moving average of the batch-wise statistics) are used instead. The learned gamma and beta are then applied to the result, exactly as in the scale-shift step. Predictions therefore do not depend on which other examples happen to share a batch. Because these statistics are fixed at inference, the normalisation becomes a fixed affine transformation, which in some architectures can be folded into the weights of a preceding linear or convolutional layer; this folding is possible only when the preceding operation is linear.
Formula
y = \gamma\,\frac{x - \mathbb{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} + \betaCommon pitfalls
- Placing the layer incorrectly relative to the activation. The original paper inserts Batch Normalization before the non-linearity, normalising the pre-activation output. Placing it after the activation is a different design that changes what is normalised, so the choice should be made deliberately rather than by default.
- Using very small mini-batches and then reporting the resulting instability as a model failure, when the cause is the normalisation statistics. Increasing the batch size or switching to a batch-independent normalisation is the usual remedy.
- Forgetting to switch the network to evaluation mode before inference. The model then normalises with noisy batch statistics, so its predictions vary with the other examples in the batch.
- Applying it to the output layer, where normalising logits or regression outputs can destroy the scale and distribution that the loss function expects.
- Applying weight decay to gamma and beta without considering that it pulls the scale and shift toward zero, which can conflict with the normalisation objective.
- Computing statistics per device in distributed training. With data parallelism, batch statistics are often computed separately on each device, so the normalising batch is the per-device batch rather than the full global batch, and results can change with the number of devices. Synchronised batch normalisation, which computes statistics across all devices, is the usual remedy when the global batch size is what matters.
Frequently asked questions
Should Batch Normalization be placed before or after the activation function?
The original Ioffe & Szegedy paper places it immediately before the activation function — that is, after the linear transformation but before applying ReLU or another non-linearity. In practice, both orderings are used and the difference is often small; however, placing it before the activation is the conventional default unless a specific architecture specifies otherwise.
Why does Batch Normalization behave differently during training and inference?
During training, the mean and variance are computed from the current mini-batch, introducing a form of stochastic regularisation. At inference, using mini-batch statistics would make predictions depend on what other samples happen to be in the batch, which is undesirable. Instead, running estimates of the population mean and variance accumulated during training are used, making inference deterministic. In most frameworks this is controlled by setting the model to evaluation mode (e.g., model.eval() in PyTorch).
What is the role of the learnable parameters gamma and beta?
After normalisation to zero mean and unit variance, the layer has lost the ability to represent any other mean or scale. Gamma and beta restore this capacity: gamma scales the normalised activation and beta shifts it. Learned by backpropagation, these parameters allow the network to represent the identity transformation when normalisation is unhelpful, preserving the network's full expressive power.
When should I use Layer Normalization or Group Normalization instead?
Layer Normalization normalises across the features of each individual example, so it does not depend on batch size and is the usual choice for recurrent networks and Transformers. Group Normalization divides channels into groups and normalises within each group, which suits small mini-batches where batch statistics are unreliable. Use Batch Normalization when mini-batches are large enough for the batch statistics to be reliable and the architecture is a standard feedforward or convolutional network. As a rough rule of thumb, this means about 32 examples or more; with very small batches, such as roughly 16 examples or fewer, consider the alternatives. These batch-size figures are heuristics and should be checked for the task at hand.
Related methods
Sources
Ioffe, S. & Szegedy, C. (2015). Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift. Proceedings of the 32nd International Conference on Machine Learning (ICML), PMLR 37, 448–456.
Open publication referenceGoodfellow, I., Bengio, Y. & Courville, A. (2016). Deep Learning (Ch. 8). MIT Press.
ISBN: 978-0-262-03561-3Ioffe, S. & Szegedy, C. (2015). Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift. arXiv preprint arXiv:1502.03167.
Open publication reference2018_Book_NeuralNetworksAndDeepLearning, p. 153
[Fran_ois_Chollet_with_J.J._Allaire]_Deep_Learnin(z-lib.org), p. ? (extract without page number)