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.leCunNormal() function extracts samples from a truncated normal distribution which is centered at zero with stddev = sqrt(1 / fanIn). Note that fanIn is the number of inputs in the tensor weight.
Syntax:
tf.initializers.leCunNormal(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.leCunNormal(3)
console.log(geek);
console.log( '\nIndividual values:\n' );
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);
|
Output:
{
"scale": 1,
"mode": "fanIn",
"distribution": "normal"
}
Individual values:
1
fanIn
normal
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
let inputValue = tf.input({ shape: [4] });
let funcValue = tf.initializers.leCunNormal(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.0666204, 0.1171203, 0.2322821, 0.1056982,
0.2149536, 0.1846998, 0.0786256],
[0.0666204, 0.1171203, 0.2322821, 0.1056982,
0.2149536, 0.1846998, 0.0786256]]
Reference: https://js.tensorflow.org/api/latest/#initializers.leCunNormal
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jul, 2021
Like Article
Save Article