我想计算变量的数量和模型的浮点运算次数。但是,tf.contrib.tfprof.model_analyzer.print_model_analysis
似乎在run_meta
提供时忽略了第一个节点。
例如,(使用tensorflow 1.0.0进行测试)
import numpy as np
import tensorflow as tf
slim = tf.contrib.slim
x = tf.placeholder(tf.float32, [None, 7, 7, 3])
c1 = slim.conv2d(x, 22, [3, 3])
run_metadata = tf.RunMetadata()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
_ = sess.run(c1, feed_dict={x: np.zeros([1, 7, 7, 3])},
options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
run_metadata=run_metadata)
analysis = tf.contrib.tfprof.model_analyzer.print_model_analysis(
tf.get_default_graph(), run_meta=run_metadata,
tfprof_options=tf.contrib.tfprof.model_analyzer.FLOAT_OPS_OPTIONS)
# 1078
print(analysis.total_float_ops)
它仅包含Conv/BiasAdd
的浮点运算数。如何使用tfprog
正确分析模型?