Open In App

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:  

Return Value: It returns the tf.Tensor object.

Example 1:  




// 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:




// 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

Article Tags :