Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.layers.minimum() Function

  • Last Updated : 21 May, 2021
Geek Week

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.

The tf.layers.minimum() function is used to create a layer that is used to compute the element-wise minimum of an Array of inputs. It takes as input a list of tensors, having the same shape.

Syntax:

tf.layers.minimum (args)

Parameters:

It takes as input an object: args (Object). It is optional to provide args object as input. Following are the fields you can provide in the args object.



  • inputShape ((null or number)[]): creates an input layer that is inserted before this layer.
  • batchInputShape ((null or number)[]): has the same purpose as the above parameter but if both input shape and batchInputShape are defined, batchInputShape will be preferred.
  • batchSize (number): if both the above parameters are not specified, batch Size is used to construct the batchInputShape.
  • dtype : the data type of the layer. Eg: float32, int32, etc.
  • name (string): it is used to give a name to the layer.
  • weights (tf.Tensor[]): it provides initial weight values.
  • trainable (boolean): it is used to specify whether the weights are updatable by fit. The default value is true.

Return Value: It returns element-wise minimum.

Example 1:

Javascript




const tf = require("@tensorflow/tfjs")
  
// providing input
const x = tf.input({shape: [4, 4, 4]});
const y = tf.input({shape: [4, 4, 4]});
  
// creating required layer
const minimumLayer = tf.layers.minimum();
const minimum = minimumLayer.apply([x, y]);
console.log(minimum.shape);

Output:

[ null, 4, 4, 4 ]

Example 2:

In this example, we will provide the args object as input with the fields of name and trainable.

Javascript




const tf = require("@tensorflow/tfjs")
  
// providing input
const x = tf.input({shape: [5, 5, 5]});
const y = tf.input({shape: [5, 5, 5]});
const z = tf.input({shape: [5, 5, 5]});
  
// creating required layer
const minimumLayer = tf.layers.minimum({name:"layer1", trainable:false});
const minimum = minimumLayer.apply([x, y, z]);
console.log(minimumLayer.name)
console.log(minimumLayer.trainable)
console.log(minimumLayer.shape);

Output:

layer1
false
[ null, 5, 5, 5 ]

Reference: https://js.tensorflow.org/api/latest/#minimum

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :