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