Search

Search papers and lessons

Group Normalization

Level 4 · 12 min read

Group normalization standardises the channels of one example in small fixed groups, so its statistics do not depend on the batch and it works even when a batch holds only one or two images.

On this page

  • Colour = topic mix
  • Discrete math
  • Neural network basics
  • Calculus
  • Linear algebra
  • Probability
  • Optimizers
  • ReadReady to readNot yet

TL;DR

A convolutional network stores its activations as a stack of channels, each a grid of values. Group normalization splits those channels into a few fixed groups and standardises each group, for one example at a time, to mean 0 and variance 1, then applies a learned scale and shift. Because it never looks at other examples in the batch, it works when the batch is tiny.

Builds on: Batch Normalization, Layer Normalization, Mean and Variance · Leads to: the Group Normalization paper

Where it's used

Object detection and segmentation. Detectors such as Mask R-CNN process high-resolution images, so a single GPU can hold only one or two images per step. Batch normalization estimates its statistics from that tiny batch, and the estimates become noisy. Group normalization was proposed partly for this setting and keeps accuracy on COCO when the batch is small.

Video and 3D models. A video clip or a volumetric scan produces many more activations per example than a single photograph. Memory limits force small batches, which is the same problem as detection, and the same fix applies.

Models trained one example at a time. Some systems update a network on each sample as it arrives, or on a shard of data split across machines. Batch statistics are then either unavailable or change with the partition. Group normalization gives the same output for an example no matter which other examples share its step, so training and inference behave the same way.

How it works

Take a tiny feature map: one image, four channels, and each channel a row of two values. Write the values as they sit in memory.

  • Channel 1: [1,3][1, 3]
  • Channel 2: [5,7][5, 7]
  • Channel 3: [0,4][0, 4]
  • Channel 4: [2,6][2, 6]

Use G=2G = 2 groups, so channels 1 and 2 form group A and channels 3 and 4 form group B.

  1. Collect the group. For group A, gather every value in channels 1 and 2: {1,3,5,7}\{1, 3, 5, 7\}. Check: four values, two channels times two positions each.
  2. Compute the mean of the group. (1+3+5+7)/4=4(1 + 3 + 5 + 7) / 4 = 4. Check: the mean lies between the smallest and largest value.
  3. Compute the variance of the group. The squared distances from 4 are 9,1,1,99, 1, 1, 9, and their average is 55. Check: the standard deviation is 5≈2.236\sqrt{5} \approx 2.236.
  4. Standardise each value in the group. The value 11 becomes (1−4)/2.236≈−1.342(1 - 4) / 2.236 \approx -1.342, and 77 becomes (7−4)/2.236≈1.342(7 - 4) / 2.236 \approx 1.342. Check: the four results average to 0.
  5. Repeat for group B. Its values {0,4,2,6}\{0, 4, 2, 6\} have mean 3 and variance 5, so the same arithmetic gives −1.342,0.447,−0.447,1.342-1.342, 0.447, -0.447, 1.342.
  6. Apply the learned scale and shift to each channel. With scale 1 and shift 0, nothing changes further. In a real network the scale and shift are trained, one pair per channel.
flowchart LR
    A[Feature map: C channels, one example] --> B[Split the C channels into G groups]
    B --> C[For each group: mean and variance over its channels and positions]
    C --> D[Standardise every value in the group]
    D --> E[Learned scale and shift per channel]
    E --> F[Normalised feature map, same shape as input]

The key property is in step 1. The statistics come only from one example's group. Put a different image beside this one in the batch and the output for this image does not change.

The math

Let an input for one example be a tensor xx with CC channels and spatial positions indexed by (h,w)(h, w). Split the channels into GG groups of C/GC / G channels each. Assume CC is divisible by GG.

Definition: Group normalization

For example nn, group gg, let Sn,gS_{n,g} be the set of all values xn,c,h,wx_{n,c,h,w} where channel cc belongs to group gg and (h,w)(h, w) ranges over all positions. Then

