Wednesday, July 3, 2024
HomeLanguagesJavascriptTensorflow.js tf.relu() Function

Tensorflow.js tf.relu() Function

Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .relu() function is used to find rectified linear of the stated tensor input i.e. max(x, 0) and is done element wise.

Syntax :  

tf.relu(x)

Parameters:  

  • x: It is the stated tensor input, and it can be of type tf.Tensor, TypedArray, or Array. Moreover, if the stated datatype is of type Boolean then the output datatype will be of type int32.

Return Value: It returns the tf.Tensor object.

Example 1:  

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input elements
const y = tf.tensor1d([11, 76, 0, -4, 6]);
  
// Calling relu() method and
// Printing output
y.relu().print();


Output:

Tensor
    [11, 76, 0, 0, 6]

Example 2:

Javascript




// Importing the tensorflow.js library 
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input
var val = [1.5, -5, .22, null, 'a'];
  
// Calling tensor1d method
const y = tf.tensor1d(val);
  
// Calling relu() method
var res = tf.relu(y)
  
// Printing output
res.print();


Output:

Tensor
    [1.5, 0, 0.22, 0, NaN]

Reference: https://js.tensorflow.org/api/latest/#relu

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments