我能得到的最接近的例子是在这个问题中找到的: https ://github.com/tensorflow/tensorflow/issues/899
使用这个最小的可重现代码:
import tensorflow as tf
import tensorflow.python.framework.ops as ops
g = tf.Graph()
with g.as_default():
A = tf.Variable(tf.random_normal( [25,16] ))
B = tf.Variable(tf.random_normal( [16,9] ))
C = tf.matmul(A,B) # shape=[25,9]
for op in g.get_operations():
flops = ops.get_stats_for_node_def(g, op.node_def, 'flops').value
if flops is not None:
print 'Flops should be ~',2*25*16*9
print '25 x 25 x 9 would be',2*25*25*9 # ignores internal dim, repeats first
print 'TF stats gives',flops
但是,返回的 FLOPS 始终为 None。有没有办法具体测量 FLOPS,尤其是 PB 文件?
原文由 kwotsin 发布,翻译遵循 CC BY-SA 4.0 许可协议
有点晚了,但也许它可以帮助将来的一些游客。对于您的示例,我成功测试了以下代码段:
也可以将探查器与
Keras
结合使用,如以下代码片段:我希望我能帮上忙!