Tensorflow.js tf.pool() Function Last Updated : 27 May, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Introduction: Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .pool() function is used to execute an N-D pooling functioning. Syntax: tf.pool(input, windowShape, poolingType, pad, dilations?, strides?) Parameters: input: The stated input tensor which is either of rank 4 or else rank 3 and of shape: [batch, height, width, inChannels]. Moreover, in case the rank is 3, then the batch of size 1 is presumed. It can be of type tf.Tensor3D, tf.Tensor4D, TypedArray, or Array.windowShape: The stated filter size: [filterHeight, filterWidth]. It can be of type [number, number], or number. In case, filterSize is a singular number, then filterHeight == filterWidth.poolingType: The stated type of pooling, it can be either 'max' or 'avg'.pad: The stated type of algorithm for padding. It can be of type valid, same, number, or conv_util.ExplicitPadding.Here, for same and stride 1, the output would have identical size as input, irrespective of the filter size.For, 'valid' the output shall be smaller than the input in case, the filter size is larger than 1*1x1.dilations: The stated dilation rates: [dilationHeight, dilationWidth] in that the input values are sampled over the height as well as width dimensions in dilated pooling. The by default value is [1, 1]. Moreover, in case dilations is a single number, then dilationHeight == dilationWidth. And if its greater than 1, then all the values of the strides should be 1. It is optional and is of type [number, number], number.strides: The stated strides of the pooling: [strideHeight, strideWidth]. In case, strides is a singular number, then strideHeight == strideWidth. It is optional and is of type [number, number], or number. Return Value: It returns tf.Tensor3D or tf.Tensor4D. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining input tensor const x = tf.tensor3d([1, 2, 3, 4], [2, 2, 1]); // Calling pool() method const result = tf.pool(x, 3, 'avg', 'same', [1, 2], 1); // Printing output result.print(); Output: Tensor [[[0.4444444], [0.6666667]], [[0.4444444], [0.6666667]]] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling pool() method tf.tensor3d([1.2, 2.1, 3.0, -4], [2, 2, 1]).pool(3, 'conv_util.ExplicitPadding', 1, 1).print(); Output: Tensor [[[3], [3]], [[3], [3]]] Reference: https://js.tensorflow.org/api/latest/#pool Comment More infoAdvertise with us Next Article Tensorflow.js tf.pad() Function N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads 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?, d 2 min read Tensorflow.js tf.model() Function Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.model() function is used to create a model which contains layers and layers that are provided in form of input a 2 min read Tensorflow.js tf.pad() 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 in Node.js. The tf. 2 min read Tensorflow.js tf.oneHot() 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.oneHot() function is used to create a one-hot tf.Tensor. The locations represented by indices take the value as 1 (default valu 2 min read Tensorflow.js tf.ones() Function Tensorflow.js is an open-source library for running machine learning models and deep learning neural networks in the browser or node environment. The tf.ones() function is used to create a new tensor where all elements are set to 1. Syntax: tf.ones(shape, dtype, name) Parameters: shape: It takes the 2 min read Tensorflow.js tf.keep() Function Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .keep() function is used to hold a tensor input that is formed within a tf.tidy() method from being spontaneously d 1 min read Like