Tensorflow.js tf.layers computeOutputShape() Method
Last Updated :
22 Apr, 2022
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .computeOutputShape() function is used to enumerate the output shape of the stated layer. And it presumes that the layer will be created in order to match the supplied input shape.
Syntax:
computeOutputShape(inputShape)
Parameters:
- inputShape: It is the stated shape i.e. set of integers or a list of sets of shape. Moreover the Shape tuples can contain void in favor of free sizes, in place of an integer. It can of type ((null | number)[]|(null | number)[][]).
Return Value: It returns (null | number)[]|(null | number)[][].
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [3]}));
const inputShape = [6, 2, 6];
const val = model.layers[0].computeOutputShape(inputShape);
console.log(val);
|
Output:
6,2,1
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [3]}));
model.add(tf.layers.dense({units: 5}));
const inputShape1 = [6, 2, 6, null ];
const inputShape2 = [6.5, 2.6, 9.1, NaN];
const val1 = model.layers[0].computeOutputShape(inputShape1);
const val2 = model.layers[1].computeOutputShape(inputShape2);
console.log(val1);
console.log(val2);
|
Output:
6,2,6,1
6.5,2.6,9.1,5
Reference: https://js.tensorflow.org/api/latest/#tf.layers.Layer.computeOutputShape
Share your thoughts in the comments
Please Login to comment...