Normalize channels without batch dependence
Convolutional networks with feature maps
Keras · Class
GroupNormalization divides feature channels into groups and normalizes each group using its own mean and variance. Optional beta and gamma parameters then offset and scale the result.
GroupNormalization partitions the selected feature axis into groups, computes each group's mean and variance, and normalizes values with a small epsilon for numerical stability. Optional trainable beta and gamma parameters then offset and scale the normalized output.
keras.layers.GroupNormalization(groups=32, axis=-1, epsilon=0.001, center=True, scale=True, beta_initializer="zeros", gamma_initializer="ones", beta_regularizer=None, gamma_regularizer=None, beta_constraint=None, gamma_constraint=None, **kwargs)| Name | Type | Description |
|---|---|---|
groups | int | Number of normalization groups; it must divide the selected input dimension. |
axis | int or list/tuple | Axis or axes over which normalization is performed; defaults to -1. |
epsilon | float | Value added to variance for numerical stability; defaults to 0.001. |
center | bool | Whether to apply the beta offset; defaults to True. |
scale | bool | Whether to apply gamma scaling; defaults to True. |
beta_initializer | initializer | Initializer for beta; defaults to zeros. |
gamma_initializer | initializer | Initializer for gamma; defaults to ones. |
beta_regularizer | regularizer or None | Optional regularizer for beta. |
gamma_regularizer | regularizer or None | Optional regularizer for gamma. |
beta_constraint | constraint or None | Optional constraint for beta. |
gamma_constraint | constraint or None | Optional constraint for gamma. |
**kwargs | keyword arguments | Additional layer keyword arguments. |
A tensor with the same general shape as the input after group normalization.
import keras
from keras import layers
inputs = keras.Input(shape=(32, 32, 64))
x = layers.GroupNormalization(groups=8)(inputs)
outputs = layers.Conv2D(32, 3, padding="same")(x)
model = keras.Model(inputs, outputs)
model.summary()This model normalizes 64-channel feature maps in eight groups before applying a convolution.
Convolutional networks with feature maps
Small-batch training
Residual or generative blocks
The layer divides channels into groups and calculates mean and variance independently within each group. It then normalizes using those statistics, rather than relying on batch-wide statistics.
Follow-up: How can the grouping be made equivalent to instance-style normalization? Use groups equal to the number of channels, so each channel forms its own group.
groups controls how many groups are formed, while axis identifies the feature dimension or dimensions to normalize. The normalized input dimension must be divisible by groups.
Follow-up: What configuration normalizes all channels together? Set groups=1, provided the selected axis and input shape match that intended grouping.
epsilon is added to the variance before division, preventing instability when the variance is zero or very small. center adds beta, and scale multiplies by gamma when enabled.
Follow-up: When might scale be disabled? If the next layer is linear, its own scaling can make gamma unnecessary.
LayerNormalizationBatchNormalizationNormalization