tensorflow 源码安装

安装bazel

下载bazel0.11:https://github.com/bazelbuild/bazel/releases
安装
chmod +x bazel-<version>-installer-linux-x86_64.sh
./bazel-<version>-installer-linux-x86_64.sh --user
#--user表示将会安装到/home/bin目录下

~/.bashrc添加:PATH=/home/*/bin:$PATH

安装protobuf

下载安装包
解压、编译、安装
tar -xf  protobuf-all-3.5.0.tar.gz  
cd protobuf-3.5.0   
./configure   
make   
make check   
make install
安装python模块
cd ./python   
python setup.py build   
python setup.py test   
python setup.py install
验证是否安装成功
python -c 'import google.protobuf'

可能报以下错误

protoc: error while loading shared libraries: libprotobuf.so.15: cannot open shared object file: No such file or directory

创建新文件:/etc/ld.so.conf.d/libprotobuf.conf ,然后在其中加入内容:/usr/local/lib
编辑环境变量 export LD_LIBRARY_PATH=/usr/local/lib

tensorflow安装

下载源码


git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git checkout r1.7

根据需要修改配置
(py3-tf-gpu) [admin@localhost tensorflow]$ ./configure 
You have bazel 0.11.1 installed.
Please specify the location of python. [Default is /home/admin/anaconda3/bin/python]: /data/users/elag/envs/py3-tf-gpu/bin/python


Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'site' has no attribute 'getsitepackages'
Found possible Python library paths:
  /data/users/elag/envs/py3-tf-gpu/lib/python3.6/site-packages
Please input the desired Python library path to use.  Default is [/data/users/elag/envs/py3-tf-gpu/lib/python3.6/site-packages]

Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: n
No jemalloc as malloc support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
No Hadoop File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n
No Amazon S3 File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: n
No Apache Kafka Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with GDR support? [y/N]: n
No GDR support will be enabled for TensorFlow.

Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL 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.

Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.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 the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.1


Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:


Do you wish to build TensorFlow with TensorRT support? [y/N]: n
No TensorRT support will be enabled for TensorFlow.

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: 6.1,6.1]


Do you want to use clang as CUDA compiler? [y/N]: n
nvcc will be used as CUDA compiler.

Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 


Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI 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]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
    --config=mkl            # Build with MKL support.
    --config=monolithic     # Config for mostly static monolithic build.
Configuration finished
bazel编译tensorflow:
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
创建pip包并安装
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* .
python setup.py develop

安装过程可能遇到的问题

Cannot find libdevice.10.bc under /usr/local/cuda-8.0
解决
将/usr/local/cuda-8.0/nvvm/libdevice/libdevice.compute_50.10.bc改为libdevice.10.bc,并复制一份至/usr/local/cuda-8.0/


>>> import tensorflow
Traceback (most recent call last):
  File "/data/users/elag/github/tensorflow/tensorflow/python/platform/self_check.py", line 25, in <module>
    from tensorflow.python.platform import build_info
ImportError: cannot import name 'build_info'

解决

#换个目录重新导入

ImportError: cannot import name 'weakref'

解决

在 path/to/python/env/Lib/site-packages/tensorflow/python/util/tf_should_use.py
将
from backports import weakref # pylint: disable=g-bad-import-order
改为
import weakref

ImportError: libcudnn.5: cannot open shared object file: No such file or directory

解决

在/usr/local/cuda/lib64 or /usr/local/cuda-8.0/lib64 做个软连接 ln -s libcudnn.so.7.* libcudnn.so.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值