Open In App

Tensorflow.js tf.layers.maxPooling3d() Function

Last Updated : 04 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js.

The tf.layers.maxPooling3d() function is used to apply max pooling operation on 3D data.

Syntax: 

tf.layers.maxPooling3d(args)

Parameters:

  • args: It is the object which can have the following properties:
    • poolSize: It is used for downscaling factors in each dimension i.e [depth, height, width]. It is an integer or an array of three integers is expected. 
    • strides: In each dimension of the pooling window, the stride size. It is an integer or an array of three integers is required. 
    • padding: The padding type to utilize for the pooling layer.
    • dataFormat: The data format to utilize for the pooling layer. 
    • inputShape: If it is specified then, it will be utilized to construct an input layer that will be inserted before this layer. 
    • batchInputShape: If it is specified it will be used for creating an input layer which will be inserted before this layer.
    • batchSize: It supports the inputShape to build the batchInputShape.
    • dtype: It is the kind of data type for this layer. This parameter applies exclusively to input layers.
    • name: It is of string type. It is the name of this layer.
    • trainable: If it is set to be true then only the weights of this layer will be changed by fit.
    • weights: The layer’s initial weight values.
    • inputDType: It is used for Legacy support.

Returns: It returns MaxPooling3D

Example 1:

Javascript




import * as tf from "@tensorflow/tfjs";
  
const input = tf.input({ shape: [3, 2, 4, 3] });
const maxPoolingLayer = tf.layers.maxPooling3d(
    { poolSize: [2, 2,4], 
    strides:[3, 4, 5], 
    padding: 'valid' });
const output = maxPoolingLayer.apply(input);
  
const model = tf.model({ inputs: input, outputs: output });
model.summary();


Output:

__________________________________________________________________________________________
Layer (type)                Input Shape               Output shape              Param #   
==========================================================================================
input44 (InputLayer)        [[null,3,2,4,3]]          [null,3,2,4,3]            0         
__________________________________________________________________________________________
max_pooling3d_MaxPooling3D4 [[null,3,2,4,3]]          [null,1,1,1,3]            0         
==========================================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
__________________________________________________________________________________________

Example 2:

Javascript




import * as tf from "@tensorflow/tfjs";
const input = tf.input({ shape: [2, 2, 4,5] });
const maxPoolingLayer =    tf.layers.maxPooling3d({ poolSize: [2, 2,4] 
                              ,strides:[3, 4, 5], padding: 'valid' });
const output = maxPoolingLayer.apply(input);
const model = tf.model({ inputs: input, outputs: output });
const x = tf.ones([2, 2, 2, 4,5]);
model.predict(x).print();


Output:

Tensor
    [[[[[1, 1, 1, 1, 1],]]],
      [[[[1, 1, 1, 1, 1],]]]]

Reference: https://js.tensorflow.org/api/latest/#layers.maxPooling3d



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads