Tensorflow.js tf.LayersModel class .summary() Method
The tf.LayersModel is a class used for training, inference, and evaluation of layers model in tensorflow.js. It contains methods for training, evaluation, prediction, and for saving of layers model purposes. So in this post, we are going to know about the model.summary() function.
The model.summary() function in tensorflow.js prints the summary for the model it includes the name of the model, numbers of weight parameters, numbers of trainable parameters.
model_name.summary (line length, position, print function)
Parameters: All the parameters are optional.
- line length: It is a custom line length in a number of characters.
- position: It is an array that showing widths for each column, values can be fractional or absolute.
- print function: function which is printing the summary for model, default function is console.log().
Example 1: In this example, we are going to create the sequential model with single dense layers and printing the summary for the model using model.summary() function.
_________________________________________________________________ Layer (type) Output shape Param # ================================================================= dense_Dense8 (Dense) [null,10] 160 ================================================================= Total params: 160 Trainable params: 160 Non-trainable params: 0 _________________________________________________________________
Example 2: In this example, we are going to create the model with 2 dense layers having activation function relu and softmax using tf.model method and making predictions also printing the summary for the model.
Prediction : Tensor [[0.2074656, 0.1515629, 0.2641615, 0.2237201, 0.1530899], [0.2074656, 0.1515629, 0.2641615, 0.2237201, 0.1530899], [0.2074656, 0.1515629, 0.2641615, 0.2237201, 0.1530899]] Summary : _________________________________________________________________ Layer (type) Output shape Param # ================================================================= input7 (InputLayer) [null,8] 0 _________________________________________________________________ dense_Dense19 (Dense) [null,7] 63 _________________________________________________________________ dense_Dense20 (Dense) [null,5] 40 ================================================================= Total params: 103 Trainable params: 103 Non-trainable params: 0 _________________________________________________________________