运行Tensorflow单元测试

时间:2015-12-10 14:35:07

标签: unit-testing tensorflow testing bazel

有没有办法手动运行Tensorflow单元测试?我想在修改TF源代码时执行完整性检查。

我看到有很多_test.py文件,其中的类执行许多测试操作,我无法弄清楚如何运行它们。应该有一个简单的方法吗?

2 个答案:

答案 0 :(得分:28)

运行TensorFlow单元测试的最简单方法是使用Bazel,假设您有downloaded the source from Git

# All tests (for C++ changes).
$ bazel test //tensorflow/...

# All Python tests (for Python front-end changes).
$ bazel test //tensorflow/python/...

# All tests (with GPU support).
$ bazel test -c opt --config=cuda //tensorflow/...
$ bazel test -c opt --config=cuda //tensorflow/python/...

答案 1 :(得分:1)

除了上述答案外,您还可以运行如图所示的单个测试,而不是完整的软件包,这样可以节省大量时间。

bazel run //tensorflow/python/kernel_tests:string_split_op_test

bazel run //tensorflow/python:special_math_ops_test

或者您可以转到单个目录并在那里运行所有测试

cd python/kernel_tests
bazel run :one_hot_op_test