Open In App

Tensorflow.js tf.layers.batchNormalization() Function

Last Updated : 25 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js.

The tf.layers.batchNormalization() function is used to apply the batch normalization operation on data. Batch normalisation is a method for training very deep neural networks that standardises each mini-inputs batch’s to a layer. This stabilises the learning process and significantly reduces the number of training epochs needed to create deep networks.

Syntax:

tf.layers.batchNormalization(args?)

Input Shape: Arbitrary. When utilizing this layer as the initial layer in a model, use the inputShape configuration.

Output Shape: The output has the same shape as the input.

Parameters: It accepts the args object which can have the following properties:

  • axis (number): The integer axis that should be normalized (typically the features axis). -1 is the default value.
  • momentum (number): The moving average’s momentum. The default value is 0.99.
  • epsilon (number): The small float is added to the variance to avoid division by zero. Defaults to 1e-3.
  • center (boolean): If this is true, add the offset of beta to the normalized tensor. If false, beta isn’t taken into account. The value is set to true by default.
  • scale (boolean): If this is true, multiplied by gamma. Gamma is not utilized if false. True is the default value.
  • betaInitializer: This is the beta weight’s initializer. ‘zeroes’ is the default value.
  • gammaInitializer: This is the gamma weight’s initializer. ‘ones’ is the default value.
  • movingMeanInitializer: This is the moving mean’s initializer. ‘zeroes’ is the default value.
  • movingVarianceInitializer: This is the moving variance’s initializer. ‘ones’ is the default value.
  • betaConstraint: The constraint for the beta weight.
  • gammaConstraint: The constraint for the gamma weight.
  • betaRegularizer: The regularizer for the beta weight.
  • gammaRegularizer: The regularizer for the beta weight.

Return Value: It returns an object (BatchNormalization).

Example 1:

Javascript




import * as tf from "@tensorflow/tfjs";
  
const batchNormalizationLayer = tf.layers.batchNormalization();
      
const x = tf.tensor([1.12, -0.8, 1.9, 0.12, 0.25, -3.4], [2, 3]);
  
batchNormalizationLayer.apply(x).print();


Output:

Tensor
   [[1.1194404, -0.7996003, 1.8990507 ],
    [0.11994  , 0.2498751 , -3.3983014]]

Example 2:

Javascript




import * as tf from "@tensorflow/tfjs";
  
const batchNormalizationLayer = tf.layers.batchNormalization();
      
const x = tf.tensor([12, 3.2, 4.8, 9, 10, 2.5, 
    8, 11, 9.4, 25, 24.9, 98.7], [2, 3, 2]);
  
batchNormalizationLayer.apply(x).print();


Output:

Tensor
   [[[11.9940042, 3.1984012 ],
     [4.7976022 , 8.9955034 ],
     [9.9950037 , 2.4987509 ]],
    [[7.9960032 , 10.994504 ],
     [9.3953028 , 24.9875088],
     [24.8875599, 98.6506805]]]

Reference: https://js.tensorflow.org/api/latest/#layers.batchNormalization



Similar Reads

Tensorflow.js tf.layers.embedding() Function
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.embedding() function is used to map positive integers into dense vectors of fixed size. Syntax: tf.layers.embedding(args)Parameters: This function accepts
3 min read
Tensorflow.js tf.layers.elu() 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.elu() function is abbreviated as Exponential L
2 min read
Tensorflow.js tf.layers.globalMaxPooling1d() Function
Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. The tf.layers.globalMaxPooling1d() function is us
2 min read
Tensorflow.js tf.layers.dot() 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. Tensorflow.js tf.layers.dot() function is used to apply the dot product between the two tensors provided. Syntax: tf.layers.dot(args); Parameters: This function accepts the following p
3 min read
Tensorflow.js tf.layers.timeDistributed() 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. The tf.layers.timeDistributed() function is used to apply the wrap of a layer to every temporal slice of a specified input. The given input must be at least 3D, and the index 1 for the
3 min read
Tensorflow.js tf.layers.average() 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.average() function is used to calculate averag
2 min read
Tensorflow.js tf.layers.gruCell() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .layers.gruCell( ) function is used to create a cell class for GRU. Syntax: tf.layers.gruCell (args) Parameters: recurrentActivation: It is a tensor input that
4 min read
Tensorflow.js tf.layers.thresholdedReLU() Function
Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. The tf.layers.thresholdedReLU() function is used
2 min read
Tensorflow.js tf.layers.minimum() 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. The tf.layers.minimum() function is used to create a layer that is used to compute the element-wise minimum of an Array of inputs. It takes as input a list of tensors, having the same
2 min read
Tensorflow.js tf.layers.dense() Function
The tf.layers.dense() is an inbuilt function of Tensorflow.js library. This function is used to create fully connected layers, in which every output depends on every input. Syntax: tf.layers.dense(args)Parameters: This function takes the args object as a parameter which can have the following properties: units: It is a positive number that defines
3 min read