Normalization Layers

A normalization layer rescales activations so that a chosen group of them has mean zero and standard deviation one, then applies a learned scale and offset. It stabilizes and speeds up training, and it does not reduce the capacity of the network. All variants take a tensor of shape (batch, channels, height, width) and return one of the same shape. Each picks a set of entries, computes their mean and standard deviation,

standardizes them, and rescales them with a learned scale and offset for each channel:

Here is a small constant that prevents division by zero. Every variant has learned parameters per layer. The variants differ only in the set :

  • Batch normalization uses one channel across the whole batch and all positions.
  • Layer normalization uses one example across all channels and positions.
  • Group normalization uses one example and one group of channels.
  • Instance normalization uses one example and one channel, the extreme case of group normalization.
  • Ghost batch normalization is batch normalization computed on part of the batch.

The decision rule is as follows:

  • Batch normalization is the default in CNNs trained with batches of moderate or large size.
  • Layer normalization fits when batch statistics are unreliable or unavailable: in RNNs, transformers and graph networks, with very small batches, or when the batch is split across machines.
  • Group normalization fits vision models that must train with only a few images per batch.
  • Instance normalization fits when the contrast of each channel within each image should be removed, as in style transfer.

Intuition

A deep network passes its activations through many layers. Without control, their scale can grow or shrink at every layer, and the right learning rate for one layer is wrong for the next. Normalization resets each group of activations to a standard scale and lets the network learn, through and , which scale it wants. The variants answer one question differently: standardized relative to what? Batch normalization compares each example with the others in the batch, channel by channel. Layer and group normalization compare activations within one example.

This choice is the tension of the family. Batch statistics average over many values, so they are stable, and their randomness from batch to batch acts as a regularizer. They also tie each example’s output to the rest of its batch, which complicates small batches, sequences and test time. Statistics computed within one example avoid all of that. They give up the regularizing noise, and they erase whatever information was carried by the overall level of the pooled activations. In the figure each square stands for one feature map, and the shaded squares share one mean and one standard deviation.

\usepackage{tikz}
\begin{document}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=0.42cm,y=0.42cm]
\foreach \px/\name in {0/BatchNorm,8/LayerNorm,16/GroupNorm,24/InstanceNorm} {
\foreach \r in {0,...,4} {
\foreach \c in {0,...,5} {
\draw[mid] (\px+\c,-\r) rectangle (\px+\c+1,-\r-1);
}
}
\node at (\px+3,-6.2) {\small \name};
}
\foreach \r in {0,...,4} \fill[cold] (2.08,-\r-0.08) rectangle (2.92,-\r-0.92);
\foreach \c in {0,...,5} \fill[cold] (8+\c+0.08,-1.08) rectangle (8+\c+0.92,-1.92);
\foreach \c in {2,3} \fill[cold] (16+\c+0.08,-1.08) rectangle (16+\c+0.92,-1.92);
\fill[cold] (24+3.08,-1.08) rectangle (24+3.92,-1.92);
\node[left] at (-0.2,-2.5) {\small batch $N$};
\node at (3,0.8) {\small channels $C$};
\end{tikzpicture}
\end{document}

Comparison Table

VariantStatistics overDepends on batchSame at train and testRegularizing noiseTypical use
Batch normone channel, all examples and positionsyesno, frozen statistics at testyesCNNs with moderate or large batches
Ghost batch normone channel, a sub-batchyesnomore than batch normvery large batches
Layer normone example, all channels and positionsnoyesnotransformers, RNNs, small batches
Group normone example, one group of channelsnoyesnovision with few images per batch
Instance normone example, one channelnoyesnostyle transfer, per-image contrast

When to Use Which

Start with batch normalization in a convolutional network. It allows higher learning rates, and its batch noise adds regularization for free. Switch to layer normalization when the batch is a poor sample of the data or is not available. Sequence models are the main case, since their statistics would have to be stored per time step and a test sequence may be longer than any training sequence. A stacked RNN normalizes each hidden state over its own entries, so no statistic uses a future time step. Graph networks are another case. Graphs in a batch have different numbers of nodes and no shared positions. The batch therefore has no common block to average over. A GNN uses layer normalization over one graph or normalizes each node’s vector across its channels. Very small batches and training split across machines are the remaining cases. Switch to group normalization in vision models whose batches are too small for batch normalization, such as detection and segmentation models with large images. Use instance normalization when each image’s own contrast is a nuisance, as in style transfer. Ghost batch normalization is a tuning option inside batch normalization, used to restore regularizing noise when batches are very large.

Examples

(Easy) Counting Statistics

A convolutional layer produces activations of shape (batch, channels, height, width).

See Also