Foundations to Frontier
Tests
E. Deep Learning › E5 Normalization Layers (one page each)

Instance Normalization

Instance normalisation standardises each channel of each example separately, over its spatial positions only. It removes per-image contrast and colour information, which is exactly what style-transfer and many image-generation networks want: AdaIN then re-imposes another image's channel statistics to transfer its style. This page covers the computation, its invariance, AdaIN, and when removing per-instance statistics helps or harms. In the exercises you verify the invariance and implement AdaIN, then show on a two-task experiment that instance normalisation gave perfect accuracy when per-example channel gains were a nuisance, and chance accuracy when channel brightness was the label.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Remove each image’s own contrast

Instance normalisation looks at one channel of one image at a time and rescales it to mean 0 and spread 1. Whatever the overall brightness and contrast of that channel in that image, they are wiped out; only the pattern within the image remains. In style transfer this is the point: the “style” of a painting lives largely in these per-channel statistics, so removing them strips the style, and putting another painting’s statistics back imposes its style.

Normalisation layers: which values share a mean and variance?
channels →ex 1ex 2ex 3ex 4ex 5ex 6
Click a cell. Highlighted cells (16 values each) are pooled to compute the mean and variance used to normalise it.
per-example mean / sd after normalising0.00/1.00 -0.00/1.00 0.00/1.00 0.00/1.00 0.00/1.00 -0.00/1.00
per-channel mean / sd after normalising0.00/1.00 0.00/1.00 0.00/1.00 0.00/1.00 -0.00/1.00 0.00/1.00 -0.00/1.00 0.00/1.00
BatchNorm noise: with batch size 6, a channel's batch mean is off from its population mean by 0.288 on average.
BatchNorm makes every channel have mean 0 and sd 1 across the batch, but each example's own statistics still vary, and its statistics depend on which other examples are in the batch: shrink N to 1 or 2 and watch the noise grow. LayerNorm, InstanceNorm and GroupNorm compute everything within one example, so they work the same at any batch size and at test time; they differ in which channels they pool.
Why engineers care

Instance normalisation (and its adaptive form AdaIN) is central to real-time style transfer, image-to-image translation and StyleGAN-type generators. The same idea, removing per-instance appearance, helps when lighting or sensor gain varies between images. The flip side matters too: if the label depends on overall brightness or colour, instance normalisation destroys it.

📝 Quick check (Level 0)
0/3 answered
  1. 1. InstanceNorm computes statistics over…
  2. 2. InstanceNorm removes…
  3. 3. AdaIN is used for…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Statistics: for x of shape (N, C, H, W), one mean and variance per (n, c), over H × W.
  • Example: a channel (1, 3) becomes (−1, 1); a constant channel (10, 10) becomes (0, 0).
  • Number of statistics: for N = 8, C = 64:
    • BatchNorm computes 64 pairs;
    • LayerNorm 8;
    • InstanceNorm 512;
    • GroupNorm with 32 groups 256.
  • Invariance: the output is unchanged if any channel of any image is scaled by a > 0 and shifted.
  • AdaIN: AdaIN(c, s) = σ(s)·(c − μ(c))/σ(c) + μ(s), per channel. Example: content value 3 with mean 1, std 2, and style mean 10, std 4: (3 − 1)/2 × 4 + 10 = 14.
📝 Quick check (Level 1)
0/3 answered
  1. 1. InstanceNorm statistics for N = 8, C = 64:
  2. 2. AdaIN of 3 (content mean 1, std 2; style mean 10, std 4):
  3. 3. IN of the constant channel (10, 10):

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

InstanceNorm in code

Exercise 1.

  • InstanceNorm’s output was unchanged when each channel of each image was given its own random gain and offset; every output channel had mean 0 and standard deviation 1.
  • AdaIN gave the content’s channels exactly the style image’s means and standard deviations.

Practice.

  • nn.InstanceNorm2d(C, affine=True) for learnable γ and β; by default PyTorch uses no affine parameters and no running statistics, so training and inference agree.
  • Use it in style-transfer and image-translation generators; in classifiers it can remove useful information.
  • It is GroupNorm with as many groups as channels.
