AI环境搭建(nvidia + cuda + cudnn + tensorflow+其他)

36 篇文章 0 订阅

AI环境搭建(nvidia + cuda + cudnn + tensorflow+其他)

1 安装显卡驱动

sudo add-apt-repository ppa:graphics-drivers/ppa  
sudo apt-get update  
sudo apt-get install nvidia-375  #此处要根据上面查询到的版本适当更改    (当前使用的是384版本)
sudo apt-get install mesa-common-dev  
sudo apt-get install freeglut3-dev

安装完成后重启电脑,后输入:

nvidia-smi

或者输入:

nvidia-settings

显示显卡列表,表示安装成功

2 安装cuda

官网下载:cuda_8.0.61_375.26_linux.run

chmod +x cuda_8.0.61_375.26_linux.run
sh cuda_8.0.61_375.26_linux.run
accept
n
后面一直yes

当出现如下提示:

Please make sure that
– PATH includes /usr/local/cuda-8.0/bin
– LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:
sudo .run -silent -driver

Logfile is /tmp/cuda_install_6583.log

表示安装完毕,可以进行cuda测试

nvcc -V

或者跑cuda测试程序:
进入到Samples安装目录,然后在该目录下终端输入make,等待十来分钟。
可以在Samples里面找到bin/x86_64/linux/release/目录,并切换到该目录
运行deviceQuery程序

sudo ./deviceQuery

查看输出结果,重点关注最后一行,Pass表示通过测试

3 安装cudnn

去官网下载与cuda相应的安装包,解压

tar zxvf cudnn-8.0-linux-x64-v6.0.tgz

将文件拷贝到cuda的相应位置:

cd cuda
sudo cp include/*  /usr/local/cuda-8.0/include/
sudo cp lib64/*  /usr/local/cuda-8.0/lib64/

设置环境变量:

vim ~/.bashrc
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

source ~/.bashrc

4 安装tensorflow

sudo pip install tensorflow-gpu==1.4.1

测试:

$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf 
>>> tf.__version__
'1.4.1'
>>> 

进一步测试:

# coding: utf-8
import tensorflow as tf

with tf.device('/cpu:0'):
    a = tf.constant([1.0,2.0,3.0],shape=[3],name='a')
    b = tf.constant([1.0,2.0,3.0],shape=[3],name='b')
with tf.device('/gpu:0'):
    c = a+b

#注意:allow_soft_placement=True表明:计算设备可自行选择,如果没有这个参数,会报错。
#因为不是所有的操作都可以被放在GPU上,如果强行将无法放在GPU上的操作指定到GPU上,将会报错。
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True))
#sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(tf.global_variables_initializer())
print(sess.run(c))

5 安装其他一些AI库,scipy,sklearn等

sudo apt install python-opencv -y
sudo pip install scipy (or sudo apt-get install python-scipy)
sudo pip install sklearn
sudo pip install sysv_ipc
sudo pip install matplotlib 
sudo apt install libffi-dev
sudo pip install ipcqueue
sudo pip install tornado==4.5.2
sudo pip install Ipy
sudo apt-get install inetutils-ping
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值