μn,g=1∣Sn,g∣∑(c,h,w)∈Sn,gxn,c,h,w,σn,g2=1∣Sn,g∣∑(c,h,w)∈Sn,g(xn,c,h,w−μn,g)2,\mu_{n,g} = \frac{1}{|S_{n,g}|} \sum_{(c,h,w) \in S_{n,g}} x_{n,c,h,w}, \qquad \sigma^2_{n,g} = \frac{1}{|S_{n,g}|} \sum_{(c,h,w) \in S_{n,g}} \left(x_{n,c,h,w} - \mu_{n,g}\right)^2,

and the normalised value is x^n,c,h,w=(xn,c,h,w−μn,g)/σn,g2+ϵ\hat{x}_{n,c,h,w} = (x_{n,c,h,w} - \mu_{n,g}) / \sqrt{\sigma^2_{n,g} + \epsilon}, where ϵ\epsilon is a tiny constant that prevents division by zero. The output is yn,c,h,w=γcx^n,c,h,w+βcy_{n,c,h,w} = \gamma_c \hat{x}_{n,c,h,w} + \beta_c, with one learned scale γc\gamma_c and one shift βc\beta_c per channel.

The size of each group is ∣Sn,g∣=(C/G)⋅H⋅W|S_{n,g}| = (C / G) \cdot H \cdot W, where HH and WW are the height and width of the feature map.

Step 1 in symbols: collect the group

Group A corresponds to g=1g = 1 with channels c∈{1,2}c \in \{1, 2\}. The set S1,1S_{1,1} contains the four values x1,1,1,1=1x_{1,1,1,1} = 1, x1,1,1,2=3x_{1,1,1,2} = 3, x1,2,1,1=5x_{1,2,1,1} = 5 and x1,2,1,2=7x_{1,2,1,2} = 7. Its size is (4/2)⋅1⋅2=4(4/2) \cdot 1 \cdot 2 = 4.

Step 2 and 3 in symbols: mean and variance

μ1,1=1+3+5+74=4,σ1,12=(1−4)2+(3−4)2+(5−4)2+(7−4)24=9+1+1+94=5.\mu_{1,1} = \frac{1 + 3 + 5 + 7}{4} = 4, \qquad \sigma^2_{1,1} = \frac{(1-4)^2 + (3-4)^2 + (5-4)^2 + (7-4)^2}{4} = \frac{9 + 1 + 1 + 9}{4} = 5.

Step 4 in symbols: standardise

With ϵ\epsilon set to 0 for hand computation,

x^1,1,1,1=1−45≈−1.342,x^1,2,1,2=7−45≈1.342.\hat{x}_{1,1,1,1} = \frac{1 - 4}{\sqrt{5}} \approx -1.342, \qquad \hat{x}_{1,2,1,2} = \frac{7 - 4}{\sqrt{5}} \approx 1.342.

Each group has mean 0 and variance 1 after this step, which is what the definition guarantees.

Step 6 in symbols: scale and shift

For γc=1\gamma_c = 1 and βc=0\beta_c = 0, y=x^y = \hat{x}. In training, γc\gamma_c and βc\beta_c are updated by gradient descent, so the network can undo the normalisation where it does not help.

Special cases

Two familiar methods are special cases of this definition:

  • G=1G = 1 puts all channels in one group. Each example is then normalised over its entire feature map, which is layer normalization.
  • G=CG = C puts each channel in its own group. Each channel of each example is normalised over its own spatial grid, which is instance normalization.

Group normalization interpolates between these two by choosing GG between 1 and CC. The paper uses G=32G = 32 as its default.

Why batch statistics are absent

Batch normalization computes μ\mu and σ2\sigma^2 over the set {(n,h,w)}\{(n, h, w)\} for each channel, so it averages across examples. Group normalization averages over (c,h,w)(c, h, w) within one example nn. The expression for μn,g\mu_{n,g} has no sum over nn, which is why its value for example nn is fixed by that example alone.

