Open In App

Tensorflow.js tf.layers.batchNormalization() 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.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:

Return Value: It returns an object (BatchNormalization).

Example 1:




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:




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


Article Tags :