Tensorflow.js tf.constraints.unitNorm() Function
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.unitNorm() function us used to create a unitNorm() constraint. It is inherited from constraint class. Constraints are used as attributes for creating tf.layers.Layer. unitNorm constraint constrains every hidden unit which are instance of this weight to have unit norm.
Syntax:
tf.constraints.unitNorm(args)
Parameters:
- args: It specifies the object containing configurations.
- axis: It specifies the axis along which to calculate norm.
Return value: It returns tf.constraints.Constraint.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const constraint = tf.constraints.unitNorm({axis :1})
console.log(constraint)
|
Output
{
"defaultAxis": 0,
"axis": 1
}
Example 2: In this example we will create a dense layer using unitNorm constraint.
Javascript
import * as tf from "@tensorflow/tfjs"
const denseLayer = tf.layers.dense({
units: 4,
kernelInitializer: 'heNormal' ,
kernelConstraint: 'unitNorm' ,
biasConstraint: 'unitNorm' ,
useBias: true
});
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
output.print()
|
Output
Tensor
[[0.3154395, 0.3988628, 1.3295887, -0.0849797],
[0.3154395, 0.3988628, 1.3295887, -0.0849797]]
Reference: https://js.tensorflow.org/api/1.0.0/#constraints.unitNorm
Last Updated :
21 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...