Ubuntu 16.04最简单的tensorflow-gpu安装教程

1.英伟达驱动安装


在“附加驱动”里,系统会自动搜索N卡驱动,列表里会提供对应你显卡的最新版官方驱动。例如我的显卡是GTX1060-6g,选择nvidia 375.51就可以了。

2.cuda8.0安装

sudo apt-get update && sudo apt-get install wget -y --no-install-recommends
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda-8.0
 

启动后配置cuda环境变量

1)一般配置此步即可,但有时会出现问题,可以选择用root用户进行编辑,也可以尝试后两步

[html]  view plain  copy
  1. gedit ~/.bashrc  # if can't edit, add sudo before  
  2.   
  3. # add the two lines following  
  4.     export PATH=/usr/local/cuda/bin:$PATH  
  5.     export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH  
  6.   
  7. # cuda can change as cuda-8.0 specifically  
  8.   
  9. source ~/.bashrc  # MUST source  

2)

[plain]  view plain  copy
  1. sudo gedit /etc/ld.so.conf.d/cuda.conf  
  2.   
  3. # add the two lines following  
  4.     /usr/local/cuda/lib64  
  5.     /lib  
  6.   
  7. sudo ldconfig -v  
3)
[plain]  view plain  copy
  1. sudo gedit /etc/profile    
  2.   
  3. # add following two lines  
  4.     PATH=/usr/local/cuda/bin:$PATH  #  不能有空格!!   
  5.     export PATH    
  6.   
  7. source /etc/profile  

验证是否安装成功:

[plain]  view plain  copy
  1. cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery  
  2.   
  3. sudo make  
  4.   
  5. ./deviceQuery  

3.cudnn5.1安装

CUDNN_URL="http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz"

wget ${CUDNN_URL}

sudo tar -xzf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local

rm cudnn-8.0-linux-x64-v5.1.tgz && sudo ldconfig

或者cudnn6.0

CUDNN_URL="http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v6.0.tgz"

wget ${CUDNN_URL}

sudo tar -xzf cudnn-8.0-linux-x64-v6.0.tgz -C /usr/local

rm cudnn-8.0-linux-x64-v5.1.tgz && sudo ldconfig

4.tensorflow-gpu安装

如果没有pip,先安装pip(sudo apt-get python-pip,sudo apt-get python3-pip)

python-2.7

sudo pip install TensorFlow-gpu

有时候需要使用sudo pip2 install TensorFlow-gpu

python-3.5

sudo pip3 install TensorFlow-gpu

5.测试

$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a+b)
42
>>>



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值