Skip to content
Related Articles

Related Articles

Tensorflow.js tf.maxPool3d() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 12 May, 2021
View Discussion
Improve Article
Save Article

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:

  • x: This specifies the input tensor of rank 5 or rank 4.
  • filterSize: This specifies filterDepth, filterHeight, filterWidth. If the specified filterSize is a single number, then filterWidth == filterHeight == filterDepth.
  • strides: The specifies the strides of the pooling: [strideDepth, strideHeight, strideWidth]. If the specified strides is a single number, then strideWidth == strideHeight ==strideDepth .
  • pad: This specifies the type of the padding algorithm.
  • dimRoundingMode: This is optional. This specifies a string from: ‘ceil’, ’round’, ‘floor’. If nothing is provided, then it will default its value to truncate.
  • dataFormat: This is optional. This specifies the data format of the output and input data.

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

Example 1:

Javascript




// 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:

Javascript




// 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!