TensorFlow Estimator 跟踪时间表?
TensorFlow Estimator tracking timeline?
跟踪 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
?
试试这个:
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]
)
跟踪 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
?
试试这个:
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]
)