Tensorflow.js tf.initializers.truncatedNormal() Function
Last Updated :
17 Sep, 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.truncatedNormal() function produces random values initialized to a truncated normal distribution.
Syntax:
tf.initializers.truncatedNormal(arguments)
Parameters: It takes an object as arguments that contain the any of key values listed below:
- mean: It is the mean of the random values to be generated.
- stddev: It is the standard deviation of the random values to be generated.
- seed: It is the random number generator seed.
Returns value: It returns tf.initializers.Initializer
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
let geek = tf.initializers.truncatedNormal(13)
console.log(geek);
console.log( '\nIndividual values:\n' );
console.log(geek.DEFAULT_MEAN);
console.log(geek.DEFAULT_STDDEV);
console.log(geek.mean);
console.log(geek.stddev);
|
Output:
{
"DEFAULT_MEAN": 0,
"DEFAULT_STDDEV": 0.05,
"mean": 0,
"stddev": 0.05
}
Individual values:
0
0.05
0
0.05
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs
const inputValue = tf.input({shape:[4]});
const funcValue = tf.initializers.truncatedNormal(11)
const dense_layer_1 = tf.layers.dense({
units: 4,
activation: 'relu' ,
kernelInitialize: funcValue
});
const dense_layer_2 = tf.layers.dense({
units: 6,
activation: 'softmax'
});
const outputValue = dense_layer_2.apply(
dense_layer_1.apply(inputValue)
);
const model = tf.model(
{
inputs: inputValue,
outputs: outputValue
});
model.predict(tf.ones([2, 4])).print();
|
Output:
Tensor
[[0.1830122, 0.1198884, 0.1611279,
0.2659391, 0.1296039, 0.1404286],
[0.1830122, 0.1198884, 0.1611279,
0.2659391, 0.1296039, 0.1404286]]
Reference: https://js.tensorflow.org/api/3.6.0/#initializers.truncatedNormal
Share your thoughts in the comments
Please Login to comment...