Ubuntu 16.04下安装TensorFlow最新GPU版 January 9, 2018 在安装TensorFlow GPU版本之前,需要安装好CUDA 8.0 + cuDNN 6.0,安装过程见[这里](/2018/01/09/46.html)。其他版本的CUDA与cuDNN也可以参考这个安装步骤。 >**补充:由于TF更新很快,本教程只适用于依赖CUDA 8.0 + cuDNN 6.0的TF版本,不过我按照同样的方法成功安装了CUDA 9.0 + cuDNN 7.0 和 TensorFlow 1.6版本,`注意环境变量添加的时候目录改成CUDA-9.0`。** 本次安装主要按照官网的安装指南进行安装,通过`virtualenv`安装了Python3.5 GPU版本,官网安装指南: > https://www.tensorflow.org/install/install_linux#InstallingVirtualenv 安装过程如下: ```bash # 安装pip 和 virtualenv sudo apt-get install python3-pip python3-dev python-virtualenv # 新建文件夹保存virtualenv cd /home/pizi mkdir python_virtualenv cd python_virtualenv # 创建虚拟环境 virtualenv --system-site-packages -p python3 tensorflow # 激活虚拟环境 source tensorflow/bin/activate # 通过豆瓣源安装TF GPU pip3 install --upgrade tensorflow-gpu -i https://pypi.douban.com/simple/ # 安装完成后新建py脚本进行测试 cd /home/pizi && nano testTF.py # 输入测试代码 import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello)) # 输出一下结果: 2018-01-09 20:14:34.116308: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2018-01-09 20:14:34.217819: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-01-09 20:14:34.218130: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties: name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:01:00.0 totalMemory: 5.93GiB freeMemory: 5.79GiB 2018-01-09 20:14:34.218151: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1) b'Hello, TensorFlow!' ``` 至此,TensorFlow GPU版安装完成。