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

TensorFlow · Class

layers.GaussianNoise

A Keras regularization layer that adds zero-centered Gaussian noise to inputs during training. It can help mitigate overfitting, while inference leaves the input unchanged.

How it works

GaussianNoise is a Keras regularization layer that adds samples from a zero-centered Gaussian distribution to its input. Its configured standard deviation controls noise magnitude; the layer adds noise only when called in training mode and passes inputs through during inference.

Syntax

tf.keras.layers.GaussianNoise(stddev, seed=None, **kwargs)

Parameters

NameTypeDescription
stddevfloatFloat; standard deviation of the noise distribution.
seedint, optionalOptional integer random seed for deterministic behavior.
inputsTensorInput tensor of any rank.
trainingboolPython boolean selecting training mode, where noise is added, or inference mode, where the layer does nothing.

Returns

A tensor with additive Gaussian noise during training; during inference, the layer does nothing and returns the input unchanged.

Key points

  • The layer perturbs each input with additive noise whose distribution is centered at zero.
  • Use it as a regularizer when a model memorizes training examples too readily.
  • Its stochastic input perturbation can be viewed as augmenting training data without changing the feature schema.
  • It is especially suited to numeric, real-valued features rather than categorical representations.
  • stddev sets the scale of the Gaussian perturbation; larger values produce stronger corruption.
  • Provide seed when repeatable random behavior is required.

Common mistakes

  • The layer does not add noise during inference; ensure the call or model execution uses training mode when testing its regularization behavior.

Example: Use GaussianNoise during training

import tensorflow as tf

inputs = tf.keras.Input(shape=(32,))
x = tf.keras.layers.GaussianNoise(stddev=0.1, seed=7)(inputs)
outputs = tf.keras.layers.Dense(1)(x)
model = tf.keras.Model(inputs, outputs)

x_batch = tf.ones((4, 32))
training_output = model(x_batch, training=True)
inference_output = model(x_batch, training=False)
print(training_output.shape, inference_output.shape)

Adds noise during training while leaving inference inputs unchanged.

When to use it

Regularize numeric inputs

A neural network overfits real-valued training features.

Augment training inputs

A model needs stochastic perturbations without changing feature shape.

Control randomness with a seed

Experiments require repeatable noise behavior.

Interview questions

QWhat does tf.keras.layers.GaussianNoise do?

GaussianNoise adds additive, zero-centered Gaussian noise to its input. The stddev argument is the standard deviation of that noise distribution.

Follow-up: How would you disable the perturbation for evaluation? Call the layer or model with training=False, which makes it do nothing.

QWhy use this layer in a model?

It is intended to reduce overfitting by corrupting real-valued inputs during training. The documentation describes this as a form of random data augmentation.

Follow-up: Why is additive Gaussian noise suitable for real-valued features? It perturbs numeric values while preserving their general representation type.

QWhich arguments control behavior?

seed is an optional integer random seed that enables deterministic behavior. inputs may be a tensor of any rank, and training selects noise-adding training behavior or no-op inference behavior.

Follow-up: What should be checked when reproducibility matters? Supply a seed and keep the execution configuration consistent across runs.

  • tf.keras.layers.GaussianDropout
  • tf.keras.layers.Layer
  • tf.keras.layers.Dense

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