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 in Node.js.
The tf.initializers.glorotNormal() function extract samples from a truncated normal distribution which is been centered at 0 with stddev = sqrt(2 / (fan_in + fan_out)). Note that the fan_in is the number of inputs in the tensor weight and the fan_out is the number of outputs in the tensor weight.
Syntax:
tf.initializers.glorotNormal(arguments)
Parameters:
- arguments: It is an object that contains seed (a number) which is the random number generator seed/number.
Return value: It returns tf.initializers.Initializer.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
console.log(tf.initializers.glorotNormal(9));
console.log( '\nIndividual values:\n' );
console.log(tf.initializers.glorotNormal(9).scale);
console.log(tf.initializers.glorotNormal(9).mode);
console.log(tf.initializers.glorotNormal(9).distribution);
|
Output:
{
"scale": 1,
"mode": "fanAvg",
"distribution": "normal"
}
Individual values:
1
fanAvg
normal
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs
const inputValue = tf.input({ shape: [4] });
const funcValue = tf.initializers.glorotNormal(9)
const dense_layer_1 = tf.layers.dense({
units: 11,
activation: 'relu' ,
kernelInitialize: funcValue
});
const dense_layer_2 = tf.layers.dense({
units: 7,
activation: 'softmax'
});
const outputValue = dense_layer_2.apply(
dense_layer_1.apply(inputValue)
);
const model = tf.model({
inputs: inputValue,
outputs: outputValue
});
model.predict(tf.ones([2, 4])).print();
|
Output:
Tensor
[[0.1004296, 0.1564845, 0.1716817, 0.1526613,
0.1739253, 0.1059624, 0.1388552],
[0.1004296, 0.1564845, 0.1716817, 0.1526613,
0.1739253, 0.1059624, 0.1388552]]
Reference: https://js.tensorflow.org/api/latest/#initializers.glorotNormal