ubuntu16 caffe GPU

来源:互联网 发布:淘宝上比较好的男鞋店 编辑:程序博客网 时间:2024/06/11 18:39

第一部分,准备材料(NVIDIA官网下载):
Cuda8.0àcuda_8.0.27_linux.run
网址:https://developer.nvidia.com/cuda-downloads

Cudnnàcudnn-7.0-linux-x64-v4.0-prod.tgz

网址:https://developer.nvidia.com/cudnn

第二部分,安装步骤

2.1系统安装

系统选择ubuntu14.04,下载后ultrISO制作到U盘安装,不细说了。关闭系统更新。

2.2、安装依赖

安装编译工具:$sudo apt-get install build-essential # basic requirement

$sudo apt-get install cmake git$sudo apt-get update    #update source

安装依赖项:

$sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler$sudo apt-get install --no-install-recommends libboost-all-dev$sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev$sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev$sudo apt-get install python-numpy python-scipy python-matplotlib

2.3、显卡驱动安装

sudo apt-get install nvidia-367 (367 qudong ban ben )

2.4、安装cuda8.0
xianzai cuda
进入cuda_8.0.27_linux.run所在目录

$cd ~/Downloads$sudo chmod +x cuda_8.0.27_linux.run$sudo ./cuda_8.0.27_linux.run

按q键退出RELU文档,按照如下选择,显卡驱动一定要选n,不装

**Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/lly]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 …**
完成后看到

*Driver: Not SelectedToolkit: Installed in /usr/local/cuda-8.0Samples: Installed in /home/zhou, but missing recommended libraries*

最后,配置环境变量,直接放在系统配置文件profile里面:

$sudo gedit /etc/profile

在最后面加入两行代码:

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

保存退出.
保存后,使环境变量立即生效,

$ source /etc/profile

执行:$ sudo ldconfig

此时,显卡驱动没装,等待下一步显卡驱动装好后检查cuda8.0是否装好。

 errors: lly@lly-desktop:~/Downloads$ sudo ldconfig/sbin/ldconfig.real: /usr/lib/nvidia-375/libEGL.so.1 is not a symbolic link/sbin/ldconfig.real: /usr/lib32/nvidia-375/libEGL.so.1 is not a symbolic link

solution:

sudo mv /usr/lib/nvidia-375/libEGL.so.1 /usr/lib/nvidia-375/libEGL.so.1.orgsudo mv /usr/lib32/nvidia-375/libEGL.so.1 /usr/lib32/nvidia-375/libEGL.so.1.orgsudo ln -s /usr/lib/nvidia-375/libEGL.so.375.39 /usr/lib/nvidia-375/libEGL.so.1sudo ln -s /usr/lib32/nvidia-375/libEGL.so.375.39 /usr/lib32/nvidia-375/libEGL.so.1

关于卸载cuda:

$cd /usr/local/cuda-8.0/bin$sudo ./uninstall_cuda_8.0.pl

2.5、检查之前的安装

此时在home目录下会出现文件夹NVIDIA_CUDA-8.0_Samples,打开终端,进入该目录:

$sudo make –j8  #编译samples,我电脑8线程,全开编译

等待2分钟左右,编译完成,执行下条指令:

$sudo ./1_Utilities/deviceQuery/deviceQuery

出现如下信息,cuda8.0安装成功(忘记截图了,下面信息是gtx670装cuda6.5的)

