Ubuntu 14.04+GT720M+CUDA8.0+CUDNN+PYCAFFE

安装系统:Ubuntu14.04

安装前执行:

sudo apt-get update

sudo apt-get install g++

CUDA8.0包括2部分内容:Driver+Tool Kit,所以安装CUDA之前不用安装NVIDIA显卡的驱动。但是Ubuntu14.04自带第三方开发的Nvidia驱动,安装CUDA前需要屏蔽。

一 屏蔽开源驱动

1. 执行如下命令:

sudo gedit /etc/modprobe.d/blacklist.conf

并在文本最后一行添加 blacklist nouveau

2. 重启

sudo reboot

二安装CUDA

1. 下载CUDA

官网地址:http://developer.nvidia.com/cuda-downloads

64位的Ubuntu 14.04,所以选择相应的runfile: cuda_8.0.61_375.26_linux.run

该run文件我放在home/faster-rcnn/cuda文件夹下

2. 安装CUDA

2.1 进入text-mode模式

切换到tty1  Ctrl+Alt+F1  进入字符界面,在纯字符界面下输入用户名和密码,输入命令关闭图形界面 sudo service lightdm stop

2.2 开始安装CUDA

进入home/faster-rcnn/cuda文件夹下:cd  home/faster-rcnn/cuda

执行安装文件:sudo sh .cuda_8.0.61_375.26_linux.run

安装过程中,询问是否安装OpenGL,选择n,其余都选y,安装路径默认即可,直接按Enter键,最后会显示installed,否则显示failed。

2.3 安装完成后重启图形界面 sudo service lightdm start 然后Ctrl+Alt+F7进入图形界面

2.4 设置环境变量,执行:sudo gedit /etc/profile 在文件末尾添加,如下内容:

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

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

    保存,退出。输入:sudo ldconfig, 环境变量立即生效

    验证安装是否完成,输入:nvidia-smi

2.5 测试cuda的samples

    cd /home/NVIDIA_CUDA-8.0_Samples,执行:make

    进入1_Utilities目录,执行: ./deviceQuery/deviceQuery

2.6 调整屏幕分辨率

安装完CUDA后,回到图形界面时,发现分辨率无法正确显示,以下为调整方法:

退出图形界面,按ctrl+alt+F1进入命令行终端。

sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.backup

sudo touch /etc/X11/xorg.conf

然后重启即可

二.安装cudnn

1.cudnn安装包

从 https://developer.nvidia.com/rdp/cudnn-download 下载,选择Linux版本下载,我是从Release Notes里面下载的

cudnn-8.0-linux-x64-v5.1.tgz,下载的压缩包放在/home/faster-rcnn/cudnn目录下

2.安装cudnn

2.1进入存放cudnn安装包的目录 cd /home/faster-rcnn/cudnn

2.2 解压缩 sudo tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz

会生成cuda/include和cuda/lib64

2.3 将cuda/include目录中的cudnn.h文件拷贝到/usr/local/cuda-8.0/include/目录下

    sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include/ 

2.4 将cuda/lib64目录中的库拷贝到/usr/local/cuda-8.0/lib64/目录下

    sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64/

2.5 将/usr/local/cuda-8.0/lib64/目录下的libcudnn库的权限改为777

    sudo chmod 777 /usr/local/cuda-8.0/include/cudnn.h 

    sudo chmod 777 /usr/local/cuda-8.0/lib64/libcudnn*

三.安装caffe

1.安装一系列的库

1.1

sudo apt-get install git

1.2

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

1.3

sudo apt-get install libatlas-base-dev

1.4

sudo apt-get install the python-dev

1.5

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

1.6

sudo apt-get install --no-install-recommends libboost-all-dev

2.安装caffe

2.1 从github上获取caffe,下载到/home/faster-rcnn/caffe目录下

    cd /home/faster-rcnn/caffe

    git clone https://github.com/BVLC/caffe.git

2.2 进入到下载的caffe目录中,将Makefile.config.example的内容复制到Makefile.config:

    sudo cp Makefile.config.example Makefile.config

2.3 打开并修改配置文件:

    sudo gedit Makefile.config

