Ubuntu17.04安装TensorFlow1.2的GPU版本

摘要:Ubuntu17.04安装TensorFlow1.2的GPU版本。首先验证nvidia显卡,然后安装CUDA Toolkit 8.0,安装cuDNN v5深度神经网络计算加速库,最后通过python pip安装TensorFlow-GPU版本。

1.安装NVIDIA的GPU-CUDA,cuDNN

Ubuntu17.04安装TensorFlow1.2的GPU版本_第1张图片

1.1. 查看当前配置

xiaolei@wang:~$ uname -m && cat /etc/*release

Ubuntu17.04安装TensorFlow1.2的GPU版本_第2张图片

1.2.安装CUDA

【CUDA官方下载】https://developer.nvidia.com/cuda-downloads

Ubuntu17.04安装TensorFlow1.2的GPU版本_第3张图片

xiaolei@wang:~/Downloads$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
xiaolei@wang:~/Downloads$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64.deb
xiaolei@wang:~/Downloads$ sudo apt update
xiaolei@wang:~/Downloads$ sudo apt install cuda

1.3.安装cuDNN

NVIDIA cuDNN是用于深度神经网络的GPU加速库。

【原文】The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers. cuDNN is part of the NVIDIA Deep Learning SDK.

【官方下载】(需要注册登录后填写个小问卷才能下载)https://developer.nvidia.com/cudnn

Ubuntu17.04安装TensorFlow1.2的GPU版本_第4张图片

  • tensorflow-gpu r1.2现在(201707)默认的是cuDNN v5,而v6会报错。
  • 安装方式很简单,下载后解压,把cudnn中的文件内容拷贝到对应的cuda中。
xiaolei@wang:~/Downloads$ tar -zxf cudnn-8.0-linux-x64-v5.1.tgz && cd cuda
xiaolei@wang:~/Downloads/cuda$ sudo cp include/cudnn.h /usr/local/cuda-8.0/include/
xiaolei@wang:~/Downloads/cuda/lib64$ sudo cp lib64/libcudnn* /usr/local/cuda-8.0/lib64

1.4.安装 libcupti-dev 包

xiaolei@wang:~$ sudo apt-get install libcupti-dev

1.5.变量设置

#!/bin/sh
# Author:wangxiaolei 王小雷
# Blog: http://blog.csdn.net/dream_an
# Github: https://github.com/wangxiaoleiai
# Date: 201707
# Organization: https://github.com/whaleai

export CUDA_HOME=/usr/local/cuda-8.0
export PATH=$CUDA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64

2.安装tensorflow-gpu

可以通过python2或者python3的安装,博主使用的是python3。

2.1.安装依赖

xiaolei@wang:~$ sudo apt-get install python-pip python-dev   # for Python 2.7
xiaolei@wang:~$ sudo apt-get install python3-pip python3-dev # for Python 3.n

2.2.安装tensorflow-gpu版本

xiaolei@wang:~$ pip install tensorflow-gpu  # Python 2.7;  GPU support
xiaolei@wang:~$ spip3 install tensorflow-gpu # Python 3.n; GPU support

Ubuntu17.04安装TensorFlow1.2的GPU版本_第5张图片

3.测试tensorflow-gpu

xiaolei@wang:~$ python3
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

Ubuntu17.04安装TensorFlow1.2的GPU版本_第6张图片

可以看到已经使用GPU了!完结-成功

1.彩蛋-卸载方法

xiaolei@wang:~$ sudo pip uninstall tensorflow  # for Python 2.7
xiaolei@wang:~$ sudo pip3 uninstall tensorflow # for Python 3.n

2.彩蛋-官网给出的常见错误处理方法

https://www.tensorflow.org/install/install_sources#common_installation_problems

你可能感兴趣的:(TensorFlow)