我想分析一个非常简单的神经网络模型的 FLOPs,用于对 MNIST 数据集进行分类,批量大小为 128。按照官方教程,我得到了以下模型的结果,但我无法理解部分输出。
w1 = tf.Variable(tf.random_uniform([784, 15]), name='w1')
w2 = tf.Variable(tf.random_uniform([15, 10]), name='w2')
b1 = tf.Variable(tf.zeros([15, ]), name='b1')
b2 = tf.Variable(tf.zeros([10, ]), name='b2')
hidden_layer = tf.add(tf.matmul(images_iter, w1), b1)
logits = tf.add(tf.matmul(hidden_layer, w2), b2)
loss_op = tf.reduce_sum(\
tf.nn.softmax_cross_entropy_with_logits(logits=logits,
labels=labels_iter))
opetimizer = tf.train.AdamOptimizer(learning_rate=0.01)
train_op = opetimizer.minimize(loss_op)
theimages_iter
和 thelabels_iter
是 tf.data 的迭代器,类似于占位符。
tf.profiler.profile(
tf.get_default_graph(),
options=tf.profiler.ProfileOptionBuilder.float_operation())
我使用此代码(相当于scope -min_float_ops 1 -select float_ops -account_displayed_op_only
tfprof 注释行工具中的代码)来分析 FLOP 并得到以下结果。
Profile:
node name | # float_ops
_TFProfRoot (--/23.83k flops)
random_uniform (11.76k/23.52k flops)
random_uniform/mul (11.76k/11.76k flops)
random_uniform/sub (1/1 flops)
random_uniform_1 (150/301 flops)
random_uniform_1/mul (150/150 flops)
random_uniform_1/sub (1/1 flops)
Adam/mul (1/1 flops)
Adam/mul_1 (1/1 flops)
softmax_cross_entropy_with_logits_sg/Sub (1/1 flops)
softmax_cross_entropy_with_logits_sg/Sub_1 (1/1 flops)
softmax_cross_entropy_with_logits_sg/Sub_2 (1/1 flops)
我的问题是
- 括号里的数字是什么意思?例如
random_uniform_1 (150/301 flops)
,什么是 150 和 301? - 为什么_TFProfRoot括号中的第一个数字是“--”?
- 为什么 Adam/mul 和 softmax_cross_entropy_with_logits_sg/Sub 的 flop 是 1?
我知道读这么久的问题令人沮丧,但是一个无法从官方文档中找到相关信息的绝望男孩需要你们的帮助。