时间轴跟踪TensorFlow会话的常规做法如下:
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)
但是现在我正在使用tf.estimator
,而没有显式定义会话。
那么我应该如何以及何时定义和使用tensorflow.python.client.timeline
?
答案 0 :(得分:1)
尝试一下:
hook = tf.train.ProfilerHook(save_steps=100, output_dir='/tmp/')
classifier.train(
input_fn=lambda: ltr_dataset.csv_input_fn(train_file_list, args.batch_size)
,hooks=[hook]
)