Foundation reference

Batch Normalization

Batch normalization subtracts each feature's mean and divides by its standard deviation, both computed over the current mini-batch during training, then applies a learned scale and shift. It made deep convolutional networks much faster to train: an Inception image classifier reached the same accuracy in 14 times fewer training steps (Ioffe & Szegedy, 2015), and ResNets apply it after every convolution (He et al., 2016).

Concept 61 of 100Core TrainingStudy phase 3
Key equation
x^=x−μBσB2+ϵ\hat{x} = \frac{x - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}
Reading map and next steps

Study guide

Where to start

Concept 61 of 100Batch NormalizationCore Training · Study phase 3: Optimization & generalization
Question

Ioffe & Szegedy motivated batch normalization as a cure for "internal covariate shift"; why did Santurkar et al. (2018) conclude that it helps mainly by making the loss and its gradients smoother instead?

How to study this pagePredict · Check · Generalize · Continue
PredictSay what you expect.

Before you move a control in the demo, say what you expect to change.

CheckCheck against the math and the papers.

Compare what the demo shows with the key equation and with the papers cited below.

GeneralizeName what stays the same.

Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.

ContinueFollow the connections.

Use the prerequisites and related concepts at the end of the page to fill the next gap.

Why It Matters for Modern Models

  • Batch normalization subtracts each feature's mean and divides by its standard deviation, both computed over the current mini-batch during training, then applies a learned scale and shift. It made deep convolutional networks much faster to train: an Inception image classifier reached the same accuracy in 14 times fewer training steps (Ioffe & Szegedy, 2015), and ResNets apply it after every convolution (He et al., 2016).
  • It allows much higher learning rates and makes training less sensitive to initialization (Ioffe & Szegedy, 2015).
  • The switch from batch statistics during training to running averages at test time is a common source of bugs, for example when a model is evaluated in training mode or when the test data differ from the training data.

Questions to Think About

  • Because each example is normalized with its batch-mates' statistics, its output and gradient depend on which other examples share the batch; what problems can that cause?
  • Why does the error of batch-normalized networks rise quickly as the batch gets small (Wu & He, 2018), and why do transformers use layer normalization, which needs no batch statistics, instead?

Interactive Demo

Core Math

If you prefer intuition first, try the demo above, then come back for the math.

Key Equation
x^=x−μBσB2+ϵ\hat{x} = \frac{x - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}

Batch normalization normalizes each feature with the mean and variance over the mm examples in the current mini-batch. For a convolutional channel, the statistics also include all spatial positions, so mm below counts batch elements times spatial positions:

x^i=xi−μBσB2+ϵ\hat{x}_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}}

where μB=1m∑i=1mxi\mu_B = \frac{1}{m}\sum_{i=1}^m x_i and σB2=1m∑i=1m(xi−μB)2\sigma_B^2 = \frac{1}{m}\sum_{i=1}^m (x_i - \mu_B)^2.

Learned parameters then scale and shift the result, so the layer can still produce whatever mean and variance the next layer needs:

yi=γ x^i+βy_i = \gamma\, \hat{x}_i + \beta

At inference there may be no batch, so the layer uses running averages of μB\mu_B and σB2\sigma_B^2 collected during training. The network therefore computes a slightly different function at training and test time.

Key Papers and Books

Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift

Ioffe & Szegedy2015ICML
Read paper →

How Does Batch Normalization Help Optimization?

Santurkar et al.2018NeurIPS
Read paper →

Group Normalization

Wu & He2018ECCV
Read paper →

Deep Learning, Section 8.7.1: Batch Normalization

Goodfellow, Bengio & Courville2016MIT Press (textbook)
View book →

Connections

Prerequisites