我使用了Timeline
对象来获取图中每个节点的执行时间:
- 您使用经典的
sess.run()
,还指定了可选参数options
和run_metadata
- 然后使用
run_metadata.step_stats
数据创建一个Timeline
对象
这是一个测量矩阵乘法性能的示例程序:
import tensorflow as tf
from tensorflow.python.client import timeline
x = tf.random_normal([1000, 1000])
y = tf.random_normal([1000, 1000])
res = tf.matmul(x, y)
# Run the graph with full trace option
with tf.Session() as sess:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
sess.run(res, options=run_options, run_metadata=run_metadata)
# Create the Timeline object, and write it to a json
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(ctf)
然后,您可以打开Google Chrome浏览器,转到chrome://tracing
页面并加载timeline.json
文件。您应该看到类似以下内容:
0
我知道我可以测量对
sess.run()
的调用的执行时间,但是是否可以获得更好的粒度并测量单个操作的执行时间?