Open In App

Tensorflow.js tf.layers.maximum() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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 Node.js.

The tf.layers.maximum() function is used to calculate maximum of every element when multiple arrays are provided as inputs.

Syntax:

tf.layers.maximum().apply([input1,input2,...... , inputn])

Parameters

  • inputShape : It is an optional parameter which is used to create the input layer and it take values like number and null.
  • batchInputShape : It is an optional parameter which is used to create the input layer before the main layer and it take values like number and null.
  • batchSize : It is an optional parameter used to make batchInputShape and it accepts only numbers.
  • dtype : It is an optional parameter and it stands for data type. By default it has ‘float32’ and also supports other values like ‘int32’, ‘bool’ etc.
  • name: It is an optional parameter and is used to define the name of the layer and it accepts strings.
  • trainable : It is an optional parameter that determines the provided input layers are updated or not. It accepts boolean values.
  • weights : It possesses the starting weights of the layer. It is also a optional parameter.
  • inputDType : It is an optional parameter used for input data type. Like dtype it also supports all its values.

Return Value: It returns maximum.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
const input1 = tf.input({shape: [3, 3]});
const input2 = tf.input({shape: [3, 3]});
const maximumLayer = tf.layers.maximum();
const maximum = maximumLayer.apply([input1, input2]);
console.log(JSON.stringify(maximum.shape));


Output:

[null,3,3]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
const input1 = tf.input({shape: [4, 4]});
const input2 = tf.input({shape: [4, 4]});
const input3 = tf.input({shape: [4, 4]});
const input4 = tf.input({shape: [4, 4]});
const input5 = tf.input({shape: [4, 4]});
const input6 = tf.input({shape: [4, 4]});
const maximumLayer = tf.layers.maximum();
const maximum = maximumLayer.apply([input1,
    input2, input3, input4, input5, input6]);
 
console.log(JSON.stringify(maximum.shape));


Output:

[null,4,4]

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



Last Updated : 14 Oct, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads