Saturday, October 5, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.initializers.heNormal() Function

Tensorflow.js tf.initializers.heNormal() 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.heNormal() function draws samples from a truncated normal distribution centered on zero with stddev = sqrt(2 / fanIn)  within [-limit, limit] where limit is sqrt(6 / fan_in). Note that the fanIn is the number of inputs in the tensor weight.

Syntax:

tf.initializers.heNormal(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.heNormal()
// function
const geek = tf.initializers.heNormal(7)
 
// Printing gain
console.log(geek);
console.log('\nIndividual values:\n');
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);


Output:

{
  "scale": 2,
  "mode": "fanIn",
  "distribution": "normal"
}

Individual values:

2
fanIn
normal

Example 2:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs
 
// Defining the input value
const inputValue = tf.input({shape:[4]});
 
// Initializing tf.initializers.heNormal() function
const funcValue = tf.initializers.heNormal(3)
 
// Creating dense layer 1
const dense_layer_1 = tf.layers.dense({
    units: 7,
    activation: 'relu',
    kernelInitialize: funcValue
});
 
// Creating dense layer 2
const dense_layer_2 = tf.layers.dense({
    units: 8,
    activation: 'softmax'
});
 
// Output
const outputValue = dense_layer_2.apply(
  dense_layer_1.apply(inputValue)
);
 
// Creation the model.
const model = tf.model({
    inputs: inputValue,
    outputs: outputValue
});
 
// Predicting the output.
model.predict(tf.ones([2, 4])).print();


Output:

Tensor 
[[0.0802892, 0.1482767, 0.1004469, 0.1141223, 0.218376, 0.1217001, 0.139549, 0.0772399], 
[0.0802892, 0.1482767, 0.1004469, 0.1141223, 0.218376, 0.1217001, 0.139549, 0.0772399]]

Reference: https://js.tensorflow.org/api/latest/#initializers.heNormal

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments