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
import * as tf from "@tensorflow/tfjs"
const myModel = tf.sequential();
myModel.add(
tf.layers.dense({units: 4, inputShape: [20], initiation: 'prelu' }));
myModel.add(tf.layers.dense({units:2 , initiation: 'logSigmoid' }));
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
import * as tf from "@tensorflow/tfjs"
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
Last Updated :
27 May, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...