Instance normalization

Also known as: InstanceNorm

On this page 8

Instance normalization (InstanceNorm) is a normalization layer that standardizes each channel of each individual sample using the mean and variance computed only over that channel’s spatial positions. In neural networks, it is best known as the layer that made fast neural style transfer practical, because it strips away the per-image contrast and color statistics that encode visual style.

Unlike batch normalization, the statistics never mix information across samples in a mini-batch, so the layer behaves identically during training and inference and works with a batch size of one. That property makes it a standard component in image generation, style transfer and image-to-image translation models.

How instance normalization computes its statistics

Instance normalization computes a separate mean and variance for every (sample, channel) pair over the height and width of the feature map. For an input tensor of shape N x C x H x W, the layer produces N times C pairs of statistics, each estimated from H times W values.

Each activation is then shifted by its channel mean, divided by the square root of the variance plus a small epsilon such as 1e-5, and optionally rescaled by a learnable scale (gamma) and shift (beta) per channel. The affine parameters let the network restore whatever scale it needs after the statistics have been removed.

The following table summarizes the parts of the computation and what each one controls.

ComponentComputed overRole
MeanH x W of one channel in one sampleRemoves the average brightness of that feature
VarianceH x W of one channel in one sampleRemoves the contrast of that feature
EpsilonFixed constant, typically 1e-5Prevents division by zero on flat maps
Gamma and betaLearned per channelRestore a useful output scale
Running statisticsOptional, often disabledUsed only if tracking is switched on
Components of the instance normalization operation

Why instance normalization removes style

Instance normalization works as contrast normalization at the feature level. Research on neural style transfer showed that the channel-wise means and variances of convolutional feature maps capture much of an image’s style, including palette, texture strength and overall contrast, while the spatial arrangement carries the content.

By erasing those statistics for every image independently, the layer makes the generator’s output less dependent on the contrast of the content image. This insight led directly to adaptive instance normalization (AdaIN), which replaces the learned gamma and beta with the mean and standard deviation of a style image, allowing arbitrary style transfer in a single forward pass.

The same mechanism explains why the layer can hurt tasks where absolute intensity carries meaning. A classifier that must distinguish a dark scene from a bright one loses part of that signal, which is one reason image classification networks rarely use it.

Instance normalization compared with other normalization layers

The normalization family differs mainly in which axes the statistics are pooled over. Group normalization contains instance normalization as the special case with one channel per group, and layer normalization as the case with a single group.

LayerStatistics pooled overDepends on batchTypical use
Batch normalizationN, H, W per channelYesImage classification CNNs
Layer normalizationC, H, W per sampleNoTransformers and RNNs
Instance normalizationH, W per sample and channelNoStyle transfer, GAN generators
Group normalizationChannel groups, H, W per sampleNoDetection with small batches
RMSNormFeatures per token, no meanNoLarge language models
Axes used by common normalization layers

Because instance normalization pools over the fewest values, its statistics are the noisiest estimates in the family when feature maps are small. On a 4 x 4 map, each mean comes from only 16 numbers, which makes the output sensitive to individual activations.

Where instance normalization is used

Instance normalization is the default choice in many image-to-image generators, where each output must be produced from one input without interference from other samples. The table below lists common settings and the reason the layer suits them.

ApplicationWhy instance normalization fitsCommon variant
Feed-forward style transferRemoves content-image contrastPlain InstanceNorm
Arbitrary style transferSwaps statistics between imagesAdaIN
Unpaired image translationPer-image output, batch size oneInstanceNorm in a ResNet generator
Style-based face generationInjects style at every resolutionAdaIN, later weight demodulation
Medical image segmentationScanner intensity varies per volume3D InstanceNorm in U-Net
Typical applications and the reason for choosing the layer

In 3D medical segmentation, volumetric U-Net variants often prefer instance normalization because GPU memory limits the batch to one or two volumes, where batch statistics would be unreliable. The per-volume normalization also reduces the effect of intensity differences between scanners.

Configuring instance normalization in practice

Most deep learning frameworks expose instance normalization with two important switches: whether the affine parameters are learned and whether running statistics are tracked. In PyTorch, the InstanceNorm2d layer sets affine=False and track_running_stats=False by default, which differs from the defaults of BatchNorm2d.

  • Enable learnable affine parameters unless a later layer, such as AdaIN, supplies its own scale and shift.
  • Leave running statistics switched off in most generators, so inference uses the statistics of the actual input.
  • Place the layer after a convolution and before the activation, the usual order in convolutional blocks.
  • Avoid it on the last layers at very low resolution, where few spatial positions remain.

Limitations and common mistakes

The main weakness of instance normalization is that it discards information that some tasks need. The table lists the problems practitioners meet most often and how they are usually addressed.

SymptomLikely causeTypical fix
Droplet or blob artifactsGenerator hides signal from normalizationUse weight demodulation instead
Lower classification accuracyUseful contrast information removedUse batch or group normalization
Unstable outputs at small mapsToo few values per statisticRemove the layer at low resolution
Train and test mismatchRunning statistics enabled by mistakeDisable tracking or recompute
Frequent problems and their fixes

A known example of the first problem appeared in early style-based generators, where the network learned to create a strong local spike that dominated the statistics and let it pass magnitude information through the normalization. Replacing the explicit normalization with weight demodulation removed those artifacts.

In simple terms

Imagine adjusting every photo so that it has the same average brightness and the same contrast. The shapes in each photo stay the same. Only the overall look is evened out. Instance normalization does this inside a neural network, separately for every image and every feature.

This matters because the look of an image is partly its style. Once the network removes that look, it can paint a new style on top. It also treats each image alone, so it does not need many images at once to work well.

A practical example

A small team builds a mobile filter that turns phone photos into images that resemble a chosen painting. They train a feed-forward convolutional generator with residual blocks on a set of landscape photos, using one painting as the style target. The first version uses batch normalization with a batch of eight images.

On a phone, the app processes one photo at a time, and the results look washed out for dark night scenes and oversaturated for bright beach shots. The team replaces every batch normalization layer with instance normalization with learnable affine parameters and retrains with the same data and loss.

The new model produces consistent stylization across very dark and very bright photos, because each input is normalized by its own statistics. Inference behaves exactly as in training, so the team no longer needs to maintain running averages, and the visible brightness artifacts disappear from user reports.