Open In App

Tensorflow.js tf.avgPool3d() 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.

The tf.avgPool3d() function is used compute the 3D average pooling.



Syntax:

tf.avgPool3d(x, filterSize, strides, pad, 
                  dimRoundingMode?, dataFormat?)

Parameters: This function accepts a parameter which is illustrated below:



Return Value: It returns the 3D average Pooling of the tensor’s elements.

Below are the examples that illustrates the use of avgPool3d() function.

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing a tensor of some elements
let geek = tf.tensor5d([10, 11, 12, 13, 14, 15, 16, 17],
                       [1, 2, 2, 2, 1]);
 
// Calling the .avgPool3d() function over
// the above tensor as its parameter
let outcome = tf.avgPool3d(geek, 2, 1, 'valid');
 
//Printing the result.
outcome.print();

Output:

Tensor
     [ [ [ [[13.5],]]]]

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing a tensor of some elements
let geek = tf.tensor5d([51, 52, 53, 54], [2, 1, 1, 1, 2]);
 
// Calling the .avgPool3d() function and
 // printing the result.
tf.avgPool3d(geek, 1, 2, 'valid').print();

Output:

Tensor
  [ [ [ [[51, 52],]]],

    [ [ [[53, 54],]]]]

Reference:https://js.tensorflow.org/api/3.6.0/#avgPool3d
 


Article Tags :