![](/img/trans.png)
[英]How to use TensorFlow C++ api as a shared library with bazel?
[英]Issue building Tensorflow using Bazel (Windows) => to use Tensorflow C++ API
我的最初目標只是使用Tensorflow的C ++ API讀取“ .pb”凍結模型並對其進行預測。 使用Keras對其進行原型制作,設法凍結了模型並在Python上使用Tensorflow進行了嘗試; 一切進展順利。 所以我基本上只需要C ++ API即可工作。
我使用的是i5-8400T計算機,沒有GPU,8GB內存。 今天(27/08/2019)已下載所有版本的bazel和tensorflow。
我要做的第一件事當然是遵循tensorflow的指南 。 bazel run -c opt //tensorflow/cc/example:example
小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:\users\imedsys\bin\tensorflow\.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:\users\imedsys\bin\tensorflow\.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:\users\imedsys\bin\tensorflow\.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做到這一點,正如去年許多人說的那樣,在Windows上構建擋板尚不可用。 我使用了兩個類似的指南,其中一個在這里 ,因此嘗試使用
cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=C:\swigwin-3.0.12\swig.exe -DPYTHON_EXECUTABLE=C:\Anaconda3\envs\tensorflow\python.exe -DPYTHON_LIBRARIES=C:\Anaconda3\envs\tensorflow\libs\python35.lib
首先,然后
`cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=C:\swigwin-3.0.12\swig.exe -DPYTHON_EXECUTABLE=C:\Anaconda3\envs\tensorflow\python.exe -DPYTHON_LIBRARIES=C:\Anaconda3\envs\tensorflow\libs\python35.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尋找已折舊或已重定位的文件。
我的問題很簡單:
預先感謝您的快速解答! :)
我已經使用Cmake為VS 2017構建了較舊的Tensorflow版本(不是2.)做過類似的工作。
uda 9。 Tensorflow 1.14與2017年。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.