Open In App

Tensorflow.js tf.layers.globalMaxPooling1d() Function

Last Updated : 12 Dec, 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.globalMaxPooling1d() function is used to apply Global max pooling operation for temporal data.

Syntax:

tf.layers.globalMaxPooling1d( args )

Parameters:

  • args: It accepts the object with the following properties:
    • inputShape: If this property is set, 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 support 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 GlobalMaxPooling1D.

Example 1:

Javascript




import * as tf from "@tensorflow/tfjs";
 
const Input = tf.input({ shape: [2, 5] });
const globalmaxPoolingLayer =
    tf.layers.globalMaxPooling1d(
        { dataFormat: 'channelFirst' }
    );
const Output = globalmaxPoolingLayer.apply(Input);
 
const Data = tf.ones([3, 2, 5]);
const model =
    tf.model({ inputs: Input, outputs: Output });
 
model.predict(Data).print();


Output:

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

Example 2:

Javascript




import * as tf from "@tensorflow/tfjs";
 
const Input = tf.input({ shape: [3, 5] });
 
const globalmaxPoolingLayer =
    tf.layers.globalMaxPooling1d({ dataFormat: 'channelLast' });
const Output = globalmaxPoolingLayer.apply(Input);
 
const model = tf.model({ inputs: Input, outputs: Output });
 
const Data =
    tf.tensor3d([2, 3, 5, 1, 3, 5, 8, 2, 2, 6, 8, 9, 4, 8, 9, 3,
                 8, 4, 2, 2, 9, 2, 4, 6, 4, 2, 6, 4, 2, 5 ],
                 [2, 3, 5]);
model.predict(Data).print();


Output:

Tensor
    [[8, 9, 5, 8, 9],
     [9, 8, 4, 6, 5]]

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads