Deep LearningNormalization
How do group normalization and instance normalization differ in convolutional neural networks?
Question 305 of 314 · Updated
On this page
- 1. Instance normalization (IN)
- 2. Group normalization (GN)
- 3. The core difference with a numerical shape example
- 4. Side-by-side comparison
- 5. An important equivalence: GroupNorm can become InstanceNorm
- 6. Why do their use cases differ?
- When instance normalization is useful
- When group normalization is useful
- 7. PyTorch implementation
- InstanceNorm2d
- GroupNorm
- Verify the equivalence in PyTorch
- 8. Production example: high-resolution medical image segmentation
- 9. Common mistakes
- 10. Decision guide
Instance normalization computes statistics separately for every sample and channel. Group normalization computes statistics for groups of channels within each sample. Both avoid dependence on other examples in the mini-batch, but they normalize different sets of activations and therefore preserve different information.
This lesson extends Deep Learning Questions 186 (instance normalization) and 187 (group normalization). Question 190 already covers when group normalization is preferable to batch normalization; this comparison focuses on the difference between group-wise and per-channel normalization.
1. Instance normalization (IN)#
For a convolutional feature map with shape , instance normalization calculates the mean and variance separately for each sample and each channel, across its spatial dimensions.
For sample and channel :
It normalizes that channel:
If affine transformation is enabled, learnable per-channel scale and bias are applied afterward.
Intuition: each image channel is normalized independently. One image's statistics do not affect another image, and one channel's statistics do not get mixed with another channel's statistics.
Instance normalization became popular in image stylization because normalizing each image independently can reduce the influence of its instance-specific contrast and appearance statistics.
2. Group normalization (GN)#
Group normalization also operates independently for each sample, but it divides the channels into groups.
Suppose a convolution produces channels and you choose groups. Each group contains:
For each sample and group, GN calculates mean and variance across the group's channels and their spatial dimensions. It then normalizes all activations in that group.
For group , containing channels:
The normalized values are then scaled and shifted, typically using learnable per-channel parameters.
Intuition: instead of normalizing every channel separately, GN normalizes a small collection of channels together. The statistics are still computed independently for each image.
3. The core difference with a numerical shape example#
Imagine a CNN produces a feature tensor:
That means:
- Batch size: 2 images
- Channels: 8
- Height: 4
- Width: 4
Instance normalization
- Each image has 8 channels.
- Each channel is normalized separately.
- Each set of statistics uses values.
- There are 2 × 8 = 16 independent normalization-statistic sets.
Group normalization with 4 groups
- Each image still has 8 channels.
- The 8 channels are split into 4 groups.
- Each group contains 2 channels.
- Each set of statistics uses values.
- There are 2 × 4 = 8 independent normalization-statistic sets.
The distinction is the normalization region: IN uses one channel at a time; GN uses multiple channels together.
4. Side-by-side comparison#
| Dimension | Instance normalization | Group normalization |
|---|---|---|
| Statistics calculated over | Spatial positions within each channel | Channels within a group and spatial positions |
| Scope | One sample, one channel | One sample, one channel group |
| Dependence on batch size | No dependence on other samples | No dependence on other samples |
| Channel grouping | Every channel is its own group | Configurable number of channel groups |
| Running statistics | Not used by default; can be enabled in PyTorch | Not used |
| Affine parameters | Optional in PyTorch | Enabled by default in PyTorch |
| Common applications | Style transfer and image generation | CNNs for detection, segmentation, and small-batch training |
| Main trade-off | Removes per-instance channel statistics | Shares statistics across channels in each group |
Neither method uses statistics from other images in the batch. This is why both can work when GPU memory forces training with very small batches.
5. An important equivalence: GroupNorm can become InstanceNorm#
A useful fact in PyTorch is that group normalization with one channel per group is equivalent to instance normalization, assuming matching settings.
If the number of groups equals the number of channels:
then each group contains exactly one channel. GN therefore computes statistics across the spatial dimensions of that channel, just like IN.
For example:
- 8 channels with 8 groups: each group has 1 channel — equivalent to instance normalization under matching affine and epsilon settings.
- 8 channels with 4 groups: each group has 2 channels — genuine group normalization.
- 8 channels with 1 group: all 8 channels are normalized together — similar to layer normalization over channels and spatial dimensions for this tensor layout.
This is not just a conceptual analogy. PyTorch's GroupNorm documentation explicitly shows the configuration where the number of groups equals the number of channels as equivalent to InstanceNorm.
Implementation caveat: PyTorch defaults are not identical. GroupNorm enables affine parameters by default, while InstanceNorm2d disables them by default. To reproduce equivalent behavior, align affine settings, epsilon, and running-statistics configuration.
6. Why do their use cases differ?#
When instance normalization is useful#
Choose IN when per-image appearance statistics should be normalized independently.
Typical use cases:
- Neural style transfer.
- Image-to-image translation.
- Some image-generation architectures.
- Tasks where contrast or style variation should have less influence on intermediate feature representations.
The benefit is that each channel is normalized using that image's own statistics. This can make stylization less sensitive to the original image's contrast.
The trade-off is important: per-instance mean and variance may contain useful information. Removing those statistics can hurt tasks where absolute intensity, contrast, or channel-specific appearance is meaningful.
When group normalization is useful#
Choose GN when you want batch-independent normalization but do not want to normalize every channel separately.
Typical use cases:
- Object detection with high-resolution images.
- Image segmentation with small training batches.
- Video models where each example consumes substantial GPU memory.
- CNN training where batch size changes across hardware or experiments.
GN shares statistics across channels inside each group. The number of groups controls how broad that normalization region is.
The Group Normalization paper showed that GN remains stable across a wide range of batch sizes and can be effective in detection and segmentation settings where batch sizes are constrained by memory.
7. PyTorch implementation#
Both modules accept convolutional feature maps shaped .
InstanceNorm2d#
PYTHONimport torch.nn as nn channels = 64 instance_norm = nn.InstanceNorm2d( num_features=channels, eps=1e-5, affine=True, track_running_stats=False ) features = instance_norm(features)
With affine enabled, the layer learns a scale and bias for each channel. By default, InstanceNorm2d uses instance statistics during both training and evaluation. Setting running-statistics tracking to true changes evaluation behavior.
GroupNorm#
PYTHONimport torch.nn as nn channels = 64 groups = 8 group_norm = nn.GroupNorm( num_groups=groups, num_channels=channels, eps=1e-5, affine=True ) features = group_norm(features)
Here, each group contains:
The number of channels must be divisible by the number of groups. GroupNorm uses statistics from the current sample in both training and evaluation; it does not maintain batch running averages.
Verify the equivalence in PyTorch#
PYTHONimport torch import torch.nn as nn x = torch.randn(2, 8, 16, 16) # Match affine and epsilon settings. gn = nn.GroupNorm( num_groups=8, num_channels=8, eps=1e-5, affine=True ) inn = nn.InstanceNorm2d( num_features=8, eps=1e-5, affine=True, track_running_stats=False ) # Copy equivalent per-channel affine parameters. with torch.no_grad(): inn.weight.copy_(gn.weight) inn.bias.copy_(gn.bias) y_gn = gn(x) y_in = inn(x) print(torch.allclose(y_gn, y_in, atol=1e-5))
The comparison should be true within numerical tolerance because each GN group contains one channel and both layers use matching normalization and affine settings.
8. Production example: high-resolution medical image segmentation#
A team trains a CNN to segment organs from high-resolution medical images. Each image consumes substantial GPU memory, so the training batch size is only two.
The team considers two normalization layers.
Option A — InstanceNorm2d
- Normalizes each channel independently for each scan.
- May reduce unwanted variation in per-scan appearance.
- Can be useful if contrast and style differences are nuisance factors.
- May remove useful intensity statistics that distinguish tissue types.
Option B — GroupNorm
- Normalizes a configurable group of channels within each scan.
- Does not depend on the other image in the mini-batch.
- Allows the model to normalize groups of learned feature channels together.
- Requires selecting a group count that divides the channel count.
A controlled engineering experiment
- Keep the architecture, data split, augmentation, optimizer, and training budget fixed.
- Train an InstanceNorm baseline with clearly documented affine and running-statistics settings.
- Train GroupNorm variants with a few valid group counts, such as 4, 8, or 16 where the channel count allows them.
- Compare validation Dice and IoU, but also inspect performance by scanner, acquisition protocol, and organ size.
- Check whether normalization improves robustness to appearance variation or removes clinically useful intensity information.
- Evaluate inference behavior using the same preprocessing and model mode used in deployment.
Decision: use the normalization layer that improves held-out segmentation quality and generalization across acquisition conditions. Small batch size alone does not decide between GN and IN; both are batch-independent.
9. Common mistakes#
- Thinking GroupNorm uses the batch dimension: GN computes statistics separately for each sample.
- Assuming IN and GN are always different: GN with one channel per group is equivalent to IN when settings match.
- Ignoring PyTorch defaults: affine parameters are enabled by default in GroupNorm but disabled by default in InstanceNorm2d.
- Choosing an invalid group count: the number of channels must be divisible by the number of groups.
- Assuming InstanceNorm is always better for images: it may remove useful per-instance intensity or contrast information.
- Assuming GroupNorm is automatically better for small batches: both avoid dependence on other samples; the normalization axes and task matter.
- Comparing models with different normalization settings and other changes: change one factor at a time to understand the effect.
- Forgetting evaluation behavior: InstanceNorm can optionally track running statistics; GroupNorm always uses input statistics.
10. Decision guide#
Choose InstanceNorm when the goal is to normalize each image channel independently and reduce the influence of instance-specific appearance statistics, especially in style-transfer and image-generation pipelines.
Choose GroupNorm when training CNNs with small or variable batch sizes and you want to normalize several channels together within each sample, especially in detection and segmentation.
If you are unsure, run a controlled comparison with the same model and data. Track task-specific metrics and inspect whether the normalization removes useful information.
Key takeaway: InstanceNorm normalizes one channel at a time within each image. GroupNorm normalizes groups of channels within each image. Both are independent of batch size, and GroupNorm becomes equivalent to InstanceNorm when every group contains exactly one channel and their settings match.
Semantic deduplication / curriculum positioning: Deep Learning Question 186 explains InstanceNorm, Question 187 explains GroupNorm, and Question 190 compares GroupNorm with BatchNorm. This lesson is distinct: it compares their normalization axes, derives the group-size relationship, explains their equivalence condition and PyTorch default differences, and provides a practical selection experiment.
Sources: Group Normalization — Wu and He (2018); Instance Normalization: The Missing Ingredient for Fast Stylization — Ulyanov et al. (2016); PyTorch GroupNorm documentation; PyTorch InstanceNorm2d documentation.
References
- 1.arXiv paper 1803.08494arxiv.org
- 2.arXiv paper 1607.08022arxiv.org
- 3.docs.pytorch.org — torch.nn.modules.normalization.GroupNormdocs.pytorch.org
- 4.docs.pytorch.org — torch.nn.modules.instancenorm.InstanceNorm2ddocs.pytorch.org
Related questions
Explore other topics:Machine LearningLarge Language Models