Tensorflow.js tf.constraints.minMaxNorm() Function
Last Updated :
21 Jul, 2021
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The tf.constraints.minMaxNorm() function is used to create a minMaxNorm constraint based on the given config object. It is inherited from constraint class. Constraints are the attributes of layers like weight, kernels, biases. minMaxNorm is a weight constraint.
Syntax:
tf.constraints.minMaxNorm(config)
Parameters: This function takes the config object as a parameter which can have the following properties:
- maxValue: It specifies the maximum norm for incoming weight.
- mixValue: It specifies the minimum norm for incoming weight.
- axis: It specifies the axis along which to calculate norm.
- rate: It specifies the rate of enforcing the constraints.
Return value: It returns a tf.constraints.Constraint.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const constraint = tf.constraints.minMaxNorm(1,0)
console.log(constraint)
|
Output:
{
"defaultMinValue": 0,
"defaultMaxValue": 1,
"defaultRate": 1,
"defaultAxis": 0,
"minValue": 0,
"maxValue": 1,
"rate": 1,
"axis": 0
}
Example 2: In this example we will create a dense layer using minMaxNorm constraint.
Javascript
import * as tf from "@tensorflow/tfjs"
const denseLayer = tf.layers.dense({
units: 4,
kernelInitializer: 'heNormal' ,
kernelConstraint: 'minMaxNorm' ,
biasConstraint: 'minMaxNorm' ,
useBias: true
});
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
output.print()
|
Output:
Tensor
[[1.5594537, 0.1787095, 0.3462192, -1.7434707],
[1.5594537, 0.1787095, 0.3462192, -1.7434707]]
Reference: https://js.tensorflow.org/api/1.0.0/#constraints.minMaxNorm
Share your thoughts in the comments
Please Login to comment...