[英]Using the Tensorflow profiler with tf.Estimator
我需要使用 Tensorflow 分析器来分析一些由于某种原因运行缓慢的代码。 不幸的是,有问题的代码使用了 tf.Estimator,所以我无法弄清楚如何将运行元数据对象注入会话 run() 调用中以获取分析器需要的信息。
我该怎么办?
tf.estimator
使用tf.train.ProfilerHook
工作!
只需在TrainSpec
钩子中添加一个ProfilerHook
!
hook = tf.train.ProfilerHook(
save_steps=20,
output_dir=os.path.join(args.model_dir, "tracing"),
show_dataflow=True,
show_memory=True)
hooks = [hook]
train_spec = tf.estimator.TrainSpec(
hooks=hooks,
input_fn=lambda: input_fn())
然后,您可以在model_dir/tracing
获取诸如timeline-{}.json
类的跟踪文件,并打开 chrome chrome://tracing
以进行可视化!
with tf.contrib.tfprof.ProfileContext('/tmp/train_dir', dump_steps=[10]) as pctx: estimator.train() # any thing you want to profile
然后你会在/tmp/train_dir/profile_10
得到一个文件
参数在https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py中定义
使用 ProfileContext,如下所述: https : //github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler 。 这使您无需访问会话即可进行概要分析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.