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:
- x: The specified 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 average Pooling of the tensor’s elements.
Below are the examples that illustrates the use of avgPool3d() function.
Example 1:
Javascript
// 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:
Javascript
// 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