我试图修改this tutorial来编译用于C ++的TensorFlow网络。它目前要求您将网络文件复制到TensorFlow源代码中,以便找到依赖关系,但我宁愿不这样做。请注意,TensorFlow也是使用Bazel构建的。
这是我的BUILD
文件:
cc_binary(
name = "mnistpredict_keras",
srcs = ["mnist_keras.cc", "MNIST.h"],
deps = [
"//tensorflow/core:tensorflow",
],
)
当我尝试运行$ bazel build :mnistpredict_keras
时,我收到错误:
ERROR: /home/saubin/git/tf-keras-speed-test/loadgraph/BUILD:17:1: no such package 'tensorflow/core': BUILD file not found on package path and referenced by '//:mnistpredict_keras'.
ERROR: Analysis of target '//:mnistpredict_keras' failed; build aborted.
INFO: Elapsed time: 0.105s
显然,问题是我试图在我的文件夹~/git/tf-keras-speed-test/loadgraph
中编译某些内容,但它无法找到依赖项//tensorflow/core:tensorflow
。我如何正确地给出依赖的路径? deps
的文档似乎不存在。
向local_repository
添加WORKSPACE
:
local_repository(
name = "tensorflow",
path = "/home/saubin/src/tensorflow",
)
这没有改变。
尝试传递完整路径:
cc_binary(
name = "mnistpredict_keras",
srcs = ["mnist_keras.cc", "MNIST.h"],
deps = [
"/home/saubin/src/tensorflow/tensorflow/core:tensorflow",
],
)
但是我得到了同样的错误:
ERROR: /home/saubin/git/tf-keras-speed-test/loadgraph/BUILD:17:1: no such package 'tensorflow/core': BUILD file not found on package path and referenced by '//:mnistpredict_keras'.
ERROR: Analysis of target '//:mnistpredict_keras' failed; build aborted.
INFO: Elapsed time: 0.287s
将TensorFlow标记为external repository dependency:
cc_binary(
name = "mnistpredict_keras",
srcs = ["mnist_keras.cc", "MNIST.h"],
deps = [
"@tensorflow//tensorflow/core:tensorflow",
],
)
但这给了我这个错误:
WARNING: /home/saubin/.cache/bazel/_bazel_saubin/74f664e7cf53364557da8b57a716c919/external/tensorflow/WORKSPACE:1: Workspace name in /home/saubin/.cache/bazel/_bazel_saubin/74f664e7cf53364557da8b57a716c919/external/tensorflow/WORKSPACE (@org_tensorflow) does not match the name given in the repository's definition (@tensorflow); this will cause a build error in future versions.
ERROR: /home/saubin/git/tensorgraph/loadgraph/BUILD:1:1: error loading package '@tensorflow//tensorflow/core': Encountered error while reading extension file 'sycl/build_defs.bzl': no such package '@local_config_sycl//sycl': error loading package 'external': The repository named 'local_config_sycl' could not be resolved and referenced by '//:mnistpredict'.
ERROR: Analysis of target '//:mnistpredict' failed; build aborted.
INFO: Elapsed time: 0.326s
答案 0 :(得分:2)
外部依赖项的文档是https://bazel.build/versions/master/docs/external.html。
您要查找的语法是@tensorflow//tensorflow/core:tensorflow
。
以//
开头的标签引用当前存储库。以@reponame//
开头的标签指的是 reponame 存储库。