Open In App

Tensorflow.js tf.layers.elu() Function

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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or Node.js.

The tf.layers.elu() function is abbreviated as Exponential Linear Unit. It is defined as: 



F(a) = alpha * (exp(a) – 1.) for a < 0, f(a) = a for a >= 0.

Syntax:



tf.layers.elu(arguments)

Parameters:

Return Value: It returns ELU.

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the tensor
const geek= tf.tensor1d([11, 12, 23, 74]);
 
// Reshaping tensor
const geek1=tf.reshape(geek,[2,2]);
 
// Creating ELU of poolSize 2*2
const elu=tf.layers.elu({poolSize:[2,2]});
 
//Applying ELU on geek1 tensor
const result = elu.apply(geek1);
 
//Printing the result tensor
result.print();

Output:

Tensor
    [[11, 12],
     [23, 74]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Reshaping tensor
const geek1=tf.reshape(tf.tensor1d([55, 63, 17, 28]),[2,2]);
 
// Applying elu on geek1 tensor
tf.layers.elu(
  {
    poolSize:[2,2]
  }
).apply(
  geek1).print();

Output:

Tensor
    [[55, 63],
     [17, 28]]

Reference: https://js.tensorflow.org/api/3.6.0/#layers.elu


Article Tags :