Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.constraints.Constraint Class

  • Last Updated : 20 Aug, 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. 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:  

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!