简体   繁体   English

将 Tensorflow 分析器与 tf.Estimator 结合使用

[英]Using the Tensorflow profiler with tf.Estimator

I need to use the Tensorflow profiler to profile some code that is running slowly for some reason.我需要使用 Tensorflow 分析器来分析一些由于某种原因运行缓慢的代码。 Unfortunately, the code in question uses tf.Estimator, so I can't figure out how to inject the run metadata object into the session run() call in order to get the information that the profiler needs.不幸的是,有问题的代码使用了 tf.Estimator,所以我无法弄清楚如何将运行元数据对象注入会话 run() 调用中以获取分析器需要的信息。

What should I do?我该怎么办?

tf.estimator use tf.train.ProfilerHook works! tf.estimator使用tf.train.ProfilerHook工作!

just add a ProfilerHook in TrainSpec hooks!只需在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())

then, you could get the tracing file like timeline-{}.json in model_dir/tracing , and open chrome chrome://tracing to visual!然后,您可以在model_dir/tracing获取诸如timeline-{}.json类的跟踪文件,并打开 chrome chrome://tracing以进行可视化!

refs: https://stackoverflow.com/a/48278275/6494418参考文献: https : //stackoverflow.com/a/48278275/6494418

with tf.contrib.tfprof.ProfileContext('/tmp/train_dir', dump_steps=[10]) as pctx: estimator.train() # any thing you want to profile

Then you will get a file at /tmp/train_dir/profile_10然后你会在/tmp/train_dir/profile_10得到一个文件

Arguments are defined in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py参数在https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/profiler/profile_context.py中定义

Use ProfileContext, as described here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler .使用 ProfileContext,如下所述: https : //github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler This allows you to profile without needing to get access to the session.这使您无需访问会话即可进行概要分析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用tensorflow tf.estimator提前停止? - Early stopping using tensorflow tf.estimator ? 使用tf.Estimator创建的tensorflow上的图优化 - Graph optimizations on a tensorflow serveable created using tf.Estimator tensorflow:使用tf.estimator和keras进行词汇查询 - tensorflow: vocabulary lookup with tf.estimator and keras Tensorflow,在另一个tf.estimator model_fn中使用经过tf.estimator训练的模型 - Tensorflow, use a tf.estimator trained model within another tf.estimator model_fn 如何在Tensorflow中的tf.estimator上使用tensorflow调试工具tfdbg? - How to use tensorflow debugging tool tfdbg on tf.estimator in Tensorflow? Tensorflow-Python-是否可以使用tf.Estimator冻结图而不包含“ RandomShuffleQueueV2”和“ QueueDequeueMany”节点? - Tensorflow-Python - Is it possible to freeze a graph using tf.Estimator without including the “RandomShuffleQueueV2” and the “QueueDequeueMany” nodes? Tensorflow:有没有办法在 tf.Estimator 中存储训练损失 - Tensorflow: Is there a way to store the training loss in tf.Estimator 张量流馈送列表功能(多热)到tf.estimator - tensorflow feed list feature (multi-hot) to tf.estimator TensorFlow:tf.Estimator模型的输入节点是什么 - TensorFlow: What are the input nodes for tf.Estimator models Tensorflow-如何为tf.Estimator()CNN使用GPU而不是CPU - Tensorflow - How to use the GPU instead of a CPU for tf.Estimator() CNNs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM