Saturday, November 23, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.Sequential class .summary() Method

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:  

  • lineLength: It is the stated custom line length, in the list of characters. It is optional and is of type number.
  • positions: It is the stated custom size of all the columns, like either fractions of lineLength i.e. [0.25, 0.5, 0.75] or else absolute list of characters i.e. [20, 40, 55]. Here, each and every number belongs to the closing i.e. right-hand position of the stated column. It is optional and is of type number[].
  • printFn: It is the stated custom print function which is utilized to substitute the default value which is console.log. It is optional parameter.

Return Value: It returns void.

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

Javascript




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

Javascript




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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments