Open In App

Tensorflow.js tf.layers.gaussianNoise() Function

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or Node.js.

The tf.layers.gaussianNoise() function is used to apply additive zero-centered Gaussian noise. Since it is a regularization layer hence, it is only active at training time.



tf.layers.gaussianNoise(arguments)

Parameters

Return Value: It returns GaussianNoise.



Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the tensor
const geek= tf.tensor1d([28561, 53678, 21343, 81422]);
 
// Reshaping tensor
const geek1 = tf.reshape(geek,[2,2]);
 
// Creating gaussianNoise of poolSize 2*2
const gaussianNoise =
      tf.layers.gaussianNoise({poolSize:[2,2]});
 
// Applying gaussianNoise on geek1 tensor
const result = gaussianNoise.apply(geek1);
 
// Printing the result tensor
result.print();

Output:

Tensor
    [[28561, 53678],
     [21343, 81422]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Reshaping tensor
const geek1 = tf.reshape(
  tf.tensor1d([215, 637, 172, 368]),
  [2,2]);
 
// Applying gaussianNoise on geek1 tensor
tf.layers.gaussianNoise(
  {
    poolSize:[2,2]
  }
).apply(
  geek1).print();

Output:

Tensor
    [[215, 637],
     [172, 368]]

Reference: https://js.tensorflow.org/api/3.6.0/#layers.gaussianNoise


Article Tags :