def adain(c, s, eps=1e-5):
    cm, cs = c.mean((2, 3), keepdim=True), c.std((2, 3), keepdim=True) + eps
    return (c - cm) / cs * s.std((2, 3), keepdim=True) + s.mean((2, 3), keepdim=True)
🐍 Exercise 1: InstanceNorm and AdaIN
Implement InstanceNorm and AdaIN, check invariance to per-channel gain and offset, and check AdaIN imposes the style's channel statistics.
📝 Quick check (Level 2)
0/3 answered
  1. 1. PyTorch's InstanceNorm2d by default…
  2. 2. InstanceNorm equals GroupNorm with…
  3. 3. In classifiers, InstanceNorm can…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why it suits style transfer. Ulyanov, Vedaldi and Lempitsky (2016) found that replacing BatchNorm by InstanceNorm in fast style-transfer networks greatly improved results: each generated image’s contrast no longer depended on the others in the batch, and the network did not need to learn to undo each content image’s contrast.

Style as statistics. Gatys et al. showed that a painting’s style is captured by correlations between feature channels; Huang and Belongie (2017) showed the channel means and standard deviations alone carry much of it. AdaIN transfers those, which allows arbitrary styles in real time.

Invariance as inductive bias. InstanceNorm makes a layer exactly invariant to per-instance, per-channel affine changes. That is right when such changes are nuisance (lighting, sensor gain, colour cast) and wrong when they are signal. Exercise 2 shows both cases.

Relation to the others. BatchNorm, LayerNorm, InstanceNorm and GroupNorm differ only in which axes the statistics are pooled over. The demo above shows the pooling sets.

📝 Quick check (Level 3)
0/3 answered
  1. 1. InstanceNorm improved fast style transfer because…
  2. 2. AdaIN transfers…
  3. 3. InstanceNorm is the wrong choice when…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Nuisance or signal?

History.

  • L. Gatys, A. Ecker and M. Bethge (2016) introduced neural style transfer.
  • D. Ulyanov, A. Vedaldi and V. Lempitsky (2016) introduced instance normalisation.
  • X. Huang and S. Belongie (2017) introduced AdaIN.
  • T. Karras, S. Laine and T. Aila (2019) used AdaIN in StyleGAN.

Exercise 2. Signals with 3 channels of length 16. Each example’s channels get random gains (0.2–5) and offsets, like images under random lighting. An MLP is trained on 40 examples after one of three preprocessings: dataset-level standardisation only, LayerNorm-style (each example over all channels) or InstanceNorm-style (each channel of each example). Mean test accuracy over three seeds:

task none over all channels per channel
label = ramp direction in channel 0 (per-channel gains and offsets) 0.904 0.947 1.000
label = whether channel 0 is brighter than channel 1 (shared gain) 0.787 0.999 0.488
  • When per-channel gains were a nuisance, instance normalisation removed them and gave perfect accuracy from 40 examples.
  • When channel brightness was the label, instance normalisation erased it: chance accuracy.
  • Normalising over all channels kept the comparison between channels and was perfect on the second task.
  • Lesson: a normalisation layer is an assumption about which variations do not matter. Choose it to match the task.
🐍 Exercise 2 (research): nuisance or signal?
Train on two tasks with random per-example lighting, using no per-example normalisation, normalisation over all channels and per-channel (instance) normalisation.

InstanceNorm in AI, robotics and aerospace

  • Image translation for simulation-to-real transfer: style-transfer networks with InstanceNorm make simulated images look real, or the reverse.
  • Varying illumination: per-instance normalisation helps vision under changing lighting, such as orbital imagery across sun angles.
  • But not for every task: where colour or brightness carries meaning (fire, smoke, thermal intensity), keep that information.

References

  1. D. Ulyanov, A. Vedaldi, V. Lempitsky (2016). “Instance normalization: the missing ingredient for fast stylization.” arXiv:1607.08022.
  2. X. Huang, S. Belongie (2017). “Arbitrary style transfer in real-time with adaptive instance normalization.” Proc. ICCV.
  3. L. A. Gatys, A. S. Ecker, M. Bethge (2016). “Image style transfer using convolutional neural networks.” Proc. CVPR.
  4. T. Karras, S. Laine, T. Aila (2019). “A style-based generator architecture for generative adversarial networks.” Proc. CVPR.