- 从github下载 Tensorflow 源码
$ git clone https://github.com/tensorflow/tensorflow
查看当前分支, 根据需求切换到指定分支, e.g. r1.3
$ cd tensorflow
$ git checkout Branch # where Branch is the desired branch
$ git checkout r1.3
- 安装Bazel
- 安装python依赖包
- numpy, which is a numerical processing package that TensorFlow requires.
- dev, which enables adding extensions to Python.
- pip, which enables you to install and manage certain Python packages.
- wheel, which enables you to manage Python compressed packages in the wheel (.whl) format.
python 2 安装命令如下
$ sudo apt-get install python-numpy python-dev python-pip python-wheel
python 3 安装命令如下
$ sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
-安装 cuda
cuda 下载路径 CUDA Toolkit
$ sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get install -y cuda
cudnn 下载路径 cudnn
注册个账号,然后根据自己的系统选择下载相应的cudnn.
$ tar zxvf cudnn-7.5-linux-x64-v5.1.tgz
$ cd cuda
$ sudo cp include/cudnn.h /usr/local/include
$ sudo cp lib64/libcudnn.* /usr/local/lib
$ sudo ln -sf /usr/local/lib/libcudnn.so.5.1.3 /usr/local/lib/libcudnn.so.5
$ sudo ln -sf /usr/local/lib/libcudnn.so.5 /usr/local/lib/libcudnn.so
$ sudo ldconfig -v
最后安装 libcupti-dev
$ sudo apt-get install libcupti-dev
-设置安装配置
根据自己python版本, cuda, cudnn版本和GPU计算力设置
$ cd tensorflow # cd to the top-level directory created
$ ./configure
-编译 pip package
- TensorFlow compiled to use SSE, AXV, FMA
$ bazel build -c opt --copt=-march=native --copt=-mfpmath=both --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
生成 .whl 文件
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
-安装 .whl
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-py2-none-any.whl
- 问题汇总
tensorflow-*-any.whl not a supported wheel on this platform
使用 python -m pip install 代替 pip install 安装
sudo python -m pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-py2-none-any.whl