1、下载TensorFlow安装文件(源代码)来源渠道有以下 (1)tensorflow 源码地址#输入以下命令获取$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
(2)tensorflow whl文件地址如tensorflow0.8分布式whl文件地址为:tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl #输入以下命令获取$ wget http://ci./job/tensorflow-master-gpu_pip/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
或者查看官方下载安装说明http:///get_started/os_setup.md 2、安装依赖,首先安装bazel\#安装相关的包:$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip$ sudo apt-get install python-numpy swig python-dev
在bazel之前需要安装JDK8,官方安装教程 (1)安装JDK8:<1>ubuntu(14.04)$ sudo add-apt-repository ppa:webupd8team/java$ sudo apt-get update$ sudo apt-get install oracle-java8-installer
<2>ubuntu(15.10)安装OpenJDK 8: 下载bazel安装文件: 然后使用以下命令安装 $ chmod +x bazel-version-installer-os.sh$ ./bazel-version-installer-os.sh --user
其中version需要替换下载的版本,即获取的安装文件为.sh。使用 设置运行环境:执行文件bazel将被安装在$HOME/bin路径下,所以加入PATH路径中: $ export PATH='$PATH:$HOME/bin'
3、安装protobuf(tensorflow依赖)下载地址为:https://github.com/google/protobuf 下载解压(如果是压缩包)后,执行 $ ./autogen.sh
将会生成configure文件 (1)默认安装步骤(需root权限):$ ./configure$ make$ make check$ make install
usr/local/bin,usr/local/lib,usr/local/include (2)修改安装路径(非root用户需要修改安装路径):protobuf默认安装在 /usr/local 目录 $./configure --prefix=/usr/local/protobuf$ make$ make check$ make install
到此步还没有安装完毕,在/etc/profile 或者用户目录 ~/.bash_profile ####### add protobuf lib path #########(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib/#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib/#执行程序搜索路径export PATH=$PATH:/usr/local/protobuf/bin/#c程序头文件搜索路径export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/protobuf/include/#c++程序头文件搜索路径export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/protobuf/include/#pkg-config 路径export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/######################################
(3)还需要重新配置Python,否则可能会在import tensorflow时候出现No module named google.protobuf,其中不知道是否一定与ldconfig有关系,http://blog.csdn.net/littlestream9527/article/details/38734001里介绍了ldconfig的功能$ ldconfig$ cd ~~/protobuf/python ##进入解压protobuf后中的python文件夹,里面会有buile文件夹与setup.py文件等$ python setup.py build$ python setup.py install$ cd /usr/local/lib/python2.7/site-packages #进入tensorflow想关联的python的目录下修改$ chmod -R 755 *
(4)查看是否安装成功
显示安装版本为2.6.1 4、源码安装tensorflow(1)下载源码文件:$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
其中–recurse-submodules是获取tensorflow所需要的protobuf库(加该选项运行成功的话,可以不单独安装protobuf) $ ./configurePlease specify the location of python. [Default is /usr/bin/python]:
(2)开始安装安装过程中需要不断输入y/n进行配置确认,如需安装支持GPU版本,需要安装Cuda7.0,cuDNN6.5(据说是写死的版本,对于Cuda7.5,cuDNN7.0没有支持,但可以手动配置) $ tar xvzf cudnn-6.5-linux-x64-v2.tgz$ sudo cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda/include$ sudo cp cudnn-6.5-linux-x64-v2/libcudnn* /usr/local/cuda/lib64$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
添加cuda路径PATH=$PATH:/usr/local/cuda (CUDA安装路径)添加lib路径LD_LIBRARY_PATH=$LA_LIBRARY_PATH:/usr/local/cuda/lib64
tensorflow 总体安装过程如下 $ ./configurePlease specify the location of python. [Default is /usr/bin/python]:Do you wish to build TensorFlow with GPU support? [y/N] yGPU support will be enabled for TensorFlowPlease specify the Cuda SDK version you want to use, e.g. 7.0. [Leaveempty to use system default]: 7.5Please specify the location where CUDA 7.5 toolkit is installed. Refer toREADME.md for more details. [default is: /usr/local/cuda]: /usr/local/cudaPlease specify the Cudnn version you want to use. [Leave empty to use systemdefault]: 4.0.4Please specify the location where the cuDNN 4.0.4 library is installed. Refer toREADME.md for more details. [default is: /usr/local/cuda]: /usr/local/cudnn-r4-rc/Please specify a list of comma-separated Cuda compute capabilities you want tobuild with. You can find the compute capability of your device at: https://developer./cuda-gpus.Please note that each additional compute capability significantly increases yourbuild time and binary size. [Default is: \'3.5,5.2\']: 3.5Setting up Cuda includeSetting up Cuda lib64Setting up Cuda binSetting up Cuda nvvmConfiguration finished
至此,完成tensorflow安装 5、whl方式安装tensorflow(1)下载whl安装文件官方whl文件下载方法 CPU版本:wget https://storage./tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whlGPU版本,需要CUDA toolkit 7.5 和 CuDNN v4.:wget https://storage./tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl #以按照以下方法直接下载0.8版本$ wget http://ci./job/tensorflow-master-gpu_pip/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
(2)或者使用bazel从源码创建$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
若建立支持GPU的安装 $ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
生成whl至/tmp/tensorflow_pkg $ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
(3)最后使用与平台匹配的whl安装tensorflow$ pip install tensorflow-0.8.0rc0-py2-none-linux_x86_64.whl
6、为项目开发对tensorflow进行相关设置
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
$ bazel build -c opt --config=cuda //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/* .$ ln -s ../tensorflow/tools/pip_package/* .$ python setup.py develop
7、测试安装成功(1)检查tensorflow是否可以正常使用$ python...>>> import tensorflow as tf>>> hello = tf.constant('Hello, TensorFlow!')>>> sess = tf.Session()>>> print(sess.run(hello))Hello, TensorFlow!>>> a = tf.constant(10)>>> b = tf.constant(32)>>> print(sess.run(a + b))42>>>
(2)测试是否支持GPU$ bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer$ bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu# Lots of output. This tutorial iteratively calculates the major eigenvalue of# a 2x2 matrix, on GPU. The last few lines look like this.000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
8、安装中常见的问题:(1)GPU有关的问题
确认GPU是否妥善安装,版本是否正确 (2)Protobuf库有关的问题tensorflow pip包依赖protobuf pip包的版本为version 3.0.0b2,Protobuf的pip包可以从PyPI下载(当运行pip install protobuf),或者可以升级版本,通过以下命令(python2.7) # Ubuntu/Linux 64-bit:$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/protobuf-3.0.0b2.post2-cp27-none-linux_x86_64.whl
可以修复以下问题: [libprotobuf ERROR google/protobuf/src/google/protobuf/io/coded_stream.cc:207] Aprotocol message was rejected because it was too big (more than 67108864 bytes).To increase the limit (or to disable these warnings), seeCodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
(3)pip安装问题:<1>Cannot import name ‘descriptor’ImportError: Traceback (most recent call last): File '/usr/local/lib/python3.4/dist-packages/tensorflow/core/framework/graph_pb2.py', line 6, in <module> from google.protobuf import descriptor as _descriptorImportError: cannot import name 'descriptor'
如果在升级tensorflow时遇到以上问题时,尝试卸载tensorflow和protobuf ,并重装rensorflow(同样需要合适的protobuf) <2>Can’t find setup.py在pip install是遇见如下错误: ...IOError: [Errno 2] No such file or directory: '/tmp/pip-o6Tpui-build/setup.py'
解决方法为: pip install --upgrade pip
<3>SSLError: SSL_VERIFY_FAILED当从URL中使用pip install时候,出现以下问题: ...SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
解决办法: 使用curl或者wget下载wheel到本地,再进行安装 |
|
来自: bookocea > 《TensorFlow》