Open In App

Tensorflow.js tf.layers.maximum() 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 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



Return Value: It returns maximum.

Example 1:




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




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


Article Tags :