Worked examples

Example
1. Tiny: two groups of two channels

A single example with four channels and one value per channel, so H=W=1H = W = 1. The values are x=[1,3,10,14]x = [1, 3, 10, 14] for channels 1 to 4. Use G=2G = 2, so groups are {1,2}\{1, 2\} and {3,4}\{3, 4\}. Take ϵ=0\epsilon = 0 and γ=1\gamma = 1, β=0\beta = 0.

  1. Group 1 holds the values 11 and 33. Their mean is 22.
  2. Their squared distances from 2 are 11 and 11, so the variance is 11.
  3. Normalise: (1−2)/1=−1(1 - 2)/1 = -1 and (3−2)/1=1(3 - 2)/1 = 1.
  4. Group 2 holds 1010 and 1414. Their mean is 1212.
  5. Their squared distances from 12 are 44 and 44, so the variance is 44 and the standard deviation is 22.
  6. Normalise: (10−12)/2=−1(10 - 12)/2 = -1 and (14−12)/2=1(14 - 12)/2 = 1.
  7. The output is [−1,1,−1,1][-1, 1, -1, 1].

Interpretation: the two groups had very different scales (values near 2 and values near 12), and after normalisation both look the same. The network now sees each group on the same footing.

Example
2. Standard: four channels, two positions each

One example with four channels and two spatial positions, so H=1H = 1 and W=2W = 2. Values: channel 1 is [1,3][1, 3], channel 2 is [5,7][5, 7], channel 3 is [0,4][0, 4], channel 4 is [2,6][2, 6]. Use G=2G = 2.

  1. Group A is channels 1 and 2, which holds {1,3,5,7}\{1, 3, 5, 7\}. Its size is (4/2)⋅1⋅2=4(4/2) \cdot 1 \cdot 2 = 4.
  2. The mean is (1+3+5+7)/4=4(1 + 3 + 5 + 7)/4 = 4.
  3. The variance is (9+1+1+9)/4=5(9 + 1 + 1 + 9)/4 = 5, so the standard deviation is 5≈2.236\sqrt{5} \approx 2.236.
  4. Normalise the four values: 1→−1.3421 \to -1.342, 3→−0.4473 \to -0.447, 5→0.4475 \to 0.447, 7→1.3427 \to 1.342.
  5. Group B is channels 3 and 4, which holds {0,4,2,6}\{0, 4, 2, 6\}. Its mean is 33 and its variance is (9+1+1+9)/4=5(9 + 1 + 1 + 9)/4 = 5.
  6. Normalise: 0→−1.3420 \to -1.342, 4→0.4474 \to 0.447, 2→−0.4472 \to -0.447, 6→1.3426 \to 1.342.
  7. Check: in group A the four normalised values sum to −1.342−0.447+0.447+1.342=0-1.342 - 0.447 + 0.447 + 1.342 = 0, as required.

Interpretation: each output value says how far it sits from the mean of its own group, measured in that group's spread. Group A and group B have the same spread here, so their outputs look alike even though their raw values differ.

Example
3. Realistic: a detector with two images per GPU

A detector's backbone produces a feature map with C=256C = 256 channels, H=W=56H = W = 56, and G=32G = 32 groups. Each step processes a batch of N=2N = 2 images on one GPU.

  1. Group size: each group has 256/32=8256 / 32 = 8 channels. The spatial grid has 56⋅56=313656 \cdot 56 = 3136 positions. So each group holds 8⋅3136=25,0888 \cdot 3136 = 25{,}088 values for one image.
  2. Batch normalization would compute each channel's statistics from N⋅H⋅W=2⋅3136=6272N \cdot H \cdot W = 2 \cdot 3136 = 6272 values. Those values come from only two images, so the estimate changes whenever the second image changes.
  3. Group normalization computes its statistics from 25,08825{,}088 values belonging to one image. Those values do not depend on the second image at all.
  4. Consequence: if you swap the image beside a given photo, its group-normalized activations stay identical, while its batch-normalized activations shift.

Try it: a feature map has C=64C = 64 channels, H=W=28H = W = 28, and G=8G = 8 groups. How many values are in one group for one image? Answer: each group has 64/8=864 / 8 = 8 channels and 28⋅28=78428 \cdot 28 = 784 positions, so 8⋅784=62728 \cdot 784 = 6272 values.

Common mistakes and tradeoffs

Mistake: group normalization is always more accurate. It is tempting to think a method that avoids batch statistics must win. In fact, when the batch is large and well-tuned, as in standard ImageNet classification, batch normalization is typically as accurate or slightly better. Group normalization's advantage appears when the batch is small, which is exactly where batch statistics become unreliable.

Mistake: the groups are chosen from the data. It is tempting to think the channels are clustered by similarity. In fact the groups are fixed blocks of consecutive channels, set before training. The method never looks at the values when forming them.

Mistake: it averages across the batch. It is tempting to think any normalisation must use other examples. In fact the statistics come only from one example's group, so its output needs no running averages at inference time. The same formula runs in training and in testing.

Mistake: GG can be any number. CC must be divisible by GG. A common default of 32 works for widths like 64, 128 and 256 but not for every layer width. Choosing GG too small makes groups large and close to layer normalization, while too large makes them close to instance normalization, which removes useful channel-wise information.

When to use it. Use group normalization when the batch is small, when the model processes high-resolution inputs, or when you need the same behaviour at training and inference. When not to use it. When the batch is large and batch normalization is already tuned, it remains a strong default. For sequence models such as transformers, Layer Normalization is the usual choice, because the feature dimension is the natural unit.

History

Batch normalization was introduced by Ioffe and Szegedy in 2015. It worked very well for large-batch image classification and quickly became standard, but its dependence on batch statistics caused trouble wherever batches were small. Ba, Kiros and Hinton proposed layer normalization in 2016 for recurrent networks, where batch statistics across time steps were awkward. Ulyanov, Vedaldi and Lempitsky proposed instance normalization in 2016 for image stylisation, where each image's own contrast and brightness should be removed. Yuxin Wu and Kaiming He proposed group normalization in 2018 as a single method that covers the space between layer and instance normalization, and showed that it matches batch normalization on large batches and is more stable on small ones. It caught on because detection and segmentation pipelines kept hitting the small-batch problem.

Recap

  • Group normalization splits channels into GG fixed groups and standardises each group within one example.
  • Its statistics come only from that example, so the output does not depend on the batch.
  • G=1G = 1 gives layer normalization; G=CG = C gives instance normalization.
  • It shines with small batches, as in detection, segmentation and video, and it behaves the same at training and inference.
  • Read next: the Group Normalization paper, which runs the experiments that compare it with batch normalization.

Check yourself

QuestionIn group normalization, over which values is the mean for one group of one example computed?Show answer
Over every value in that group's channels and all spatial positions, for that one example only. Other examples in the batch are not used.
QuestionA feature map has C=12C = 12 channels and G=3G = 3 groups. How many channels are in each group, and how many channels does each group normalise over for a single example if the spatial grid is 5×55 \times 5?Show answer
Each group has 12/3=412 / 3 = 4 channels. Each group contains 4⋅5⋅5=1004 \cdot 5 \cdot 5 = 100 values per example, and those 100 values are the set the mean and variance are computed over.
QuestionWhy does batch normalization become unreliable with batch size 2, while group normalization does not?Show answer
Batch normalization estimates each channel's mean and variance from the examples in the batch, so with two examples the estimate depends heavily on which two images were drawn. Group normalization computes its statistics within one example's group, so the batch size does not change its values.
QuestionApplied: a model uses group normalization with G=CG = C. Explain, in words, what each channel of each image is normalised against, and which known method this is.Show answer
Each channel of each image is normalised against the values of that same channel across its own spatial positions. Nothing is shared with other channels or other images. This is instance normalization.

Sources