Open In App

Tensorflow.js tf.pool() Function

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:



Return Value: It returns tf.Tensor3D or tf.Tensor4D.

Example 1:




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




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


Article Tags :