📜  Tensorflow.js tf.Sequential 类 .summary() 方法

📅  最后修改于: 2022-05-13 01:56:33.553000             🧑  作者: Mango

Tensorflow.js tf.Sequential 类 .summary() 方法

Tensorflow.js 是由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

tensorflow.js 中的 .summary ()函数用于打印文本摘要,以支持顺序模型的层。此外,它包括名称以及包括模型在内的每一层的类型、层的输出配置、每一层的权重参数的计数、可训练加非可训练的绝对计数- 所述模型的可训练参数。

句法:

summary(lineLength?, positions?, printFn?)

参数:

  • lineLength:它是在字符列表中规定的自定义行长度。它是可选的,类型为 number。
  • 位置:它是所有列的规定自定义大小,如lineLength的任一部分,即 [0.25, 0.5, 0.75] 或绝对字符列表,即 [20, 40, 55]。在这里,每个数字都属于所述列的结束,即右手位置。它是可选的,类型为 number[]。
  • printFn:它是声明的自定义打印函数,用于替换默认值console.log 。它是可选参数。

返回值:返回void。

示例 1:不带任何参数调用 summary() 方法。

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();


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]});


输出:

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

示例 2:使用其参数调用 summary() 方法。

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]});

输出:

Layer (type Output shap Param #

dense_Dense189 (Dense [null,7 49

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

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