Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.BatchNormalization

BatchNormalization normalizes activations using batch statistics during training and moving statistics during inference. It can apply learned scale and offset parameters after normalization.

How it works

BatchNormalization normalizes selected input channels and then optionally applies learned scale and offset. Training uses statistics from the current batch, while inference uses moving statistics accumulated during training.

Syntax

keras.layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001, center=True, scale=True, beta_initializer="zeros", gamma_initializer="ones", moving_mean_initializer="zeros", moving_variance_initializer="ones", beta_regularizer=None, gamma_regularizer=None, beta_constraint=None, gamma_constraint=None, renorm=False, renorm_clipping=None, renorm_momentum=0.99, synchronized=False, **kwargs)

Parameters

NameTypeDescription
axisint or tuple of intsAxis or axes whose channels are normalized; defaults to the last axis.
momentumfloatDecay factor for the moving statistics.
epsilonfloatSmall value added to variance for numerical stability.
centerboolWhether to add the learned beta offset.
scaleboolWhether to multiply by the learned gamma scale.
beta_initializerstr or initializerInitializer for beta.
gamma_initializerstr or initializerInitializer for gamma.
moving_mean_initializerstr or initializerInitializer for moving mean.
moving_variance_initializerstr or initializerInitializer for moving variance.
beta_regularizerregularizerRegularizer for beta.
gamma_regularizerregularizerRegularizer for gamma.
beta_constraintconstraintConstraint for beta.

Returns

A layer instance that normalizes inputs.

Key points

  • It is a Keras layer for normalizing activations.
  • The transformation aims to keep the output mean near zero and its standard deviation near one.
  • Normalization is performed independently for each channel selected by axis.
  • With training=True, statistics come from the current input batch.
  • With training=False, accumulated moving statistics are used.
  • Inference behavior is the default when the layer or model is called without an explicit training flag.

Example: Batch-normalize features

import keras
from keras import layers

inputs = keras.Input(shape=(32,))
x = layers.BatchNormalization()(inputs)
outputs = layers.Dense(1)(x)
model = keras.Model(inputs, outputs)
model.compile(optimizer="adam", loss="mse")
model.fit(
    keras.ops.ones((8, 32)),
    keras.ops.zeros((8, 1)),
    epochs=1,
    verbose=0,
)

Builds a model that normalizes 32-feature inputs before a dense output layer.

When to use it

Stabilize dense-layer activations

Feature-based neural networks

Normalize channel activations

Convolutional networks

Preserve batch-normalization statistics during fine-tuning

Transfer learning

Interview questions

QWhat does BatchNormalization do during training?

BatchNormalization normalizes each selected channel using the current batch's mean and variance during training. It then applies learned gamma scaling and beta offset, with epsilon protecting the denominator.

Follow-up: How does inference differ? It uses moving mean and moving variance collected during training instead of statistics from the current batch.

QWhat is the purpose of the axis argument?

By default, axis=-1, so the last input axis is normalized. For convolutional data, the channel axis should be selected explicitly when it is not the last axis.

Follow-up: Why does axis matter? It determines which dimension receives separate normalization statistics and trainable parameters.

QWhich state does BatchNormalization maintain?

The layer keeps moving averages of batch mean and variance for inference. These are non-trainable weights, whereas the learned scale and offset are trainable when enabled.

Follow-up: What fine-tuning precaution is recommended? Keep BatchNormalization in inference mode by passing training=False when calling the base model.

  • layers.LayerNormalization
  • layers.Normalization
  • layers.Layer

Source: BatchNormalization layer. Checked 2026-10-15.