./deviceQuery Starting...   CUDA Device Query (Runtime API) version (CUDART static linking)  Detected 1 CUDA Capable device(s)  Device 0: "GeForce GTX 670"    CUDA Driver Version / Runtime Version          6.5 / 6.5    CUDA Capability Major/Minor version number:    3.0    Total amount of global memory:                 4095 MBytes (4294246400 bytes)    ( 7) Multiprocessors, (192) CUDA Cores/MP:     1344 CUDA Cores    GPU Clock rate:                                1098 MHz (1.10 GHz)    Memory Clock rate:                             3105 Mhz    Memory Bus Width:                              256-bit    L2 Cache Size:                                 524288 bytes    Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)    Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers    Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers    Total amount of constant memory:               65536 bytes    Total amount of shared memory per block:       49152 bytes    Total number of registers available per block: 65536    Warp size:                                     32    Maximum number of threads per multiprocessor:  2048    Maximum number of threads per block:           1024    Max dimension size of a thread block (x,y,z): (1024, 1024, 64)    Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)    Maximum memory pitch:                          2147483647 bytes    Texture alignment:                             512 bdeclared as function returning an arrayytes    Concurrent copy and kernel execution:          Yes with 1 copy engine(s)    Run time limit on kernels:                     Yes    Integrated GPU sharing Host Memory:            No    Support host page-locked memory mapping:       Yes    Alignment requirement for Surfaces:            Yes    Device has ECC support:                        Disabled    Device supports Unified Addressing (UVA):      Yes    Device PCI Bus ID / PCI location ID:           1 / 0    Compute Mode:       < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >  deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 670  Result = PASS

可以看到,最后出现了PASS,安装cuda完成。

还可以:查看nvcc版本

$nvcc --version

显示

$nvidia-smi

2.6、CUDNN安装

$tar -zxvf cudnn-7.0-linux-x64-v4.0-prod.tgz  $cd cuda$sudo cp lib64/lib* /usr/local/cuda/lib64/  $sudo cp include/cudnn.h /usr/local/cuda/include/

更新软连接:

$cd /usr/local/cuda/lib64/$sudo chmod +r libcudnn.so.5.1.5 # ziji de banben $sudo ln -sf libcudnn.so.5.1.5 libcudnn.so.5$sudo ln -sf libcudnn.so.5 libcudnn.so

更新设置:

$sudo ldconfig

2.7 opencv安装

进入这个网址下载文件https://github.com/jayrambhia/Install-OpenCV

解压后 进入其目录

$ cd Ubuntu

$ chmod +x *

$ ./opencv_latest.sh

2.8拉取caffe源码

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

2.9安装python的pip和easy_install,方便安装软件包(超慢的下载。。。)

$sudo wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py$sudo python ez_setup.py --insecure$wget https://bootstrap.pypa.io/get-pip.py$sudo python get-pip.py

2.10.安装python依赖(路径根据自己的目录可能要调一下)

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

2.11.编辑caffe所需的Makefile文件,配置

$cd caffe$cp Makefile.config.example Makefile.config$sudo gedit Makefile.config
$Makefile.config#里面有依赖库的路径,及各种编译配置,取消USE_CUDNN := 1的注释,开启GPU,USE_LMDB := 1

配置运行环境,调用CUDA库,在/etc/ld.so.conf.d目录新建caffe.conf,

$sudo gedit /etc/ld.so.conf.d/caffe.conf

添加:

/usr/local/cuda/lib64

保存退出,执行:

$sudo ldconfig

2.12、编译caffe、pycaffe

进入caffe根目录,

$sudo make –j8

error:

src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such file or directoryhttp://blog.csdn.net/xue_wenyuan/article/details/52037121

http://blog.csdn.net/xue_wenyuan/article/details/52037121
这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径.
Step 1
在Makefile.config文件的第85/94行,添加/usr/include/hdf5/serial/ 到 INCLUDE_DIRS,也就是把下面第一行代码改为第二行代码。

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/includeINCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

Step 2
在Makefile文件的第173/181行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和 hdf5_serial,也就是把下面第一行代码改为第二行代码。

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

测试一下结果,

$sudo make test –j8$sudo make runtest –j8

(runtest中个别没通过没关系,不影响使用)

$make pycaffe –j8

Makefile.config zhong python lujing yao xie dui

errors:
http://blog.csdn.net/hongye000000/article/details/51043913

第三部分,拿cifar10测试下效果

$cd /home/smith/caffe
$sudo sh data/cifar10/get_cifar10.sh # (脚本下载速度太慢,找个迅雷下载拷进来,再照脚本解压)
# sudo sh examples/cifar10/create_cifar10.sh# sudo sh examples/cifar10/train_quick.sh

下面,网络开始初始化、训练了,loss会开始下降,很快的就会出现优化完成。

原创粉丝点击