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

TensorFlow · Class

layers.Normalization

A Keras preprocessing layer that standardizes continuous features using stored mean and variance. Statistics can be supplied at construction or learned with adapt().

How it works

Normalization learns or receives feature statistics, then shifts and scales inputs using those values. With the default axis, each feature index gets its own mean and variance; setting invert=True reverses the transformation.

Syntax

tf.keras.layers.Normalization(axis=-1, mean=None, variance=None, invert=False, **kwargs)

Parameters

NameTypeDescription
axisInteger, tuple of integers, or NoneAxis or axes receiving separate statistics for each index; None uses scalar statistics across all input elements.
meanOptional value or valuesMean value or values used for normalization; they must broadcast to the retained-axis shape.
varianceOptional value or valuesVariance value or values used for normalization; they must broadcast to the retained-axis shape.
invertBooleanIf true, applies the inverse transformation and reconstructs the original scale.
**kwargsKeyword argumentsAdditional layer keyword arguments.

Returns

A Keras preprocessing layer that outputs normalized inputs, or inverse-transformed inputs when invert=True.

Key points

  • Normalization is a preprocessing layer intended for continuous-valued features.
  • Its standardization target is a distribution centered near zero with unit standard deviation.
  • At execution time, it subtracts the stored mean and divides by the square root of the stored variance.
  • Calling adapt() derives statistics from data and keeps them as layer weights.
  • The axis setting selects dimensions whose individual indices receive separate statistics.
  • Constructor-provided means are broadcast across the dimensions retained by axis.

Common mistakes

  • Call adapt() before training, evaluation, or prediction when the layer learns its statistics.
  • Provide mean and variance at construction, or adapt the layer; do not leave both sources unspecified.
  • axis=None uses one scalar mean and variance for every input element rather than separate statistics per feature.

Example: Adapt and apply feature normalization

import numpy as np
import tensorflow as tf

layer = tf.keras.layers.Normalization(axis=-1)
layer.adapt(np.array([[1., 10.], [3., 14.], [5., 18.]]))
print(layer(np.array([[3., 14.]], dtype=np.float32)))

Creates a feature-wise normalizer, learns its statistics from sample data, and transforms one input row.

When to use it

Feature preprocessing

Prepare numeric columns before a neural network consumes them.

Consistent inference scaling

Reuse fixed training statistics when serving or exporting a model.

Inverse transformation

Undo a previously applied standardization step.

Interview questions

QHow does tf.keras.layers.Normalization transform inputs?

The layer standardizes inputs by subtracting the stored mean and dividing by the square root of the stored variance. It can use statistics supplied in the constructor or statistics learned with adapt().

Follow-up: How would you restore standardized values? Set invert=True so the layer applies the inverse transformation using its stored statistics.

QWhat does the axis argument control?

axis determines which dimensions receive separate mean and variance values. The default axis=-1 therefore normalizes feature positions independently, while axis=None uses one scalar pair of statistics.

Follow-up: What shape constraint matters for supplied statistics? Their values must broadcast to the shape of the retained axes, or build() raises an error.

QWhen should adapt() be called, and what does it do?

adapt() computes the dataset mean and variance and stores them as the layer's weights. It must be completed before fit(), evaluate(), or predict() uses the layer.

Follow-up: What alternative avoids adapt()? Pass compatible mean and variance values during construction.

  • tf.keras.layers.UnitNormalization
  • tf.keras.layers.LayerNormalization
  • tf.keras.layers.BatchNormalization

Source: tf.keras.layers.Normalization | TensorFlow v2.16.1. Checked 2026-10-15.