PC上装好Ubuntu系统,我们一步一步来讲解如何使用源码安装tensorflow?(我的Ubuntu系统是15.10)
根据你的系统型号选择相应的cuda版本下载
https://developer.nvidia.com/cuda-downloads
我选的是cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb
右击下载到的文件,Open inTerminal,输入一下命令:
sudo dpkg -icuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb
sudo apt-get update
sudo apt-get install cuda
安装到:/usr/local/cuda
下载cudnn,https://developer.nvidia.com/cudnn
我下的版本是cudnn-7.0-linux-x64-v4.0-prod.tgz
同上,输入以下命令:
tar xvzf cudnn-7.0-linux-x64-v4.0-prod.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
下载tensorflow源文件
git clone--recurse-submodules https://github.com/tensorflow/tensorflow
安装Bazel,Bazel是Google开源构建工具,类似于Make的工具,用来编译构建tensorflow
http://bazel.io/docs/install.html
Bazel下载地址:
https://github.com/bazelbuild/bazel/releases(bazel-0.2.2b-installer-linux-x86_64.sh)
sudo apt-get install pkg-config zip g++zlib1g-dev unzip
chmod +x bazel-version-installer-os.sh
./bazel-version-installer-os.sh --user
export PATH="$PATH:$HOME/bin"
安装tensorflow其他的依赖
sudo apt-get install python-numpy swig python-dev python-wheel
配置tensorflow,需要你指定相应文件的安装目录。cd进tensorflow源文件。
sudo ./configure
配置好,会出现以下内容:
Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Setting up CUPTI include
Setting up CUPTI lib64
Configuration finished
使用Bazel编译构建
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]OK!
Test:
cd /home/lei/tensorflow/tensorflow/models/image/mnist
python convolutional.py
Tips:
参考资料: