Tensorflow.js tf.initializers.randomUniform() 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.randomUniform() function generates random values that is initialized to a uniform distribution. The values are distributed uniformly between the configured min-value and max-value.
Syntax:
tf.initializers.randomUniform(arguments)
Parameters:
- arguments: It is an object that contains 3 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.randomUniform(5)
console.log(geek);
console.log( '\nIndividual values:\n' );
console.log(geek.DEFAULT_MINVAL);
console.log(geek.DEFAULT_MAXVAL);
console.log(geek.minval);
console.log(geek.maxval);
|
Output:
{
"DEFAULT_MINVAL": -0.05,
"DEFAULT_MAXVAL": 0.05,
"minval": -0.05,
"maxval": 0.05
}
Individual values:
-0.05
0.05
-0.05
0.05
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs
const inputValue = tf.input({shape:[4]});
const funcValue = tf.initializers.randomUniform(8)
const dense_layer_1 = tf.layers.dense({
units: 5,
activation: 'relu' ,
kernelInitialize: funcValue
});
const dense_layer_2 = tf.layers.dense({
units: 7,
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.1145501, 0.133405, 0.0640167, 0.2349582,
0.1064994, 0.0799759, 0.2665946],
[0.1145501, 0.133405, 0.0640167, 0.2349582,
0.1064994, 0.0799759, 0.2665946]]
Reference: https://js.tensorflow.org/api/3.6.0/#initializers.randomUniform
Last Updated :
31 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...