Tensorflow.js tf.initializers.leCunUniform() Function
Last Updated :
21 Jul, 2021
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
import * as tf from "@tensorflow/tfjs"
console.log(tf.initializers.leCunUniform(4));
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
import * as tf from "@tensorflow/tfjs"
let inputValue = tf.input({ shape: [4] });
let funcValue = tf.initializers.leCunUniform(6)
let dense_layer_1 = tf.layers.dense({
units: 3,
activation: 'relu' ,
kernelInitialize: funcValue
});
let dense_layer_2 = tf.layers.dense({
units: 6,
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.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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...