Open In App

Tensorflow.js tf.Sequential class .summary() Method

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 .summary() function in tensorflow.js is used to print a text summary in favor of the sequential model’s layers. Moreover, it consists of the name as well as the type of each and every layers that include the model, the output configuration(s) of the layers, the counts of weight parameters of each and every layer, the absolute counts of trainable plus non-trainable parameters of the stated model.



Syntax:  

summary(lineLength?, positions?, printFn?)

Parameters:  



Return Value: It returns void.

Example 1: Calling summary() method without any parameter.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Defining model
const myModel = tf.sequential();
 
// Calling add() method to add layers
myModel.add(
     tf.layers.dense({units: 4, inputShape: [20], initiation: 'prelu'}));
myModel.add(tf.layers.dense({units:2 , initiation: 'logSigmoid'}));
 
// Calling summary method and
// Printing output
myModel.summary();

Output:

_________________________________________________________________
Layer (type)                 Output shape              Param #   
=================================================================
dense_Dense121 (Dense)       [null,4]                  84        
_________________________________________________________________
dense_Dense122 (Dense)       [null,2]                  10        
=================================================================
Total params: 94
Trainable params: 94
Non-trainable params: 0
_________________________________________________________________

Example 2: Calling summary() method with its parameters.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Calling summary method with its
// parameters and printing output
 tf.sequential({
    layers:[tf.layers.dense({units: 7, inputShape: [6]})]
 }).summary({lineLength: 4}, {positiions: [1, 2, 4]});

Output:

Layer (type) Output shape Param #

dense_Dense189 (Dense) [null,7] 49

Total params: 49
Trainable params: 49
Non-trainable params: 0

Reference: https://js.tensorflow.org/api/latest/#tf.Sequential.summary


Article Tags :