使用 Bazel (Windows) 构建 Tensorflow 的问题 => 使用 Tensorflow C++ API
Issue building Tensorflow using Bazel (Windows) => to use Tensorflow C++ API
我最初的目标只是使用Tensorflow的C++ API来读取".pb"冻结模型并对其进行预测。正在使用 Keras 对其进行原型设计,设法冻结模型并在 Python 上使用 Tensorflow 进行尝试;一切都很顺利。 所以我基本上只需要 C++ API 即可工作。
我使用的是i5-8400T计算机,没有GPU,8GB内存。所有版本的bazel和tensorflow今天(27/08/2019(下载。
我做的第一件事当然是遵循 tensorflow 的指南。跑了小bazel run -c opt //tensorflow/cc/example:example
,那...几次。
第一次,需要将我的 bazel 版本降级到0.26.1
以使 TensorFlow 的configure.py
满意。
然后我遇到了与一些人显然相同的问题,这是一个获取io_bazel_rules_docker
的错误,然后当然会停止构建的其余部分。(以下是我在这里得到的输出(
bazel : INFO: Options provided by the client:
Au caractère Ligne:1 : 1
+ bazel run -c opt //tensorflow/cc/example:example > error.txt 2>&1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (INFO: Options provided by the client::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Inherited 'common' options: --isatty=0 --terminal_columns=80
INFO: Options provided by the client:
Inherited 'build' options: --python_path=C:/Users/IMEDSYS/AppData/Local/Programs/Python/Python37/python.exe
INFO: Reading rc options for 'run' from c:usersimedsysbintensorflow.bazelrc:
Inherited 'build' options: --apple_platform_type=macos --define framework_shared_object=true --define
open_source_build=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true
--spawn_strategy=standalone --strategy=Genrule=standalone -c opt --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
--announce_rc --define=grpc_no_ares=true --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib
--define=INCLUDEDIR=$(PREFIX)/include
INFO: Reading rc options for 'run' from c:usersimedsysbintensorflow.tf_configure.bazelrc:
Inherited 'build' options: --action_env
PYTHON_BIN_PATH=C:/Users/IMEDSYS/AppData/Local/Programs/Python/Python37/python.exe --action_env
PYTHON_LIB_PATH=C:/Users/IMEDSYS/AppData/Local/Programs/Python/Python37/lib/site-packages
--python_path=C:/Users/IMEDSYS/AppData/Local/Programs/Python/Python37/python.exe --config monolithic --copt=-w
--host_copt=-w --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN --copt=-DNOGDI --host_copt=-DNOGDI
--verbose_failures --distinct_host_configuration=false --action_env TF_CONFIGURE_IOS=0
INFO: Found applicable config definition build:monolithic in file c:usersimedsysbintensorflow.bazelrc: --define
framework_shared_object=false
Loading:
Loading: 0 packages loaded
INFO: Call stack for the definition of repository 'io_bazel_rules_docker' which is a git_repository (rule definition
at C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/bazel_tools/tools/build_defs/repo/git.bzl:252:18):
- C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/bazel_toolchains/repositories/repositories.bzl:37:9
- C:/users/imedsys/bin/tensorflow/WORKSPACE:35:1
ERROR: An error occurred during the fetch of repository 'io_bazel_rules_docker':
Traceback (most recent call last):
File "C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/bazel_tools/tools/build_defs/repo/git.bzl", line 234
_clone_or_update(ctx)
File "C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/bazel_tools/tools/build_defs/repo/git.bzl", line 74, in
_clone_or_update
fail(("error cloning %s:n%s" % (ctx....)))
error cloning io_bazel_rules_docker:
fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
/bin/bash: line 1: cd: C:/users/imedsys/_bazel_imedsys/wmdtvioi/external: No such file or directory
+ cd C:/users/imedsys/_bazel_imedsys/wmdtvioi/external
/bin/bash: line 3: cd: C:/users/imedsys/_bazel_imedsys/wmdtvioi/external: No such file or directory
+ git -C C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker reset --hard
251f6a68b439744094faff800cd029798edf9faa
fatal: cannot change to 'C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker': No such file or
directory
+ git -C C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker fetch '' origin
251f6a68b439744094faff800cd029798edf9faa:251f6a68b439744094faff800cd029798edf9faa
fatal: cannot change to 'C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker': No such file or
directory
+ git -C C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker fetch origin
251f6a68b439744094faff800cd029798edf9faa:251f6a68b439744094faff800cd029798edf9faa
fatal: cannot change to 'C:/users/imedsys/_bazel_imedsys/wmdtvioi/external/io_bazel_rules_docker': No such file or
directory
ERROR: ... *idem*
ERROR: ... *idem*
INFO: Elapsed time: 2.346s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
FAILED: Build did NOT complete successfully (0 packages loaded)
***
我尝试应用此问题提供的内容,其中包括转到rules_docker存储库并用最新的目标替换目标。
问题是,即使在这之后,你也会在 protobuf 目标中遇到同样类型的错误,如果我应用相同的策略,我会收到哈希错误。
然后我试着用CMake来做这件事,就像去年许多人说的那样,窗户上的bazel建筑还无法使用。我使用了两个类似的指南,其中一个在这里,因此尝试使用
cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=C:swigwin-3.0.12swig.exe -DPYTHON_EXECUTABLE=C:Anaconda3envstensorflowpython.exe -DPYTHON_LIBRARIES=C:Anaconda3envstensorflowlibspython35.lib
首先,然后
`cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=C:swigwin-3.0.12swig.exe -DPYTHON_EXECUTABLE=C:Anaconda3envstensorflowpython.exe -DPYTHON_LIBRARIES=C:Anaconda3envstensorflowlibspython35.lib -Dtensorflow_BUILD_PYTHON_BINDINGS=OFF -Dtensorflow_ENABLE_GRPC_SUPPORT=OFF -Dtensorflow_BUILD_SHARED_LIB=ON`
我得到这些错误:
cmake : CMake Warning at CMakeLists.txt:9 (message):
Au caractère Ligne:1 : 1
+ cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=C:Users ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CMake Warning a...xt:9 (message)::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Your current cmake generator is set to use 32 bit toolset architecture.
This may cause "compiler out of heap space" errors when building. Consider
using the flag -Thost=x64 when running cmake. Ignore this if you are on
CMake GUI.
-- Selecting Windows SDK version to target Windows 10.0.17763.
-- C:/Users/IMEDSYS/bin/tensorflow/tensorflow/contrib/cmake/build/abseil_cpp/src/abseil_cpp_build
-- Configuring done
CMake Error at tf_core_ops.cmake:77 (add_library):
Cannot find source file:
C:/Users/IMEDSYS/bin/tensorflow/tensorflow/contrib/factorization/ops/clustering_ops.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
tf_core_ops.cmake:95 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
Cannot find source file:
C:/Users/IMEDSYS/bin/tensorflow/tensorflow/contrib/rnn/ops/gru_ops.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
tf_core_ops.cmake:107 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
Cannot find source file:
C:/Users/IMEDSYS/bin/tensorflow/tensorflow/contrib/rnn/ops/lstm_ops.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
tf_core_ops.cmake:108 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_kernels.cmake:205 (add_library):
Cannot find source file:
C:/Users/IMEDSYS/bin/tensorflow/tensorflow/contrib/factorization/kernels/clustering_ops.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:596 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
No SOURCES given to target: tf_contrib_factorization_clustering_ops
Call Stack (most recent call first):
tf_core_ops.cmake:95 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
No SOURCES given to target: tf_contrib_rnn_gru_ops
Call Stack (most recent call first):
tf_core_ops.cmake:107 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
No SOURCES given to target: tf_contrib_rnn_lstm_ops
Call Stack (most recent call first):
tf_core_ops.cmake:108 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_ops.cmake:77 (add_library):
No SOURCES given to target: tf_contrib_tpu_ops
Call Stack (most recent call first):
tf_core_ops.cmake:115 (GENERATE_CONTRIB_OP_LIBRARY)
CMakeLists.txt:594 (include)
CMake Error at tf_core_kernels.cmake:205 (add_library):
No SOURCES given to target: tf_core_kernels
Call Stack (most recent call first):
CMakeLists.txt:596 (include)
CMake Generate step failed. Build files cannot be regenerated correctly.
这次我觉得只是 CMake 查找已折旧或重新定位的文件。
所以
我的问题很简单:
- 是否有人有 2 个 Bazel 和 TensorFlow 的版本号实际上可以一起工作(因为它似乎对某些人有效 => 我考虑尝试 Voodoo(?
- 是否有人有一个非常简单的解决方案来使用 Tensorflow 的 c_api 或C++ API?
- 是否有人知道另一种方法,可以从C++构建的软件中使用 Keras 或 Tensorflow 输出(.hdf5 或 .pb(进行预测,而不会像"system("Python predict.py"(那样令人作呕?
提前感谢您的快速回答! :)
我做过类似的工作,使用 Cmake 为 VS 2017 构建较旧的 Tensorflow 版本(不是 2.(。
库达 9 .张量流 1.14 VS 2017 .
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 在 c++ 中使用 Tensorflow Lite 在边缘 TPU 上运行"mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite"时出现问题
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- constexpr 使用 clang 编译 TensorFlow 时出错
- 将 tensorflow lite 与 Qt 一起使用
- 在C++应用程序中使用 Tensorflow:如何释放 GPU 内存
- 在 Tensorflow C++ 中使用 FIFOQueue 时遇到问题
- 使用 C 代码构建 Tensorflow lite micro
- 在 tensorflow-GPU 中使用用户运算符时未定义的符号>=1.15
- 无法使用 ReadBinaryProto Tensorflow 加载协议缓冲区
- 在 C++ 版本的 Tensorflow 上使用多个 GPU
- Tensorflow如何默认使用CPU核心
- 使用Bazel构建Tensorflow
- 无法运行使用 MKL 编译的 TensorFlow
- 如何使用 C++ 的 TensorFlow 估算器?
- 无法在 Windows 10/Visual C++ 2017 上使用 tensorflow C++ API tensor
- 是否可以在QT项目中使用Tensorflow C++ API?
- 使用 Bazel (Windows) 构建 Tensorflow 的问题 => 使用 Tensorflow C++ API
- 使用客户端:: run and Clientsession:tensorflow中的feedType
- Tensorflow C++ 代码 SessionFactory::GetFactory 如何选择使用哪个会话?直接会话