Open In App

Tensorflow.js tf.layers.alphaDropout() 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.AlphaDropout() function is used to apply Alpha Dropout to the input. Since it is a regularization layer hence, it is only active at training time.



Syntax:

tf.layers.AlphaDropout(arguments)

Parameters



Return Value: It returns AlphaDropout.

Example 1:




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

Output:

Tensor
    [[121 , 152 ],
     [2213, 7814]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Reshaping tensor
const geek1 = tf.reshape(
  tf.tensor1d([25, 163, 127, 328]),
  [2,2]);
 
// Applying alphaDropout on geek1 tensor
tf.layers.alphaDropout(
  {
    poolSize:[2,2]
  }
).apply(
  geek1).print();

Output:

Tensor
    [[25 , 163],
     [127, 328]]

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


Article Tags :