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.glorotUniform() function extracts samples from a uniform distribution within [-limit, limit] where limit is sqrt(6 / (fan_in + fan_out)) where fan_in is the number of input units in the weight tensor and fan out is the number of output units in the weight tensor
Syntax:
tf.initializers.glorotUniform(arguments).
Parameters:
- arguments: It is an object that contains seed (a number) which is the random number generator seed/number.
Returns value: It returns tf.initializers.Initializer.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const geek = tf.initializers.glorotUniform(7)
console.log(geek);
console.log( '\nIndividual values:\n' );
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);
|
Output:
{
"scale": 1,
"mode": "fanAvg",
"distribution": "uniform"
}
Individual values:
1
fanAvg
uniform
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
let inputValue = tf.input({shape:[4]});
let funcValue = tf.initializers.glorotUniform(7)
let dense_layer_1 = tf.layers.dense({
units: 5,
activation: 'relu' ,
kernelInitialize: funcValue
});
let dense_layer_2 = tf.layers.dense({
units: 7,
activation: 'softmax'
});
let outputValue = dense_layer_2.apply(
dense_layer_1.apply(inputValue)
);
let model = tf.model({
inputs: inputValue,
outputs: outputValue
});
let finalOutput = model.predict(tf.ones([2, 4]));
finalOutput.print();
|
Output:
Tensor
[[0.0809571, 0.1913243, 0.1932435, 0.1622382,
0.2768594, 0.046838, 0.0485396],
[0.0809571, 0.1913243, 0.1932435, 0.1622382,
0.2768594, 0.046838, 0.0485396]]
Reference: https://js.tensorflow.org/api/latest/#initializers.glorotUniform