Regularize numeric inputs
A neural network overfits real-valued training features.
TensorFlow · Class
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.
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.
tf.keras.layers.GaussianNoise(stddev, seed=None, **kwargs)| Name | Type | Description |
|---|---|---|
stddev | float | Float; standard deviation of the noise distribution. |
seed | int, optional | Optional integer random seed for deterministic behavior. |
inputs | Tensor | Input tensor of any rank. |
training | bool | Python boolean selecting training mode, where noise is added, or inference mode, where the layer does nothing. |
A tensor with additive Gaussian noise during training; during inference, the layer does nothing and returns the input unchanged.
stddev sets the scale of the Gaussian perturbation; larger values produce stronger corruption.seed when repeatable random behavior is required.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.
A neural network overfits real-valued training features.
A model needs stochastic perturbations without changing feature shape.
Experiments require repeatable noise behavior.
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.
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.
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.GaussianDropouttf.keras.layers.Layertf.keras.layers.Dense