Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tensorflow.js tf.initializers.leCunNormal() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the .initializers.leCunNormal() function
const geek = tf.initializers.leCunNormal(3)
 
// Printing gain
 
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




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Defining the input value
let inputValue = tf.input({ shape: [4] });
 
// Initializing tf.initializers.leCunNormal()
// function
let funcValue = tf.initializers.leCunNormal(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.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


My Personal Notes arrow_drop_up
Last Updated : 23 Jul, 2021
Like Article
Save Article
Similar Reads
Related Tutorials