针对需求修改几项即可,如下:

    a.若使用cudnn,则将:#USE_CUDNN := 1 修改成:USE_CUDNN := 1

    b.若要使用python来编写layer,则将:#WITH_PYTHON_LAYER := 1去掉#号修改为:WITH_PYTHON_LAYER := 1

    c.修改成:USE_OPENCV := 1, USE_LEVELDB := 1, USE_LMDB := 1

2.4 编译:

a. make; b. make test; c. make runtest

在make runtest时出现了一个错误,大致内容如下:

  1. <pre name="code" class="plain">[----------] 6 tests from CuDNNConvolutionLayerTest/1, where TypeParam = double  
  2. [ RUN      ] CuDNNConvolutionLayerTest/1.TestSimpleConvolutionGroupCuDNN  
  3. F1014 08:55:30.083176 23568 cudnn_conv_layer.cpp:30] Check failed: status == CUDNN_STATUS_SUCCESS (6 vs. 0)  CUDNN_STATUS_ARCH_MISMATCH 

因为笔记本上的GT720M的CUDA Capability是2.1,而官方的cudnn加速是不支持3.0以下的版本的,因此只能在Makefile.config中注释掉USE_CUDNN这行,重新执行如下命令:

make clean

make

make test

make runtest

另外,make runtest 时报错:make runtest  error while loading shared libraries libcudart.so.8.0

将几个文件libcudart.so.8.0 libcublas.so.8.0 libcurand.so.8.0 libcudnn.so.5 从目录/usr/local/cuda-8.0/lib64/ 拷贝到 /usr/lib/

分别执行如下操作:

sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/lib/libcudart.so.8.0

sudo ldconfig

2.5 用Mnist数据集进行测试

    a.将终端定位到Caffe根目录: cd ~/faster-rcnn/caffe

    b.下载MNIST数据库并解压缩: ./data/mnist/get_mnist.sh

    c.将其转换成Lmdb数据库格式: ./examples/mnist/create_mnist.sh

    d.训练网络: ./examples/mnist/train_lenet.sh

五.编译pycaffe

我的caffe源码放在/home/faster-rcnn/caffe

cd /home/faster-rcnn/caffe

1.1

sudo apt-get install python-dev python-pip

1.2

sudo apt-get install python-numpy

sudo apt-get install python-scipy

1.3  进入到caffe/python目录

cd python

for req in $(cat requirements.txt); do sudo pip install $req; done

    If has problem, this solution is: 修复pip

    1.download file: get-pip.py from: https://pip.pypa.io/en/latest/installing/

    2.sudo python get-pip.py

另外:在这一部,编译时还遇到了另外两个问题导致编译失败

(1)编译时提示:

The directory '/home/stone/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/home/stone/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

并用黄色标注这些提示。需要在sudo后面加-H可解决;

(2)编译时提示:

matplotlib 2.2.2 has requirement python-dateutil>=2.1, but you'll have python-dateutil 1.5 whidch is incompatible.

这主要是安装不同库之间版本不兼容导致的,这里是安装matplotlib2.2.2版本过高,需要依赖python-dateutil库版本要求大于2.1,而其他库安装要求python-dateutil的版本在1.5-2.0之间,所以发生冲突。我采用的解决方法是,通过pip安装指定版本的matplotlib 1.5.3,也就是降低matplotlib的版本,这样就会兼容。

sudo -H pip install matplotlib==1.5.3

这里加-H的原因见(1)

1.4

make pycaffe

1.5 在Ubuntu环境下,打开python解释程序,输入import caffe时,出现错误解决方法:

    a. sudo gedit ~/.bashrc

    b. export PYTHONPATH=/home/iscas/caffe/python

    c. source ~/.bashrc

1.6 测试pycaffe是否编译成功

    python

    import caffe

出现错误:ImportError: cannot import name cbook

解决方案:

卸载之前的matplotlib:

sudo pip uninstall matplotlib

使用该命令重新安装:

sudo apt-get install python-matplotlib
发布了14 篇原创文章 · 获赞 0 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xijingmingxijingming/article/details/80247090