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.leCunUniform() function takes samples from a uniform distribution in the interval [-cap, cap] with cap = sqrt(3 / fanIn). Note that the fanIn is the number of inputs in the tensor weight.
Syntax:
tf.initializers.leCunUniform(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" // Initialising the .initializers.leCunUniform() function console.log(tf.initializers.leCunUniform(4)); // Printing individual values from the gain console.log( "\nIndividual Values\n" ); console.log(tf.initializers.leCunUniform(4).scale); console.log(tf.initializers.leCunUniform(4).mode); console.log(tf.initializers.leCunUniform(4).distribution); |
Output:
{ "scale": 1, "mode": "fanIn", "distribution": "uniform" } Individual Values 1 fanIn 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.leCunUniform() // function let funcValue = tf.initializers.leCunUniform(6) // Creating dense layer 1 let dense_layer_1 = tf.layers.dense({ units: 3, activation: 'relu' , kernelInitialize: funcValue }); // Creating dense layer 2 let dense_layer_2 = tf.layers.dense({ units: 6, activation: 'softmax' }); // Output Value 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.1853671, 0.1406064, 0.1505066, 0.1183221, 0.2430924, 0.1621054], [0.1853671, 0.1406064, 0.1505066, 0.1183221, 0.2430924, 0.1621054]]
Reference: https://js.tensorflow.org/api/latest/#initializers.leCunUniform