Saturday, December 28, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.prelu() Function

Tensorflow.js tf.prelu() 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 .prelu() function is used to find leaky rectified linear of the stated tensor input along with parametric alphas and is done element wise.

Syntax :  

tf.prelu(x, alpha)

Where, x < 0 ? alpha * x : f(x) = x

Parameters:  

  • x: It is the stated tensor input, and it can be of type tf.Tensor, TypedArray, or Array.
  • alpha: It is the stated scaling factor for the stated negative values in tensor input, and it can be of type tf.Tensor, TypedArray, or Array.

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, 12, -31, 36]);
  
// Defining alpha
const alp = tf.scalar(0.2);
  
// Calling prelu() method and
// Printing output
y.prelu(alp).print();


Output:

Tensor
    [-2.2, 12, -6.2000003, 36]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling prelu() method and
// Printing output
var res = tf.prelu(tf.tensor1d(
  [-1.9, 8.2, -6.1, 13.6]), tf.scalar(-1));
res.print();


Output:

Tensor
    [1.9, 8.1999998, 6.0999999, 13.6000004]

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

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!

RELATED ARTICLES

Most Popular

Recent Comments