Ubuntu14.04 CUDA/cuDNN/caffe/DIGIT 安装备忘录

一、硬件需要有一块支持cuda的显卡(这里用k4200),内存16G以上,CPU一般的就可以

二、操作系统 Ubuntu14.04 desktop 64bit

三、安装显卡驱动

(1)从nvidia官网上下载对应的驱动 NVIDIA-Linux-x86_64-367.44.run
添加执行权限 chmod +x /home/downloads/NVIDIA-Linux-x86_64-367.44.run

(2)删除已经安装的nv驱动
$sudo apt-get –purge remove nvidia-*
修改配置文件添加nouveau到blacklist
$sudo gedit /etc/modprobe.d/blacklist.conf
在最后添加 blacklist nouveau 保存并重启电脑

(3)关掉图形切换到命令行
$sudo service lightdm stop
此时黑屏 同时按 ctrl + alt + F1 登陆
以root身份安装 sudo sh /home/downloads/NVIDIA-Linux-x86_64-367.44.run 按照提示安装完成,运行

四、更换阿里云源

国内访问国外网站比较慢,有的甚至打不开更新不了程序
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
sudo vim /etc/apt/sources.list #修改

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

sudo apt-get update #更新列表

五、一系列的软件安装

利用GPU支持深度学习的主流框架目前有三个,包括Theano、Torch和caffe。 NVIDIA DIGITS则是一个网络服务器,它提供了一个方便的网络接口,用于训练和测试基于caffe的深度神经网络。

(1)CUDA
# installation of required tools
sudo apt-get install -y gcc g++ gfortran build-essential git wget linux-image-generic libopenblas-dev python-dev python-pip python-nose python-numpy python-scipy

# downloading the (currently) most recent version of CUDA
Sudo wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb

# installing CUDA
sudo dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb

sudo apt-get update
sudo apt-get install cuda

# setting the environment variables so CUDA will be found
echo -e “\nexport PATH=/usr/local/cuda/bin:$PATH” >> .bashrc
echo -e “\nexport LD_LIBRARY_PATH=/usr/local/cuda/lib64” >> .bashrc

sudo reboot

# installing the samples and checking the GPU
cuda-install-samples-7.0.sh ~/
cd NVIDIA\_CUDA-7.0\_Samples/1\_Utilities/deviceQuery
make
./deviceQuery

安装完CUDA后,检测CUDA安装是否成功(可选):

#在CUDA目录下安装samples并编译:
/usr/local/cuda/bin/cuda-install-samples-7.5.sh ~/cuda-samples

cd ~/cuda-samples/NVIDIA*Samples
make -j $(($(nproc) + 1))
#其中-j $(($(nproc) + 1))指使用机器上所有的核并行执行make命令来使编译更快

#执行deviceQuery来检测显卡并进行相关测试,Result=pass即为通过
bin/x86_64/linux/release/deviceQuery

进入/usr/local/cuda/samples:

sudo make all -j4

完成后进入samples/bin/x86_64/linux/release:

./deviceQuery

可以看到你的显卡信息

(2)cuDNN

# unpack the library
gzip -d cudnn-6.5-linux-x64-v2.tar.gz
tar xf cudnn-6.5-linux-x64-v2.tar

# copy the library files into CUDA’s include and lib folders
sudo cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda-7.0/include
sudo cp cudnn-6.5-linux-x64-v2/libcudnn* /usr/local/cuda-7.0/lib64

(3)Caffe

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler libatlas-base-dev

# the version number of the required branch might change
# consult https://github.com/NVIDIA/DIGITS/blob/master/README.md
git clone –branch v0.11.0 https://github.com/NVIDIA/caffe.git

cd ~/caffe/python
for req in $(cat requirements.txt); do sudo pip install $req; done

cd ~/caffe
cp Makefile.config.example Makefile.config

# check that USE_CUDNN is set to 1 in case you would
# like to use it and to 0 if not

make all
make py
make test
make runtest

echo -e “\nexport CAFFE_HOME=/home/ubuntu/caffe” >> ~/.bashrc

# load the new environmental variables
bash

(4)DIGITS

cd ~
git clone https://github.com/NVIDIA/DIGITS.git digits
cd digits
sudo apt-get install graphviz gunicorn
for req in $(cat requirements.txt); do sudo pip install $req; done

六、启动和配置DIGITS

DIGITS在第一次启动时会问你一些关于配置目的的问题。这些设置是非常直白,并且可以事后在~/.digits/digits.cfg中更改。

# change into your digits directory
cd digits

# start the server
./digits-devserver

在浏览器输入地址http://localhost:5000 打开digits的管理界面
Most values are set silently by default. If you need more control over your configuration, try one of these commands:
# Set more options before starting the server
./digits-devserver –config
# Advanced usage python -m digits.config.edit –verbose

 

参考文档:
http://www.07net01.com/2015/08/918480.html