Open In App

Tensorflow.js tf.maxPool3d() 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.maxPool3d() function is used compute the 3D max pooling.



Syntax:

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

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



Return Value: It returns the 3D max pooling of the tensor’s elements.

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let pool = tf.tensor5d([11, 12, 13, 14], [2, 1, 1, 1, 2]);
  
// Calling the .maxPool3d()
let output = tf.maxPool3d(pool, 1, 2, 'valid');
  
// Printing the output.
output.print();

Output:

Tensor
    [ [ [ [[11, 12],]]],

      [ [ [[13, 14],]]]]

Example 2:




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

Output:

Tensor
     [ [ [ [[54.5],]]]]

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

Article Tags :