TensorFlow:如何启动Profiler

时间:2018-11-26 12:30:02

标签: tensorflow profiling

我想分析我的模型。这是有关如何执行此操作的教程:https://towardsdatascience.com/howto-profile-tensorflow-1a49fb18073d。但是我想使用TensorFlow分析器,如https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/profiler/README.md#quick-start所示。根据这篇文章,以下代码应启动事件探查器:

from math import log10

L = [56, 2131]

def sum_of_digits_sorted(L):
    def summer(x):
        return sum(x // 10**i % 10 for i in range(int(log10(x))+1))
    return sorted(L, key=summer)

print(sum_of_digits_sorted(L))

[2131, 56]

我生成了文件profile_100并找到了目录分析器。这就是我在终端中输入的内容:

# When using high-level API, session is usually hidden.
#
# Under the default ProfileContext, run a few hundred steps.
# The ProfileContext will sample some steps and dump the profiles
# to files. Users can then use command line tool or Web UI for
# interactive profiling.
with tf.contrib.tfprof.ProfileContext('/tmp/train_dir') as pctx:
  # High level API, such as slim, Estimator, etc.
  train_loop()

bazel-bin/tensorflow/core/profiler/profiler \
--profile_path=/tmp/train_dir/profile_xx
tfprof> op -select micros,bytes,occurrence -order_by micros

# To be open sourced...
bazel-bin/tensorflow/python/profiler/profiler_ui \
--profile_path=/tmp/profiles/profile_1

这引发了以下错误:

bazel-/Users/mencia/anaconda/envs/tensorflow_py36/lib/python3.6/site-packages/tensorflow/profiler \ 
--profile_path=~/tmp/train_dir/profile_100

我的目录分析器包含:

-bash: 
bazel-/Users/mencia/anaconda/envs/tensorflow_py36/lib/python3.6/site- packages/tensorflow/profiler: No such file or directory

但是根据上面的代码,应该有

__init__.py
__pycache__

我没有。

我该如何启动Profiler?

1 个答案:

答案 0 :(得分:1)

您必须先构建探查器。克隆TensorFlow仓库(git clone https://github.com/tensorflow/tensorflow.git)并在根目录中运行bazel build --config opt tensorflow/core/profiler:profiler