Skip to content
Related Articles
Open in App
Not now

Related Articles

Tensorflow.js tf.initializers.heUniform() Function

Improve Article
Save Article
Like Article
  • Last Updated : 23 Jul, 2021
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.heUniform() function draws samples from a uniform distribution within [-cap, cap] where cap is sqrt(6 / fan_in). Note that the fanIn is the number of inputs in the tensor weight.

Syntax:

tf.initializers.heUniform(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.heUniform() function
const geek = tf.initializers.heUniform(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": "uniform"
}

Individual values:

2
fanIn
uniform

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.heUniform() function
const funcValue = tf.initializers.heUniform(4)
 
// Creating dense layer 1
const dense_layer_1 = tf.layers.dense({
    units: 6,
    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.2727611, 0.1405532, 0.0409708, 0.1262356, 
        0.1215546, 0.134949, 0.0845761, 0.0783997],
    [0.2727611, 0.1405532, 0.0409708, 0.1262356, 
        0.1215546, 0.134949, 0.0845761, 0.0783997]]

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


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!