要GPU的话要下载nvidia驱动的 尽量装最新版的驱动吧 还有cudnn version为5以上的 这些在官网都有提及的
$ cd tensorflow # cd to the top-level directory created $ ./configure Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7 Found possible Python library paths: /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages Please input the desired Python library path to use. Default is [/usr/lib/python2.7/dist-packages] Using python library path: /usr/local/lib/python2.7/dist-packages Do you wish to build TensorFlow with MKL support? [y/N] No MKL support will be enabled for TensorFlow Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: Do you wish to use jemalloc as the malloc implementation? [Y/n] jemalloc enabled Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] No Google Cloud Platform support will be enabled for TensorFlow Do you wish to build TensorFlow with Hadoop File System support? [y/N] No Hadoop File System support will be enabled for TensorFlow Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] No XLA support will be enabled for TensorFlow Do you wish to build TensorFlow with VERBS support? [y/N] No VERBS support will be enabled for TensorFlow Do you wish to build TensorFlow with OpenCL support? [y/N] No OpenCL support will be enabled for TensorFlow Do you wish to build TensorFlow with CUDA support? [y/N] Y CUDA support will be enabled for TensorFlow Do you want to use clang as CUDA compiler? [y/N] nvcc will be used as CUDA compiler Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 8.0 Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 6 Please specify the location where cuDNN 6 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: "3.5,5.2"]: 3.0 Do you wish to build TensorFlow with MPI support? [y/N] MPI support will not be enabled for TensorFlow Configuration finished
这句命令其实是bazel的用法 具体要生成哪个可以 " vim $(TF_ROOT_PATH)/tensorflow/BUILD " 查看
有写问题一种是tensorflow太新可能编译不通过,一种可能是bazel太新导致有些错误。如:
_WARNING: ignoring http_proxy in environment.
ERROR: /root/.cache/bazel/bazel_root/6093305914d4a581ed00c0f6c06f975b/external/io_bazel_rules_closure/closure/private/defs.bzl:27:16: Theset
constructor for depsets is deprecated and will be removed. Please use thedepset
constructor instead. You can temporarily enable the deprecatedset
constructor by passing the flag --incompatible_disallow_set_constructor=false.
ERROR: error loading package '': Extension file 'closure/private/defs.bzl' has errors.
cp -r tensorflow/ $(YOUR_PATH)
5、库的使用
在使用tensorflow c/c++接口时,会有很多头文件依赖、protobuf版本依赖等问题
(1)tensorflow/contrib/makefile目录下,找到build_all_xxx.sh文件并执行,例如准备在linux上使用,就执行build_all_linux.sh文件,成功后会出现一个gen文件夹
(2)把tensorflow和bazel-genfiles文件夹下的头文件都抽取出来放在一个文件夹下面,或者通过cmake把这两个路径添加进include_directories中
(3)tensorflow/contrib/makefile/gen/protobuf/include,也就是(1)中生成的文件夹中的头文件,也需要抽取或者在cmake中包含在include_directories中
代码:
#include#include public/session.h> #include using namespace std; using namespace tensorflow; int main() { Session* session; Status status = NewSession(SessionOptions(), &session); if (!status.ok()) { cout << status.ToString() << "\n"; return 1; } cout << "Session successfully created.\n"; } cmake:
cmake_minimum_required (VERSION 2.8.8) project (tf_example) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -W") aux_source_directory(./src DIR_SRCS) link_directories(./lib) include_directories( path_to_tensorflow/tensorflow path_to_tensorflow/tensorflow/bazel-genfiles path_to_tensorflow/tensorflow/contrib/makefile/gen/protobuf/include ) add_executable(tf_test ${DIR_SRCS}) target_link_libraries(tf_example tensorflow_cc)
接下来执行命令:
cd build
cmake ..
make