Open In App

Tensorflow.js tf.constraints.Constraint Class

Improve
Improve
Like Article
Like
Save
Share
Report

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. The tf.constraints.Constraint class is used to extend the serialization.Serializable class. Moreover, it is the base class in favor of the functions which enforce constraints on the weight values.

This tf.constraints.Constraint class contains four inbuilt functions which are illustrated below:  

Example 1: In this example, tf.constraints.Constraint class .constraints.minMaxNorm() function is used to create a minMaxNorm constraint based on the given config object. It is inherited from the constraint class. Constraints are the attributes of layers like weight, kernels, biases. minMaxNorm is a weight constraint.

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
  
// Calling maxNorm() function
var a = tf.constraints.maxNorm(2, 0)
  
// Printing output
console.log(a)


 

Output:

{
    "defaultMaxValue": 2,
    "defaultAxis": 0,
    "maxValue": 2,
    "axis": 0
}

Example 2: In this example, tf.constraints.Constraint class .constraints.nonNeg() function is used to create a nonNeg constraint. nonNeg is a non-negative weight constraint. It is inherited from constraint class. Constraints are the attributes of the layers.

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
  
// Use nonNeg() function
const constraint = tf.constraints.nonNeg( )
  
// Print output
console.log(constraint)


Output:

{}

Reference: https://js.tensorflow.org/api/latest/#class:constraints.Constraint


Last Updated : 20 Aug, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads