# Tensorflow.js tf.layers computeOutputShape() Method

• Last Updated : 27 Jul, 2021

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.

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!

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

 `// Importing the tensorflow.js library``import * as tf from ``"@tensorflow/tfjs"`` ` `// Creating a model``const model = tf.sequential();`` ` `// Adding a layer``model.add(tf.layers.dense({units: 1, inputShape: }));`` ` `// Defining inputShape``const inputShape = [6, 2, 6];`` ` `// Calling computeOutputShape() method with its ``// parameter``const val = model.layers.computeOutputShape(inputShape);`` ` `// Printing output``console.log(val);`

Output:

`6,2,1`

Example 2:

## Javascript

 `// Importing the tensorflow.js library``import * as tf from ``"@tensorflow/tfjs"`` ` `// Creating a model``const model = tf.sequential();`` ` `// Adding layers``model.add(tf.layers.dense({units: 1, inputShape: }));``model.add(tf.layers.dense({units: 5}));`` ` `// Defining inputShape``const inputShape1 = [6, 2, 6, ``null``];``const inputShape2 = [6.5, 2.6, 9.1, NaN];`` ` ` ` `// Calling computeOutputShape() method with its ``// parameter``const val1 = model.layers.computeOutputShape(inputShape1);``const val2 = model.layers.computeOutputShape(inputShape2);`` ` `// Printing output``console.log(val1);``console.log(val2);`

Output:

```6,2,6,1
6.5,2.6,9.1,5```

My Personal Notes arrow_drop_up