【问题标题】:Debug tensorflow unit tests调试 tensorflow 单元测试
【发布时间】:2016-10-13 03:35:57
【问题描述】:

我找到了link,它显示了如何运行单元测试。

而且我认为通过调试单元测试可以更好地理解源代码。

我可以在 tensorflow python 应用程序运行时调试源代码。但我不知道如何调试单元测试。我是 bazel 和 gdb 调试的新手。

【问题讨论】:

  • 每个“bazel 测试”本质上都在 bazel-bin 下运行相应的二进制文件,因此您可以在 gdb 下直接运行该二进制文件
  • @YaroslavBulatov 谢谢,但我找不到测试文件的位置。例如,common_shape_fns_test.cc,我搜索common_shape_fns_test.cc 字符串并在BUILD 文件中找到它。然后我找不到任何提示。
  • 现在我知道我应该先构建它:bazel build //tensorflow/core:framework_common_shape_fns_test。然后我可以运行它:bazel-bin/tensorflow/core/framework_common_shape_fns_test

标签: python c++ machine-learning gdb tensorflow


【解决方案1】:

总结一下:

  • 您必须确保首先构建测试二进制文件:通过运行bazel test <target> 或使用bazel build <target> 或使用bazel build -c dbg <target>。最后一个提供完全可调试的可执行文件,在 gdb 回溯中为您提供行号。
  • 二进制文件与 BUILD 文件位于同一目录中(即,如果您有 tensorflow/core/BUILD,则二进制文件将在 bazel-bin/tensorflow/core 下)
  • 您可以使用 bazel 查询找到包含给定 .cc 文件的 bazel 名称。 IE,对于common_shape_fns_test,您可以使用以下命令找到目标名称为//tensorflow/core:framework_common_shape_fns_test

.

fullname=$(bazel query tensorflow/core/framework/common_shape_fns_test.cc)
bazel query "attr('srcs', $fullname, ${fullname//:*/}:*)"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 2017-05-09
    • 2013-05-08
    • 2015-08-25
    • 2011-07-31
    相关资源
    最近更新 更多