Tensorflow.js tf.initializers.glorotUniform() 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 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
// Importing the tensorflow.Js library import * as tf from "@tensorflow/tfjs" // Initializing the .initializers.glorotUniform() function const geek = tf.initializers.glorotUniform(7) // Printing gain value console.log(geek); // Printing individual values from gain 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
// Importing the tensorflow.Js library import * as tf from "@tensorflow/tfjs" // Defining the input value let inputValue = tf.input({shape:[4]}); // Initializing tf.initializers.glorotUniform() function let funcValue = tf.initializers.glorotUniform(7) // Creating dense layer 1 let dense_layer_1 = tf.layers.dense({ units: 5, activation: 'relu' , kernelInitialize: funcValue }); // Creating dense layer 2 let dense_layer_2 = tf.layers.dense({ units: 7, activation: 'softmax' }); // Output let outputValue = dense_layer_2.apply( dense_layer_1.apply(inputValue) ); // Creation the model. let model = tf.model({ inputs: inputValue, outputs: outputValue }); // Predicting the output 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
Please Login to comment...