Ubuntu16.04+Cuda8.0+1080ti+caffe+faster-rcnn教程

一、事先声明:
1、Ubuntu版本:Ubuntu使用的是16.04。而不是16.04.1或16.04.2,这三个是有区别的。笔者曾有过这样的经历,Git上一个SLAM地图构建程序在Ubuntu14.04.3上可以正常make与工作,而14.04.4却一塌Error。。。

可自己在Google搜索关键字“Ubuntu16.04.1”做“引子”找到历史版本,第一个就是。在此我们放出网址:

http://old-releases.ubuntu.com/releases/16.04.1/

问:有两个“64-bit PC (AMD64) desktop image”怎么办?那个才是16.04?
答:点进去看看ISO前缀名称!


2、为什么免安装OpenCV?因为执行完下面语句OpenCV就自动安装上了,但不是OpenCV3,而是OpenCV 2.4.9.1。

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 

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

sudo apt-get install -y python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython 

可用命令

pkg-config --modversion opencv

查询一下,faster-rcnn用OpenCV2的即可正常运行。如果您非要使用CV3,这里也给出参考教程。要相信OpenCV3不是三四行shell就能装好的。

OpenCV3.2.0安装链接如下

https://www.linuxhint.com/how-to-install-opencv-on-ubuntu/


二、软件版本:

Ubuntu16.04

Cuda8.0

1080ti驱动

OpenCV3.2.0

cuDNN5.1 (5.1.10)

glog-0.3.3.tar.gz

注:以上这些都可以事先下载好。

注意:安装完Ubuntu后记得关闭“自动更新”。笔者装机完,正常使用两天后,出现了ubuntu反复登录桌面的问题。我是重装了Unity,也装了GDM。但愿你不会出现这类问题,如果出现了,下面给出解决链接。

http://www.linuxidc.com/Linux/2011-07/39491.htm

http://forum.ubuntu.org.cn/viewtopic.php?t=460910


三、安装Caffe参考:

1、主要参考:

迷途de小狼:

http://blog.csdn.net/u010733679/article/details/52249503

2、辅助参考:

http://www.jianshu.com/p/69a10d0a24b9

http://blog.csdn.net/yan_song_/article/details/53154611

http://www.linuxidc.com/Linux/2016-09/135016.htm

http://blog.csdn.net/zhangzhenyuancs/article/details/52261004

3、声明与建议:

在此感谢几位网友的博客,正是参考了几位大神的博客才有我的成功安装。如有版权问题,请联系我,谢谢。

另外就是给要安装的朋友们给两个建议,自己搜索、或从上面的参考中至少选择三四篇文章通篇阅读一下,形成适合自己的安装思路。别人(包括本Blog)的环境都可能和屏幕前的你有所出入,所以要有所取舍。


四、安装Caffe步骤:

1、安装Ubuntu16.04

120G SSD:

/boot 400MB

/ SSD剩余所有

swap 内存两倍空间(心疼SSD的可放在2T机械)

2T

/home


2、安装1080ti驱动

Ctrl+alt+F1//进入字符界面
sudo service lightdm stop //关闭lightdm登录管理器 
sudo chmod 755 NVIDIA-Linux-x86_64-378.13.run  //获取权限  
sudo ./NVIDIA-Linux-x86_64-378.13.run  //安装驱动

Accept 

Continue installation 

安装完成之后

sudo service lightdm start


3、安装Cuda8.0

sudo sh ./cuda_8.0.61_375.26_linux-run
进入安装命令行
---Do you accept the previously read EULA?
accept/decline/quit: accept
---Install NVIDIA Accelerated Graphics Driver for Linux-x86_64361.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/duan ]:回车


//配置环境变量:

sudo gedit /etc/profile
//在文件末尾加入以下2行
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
//然后
sudo ldconfig
//验证cuda是否安装成功
cd NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery
make
./deviceQuery 
//如果显示pass,则代表成功。


4、安装OpenCV(可跳过,Ubuntu默认安装cv2):

见第一章网址,不用修改什么源文件。

注:如果你是4/8线程可用下代码加速编译:

make -j4       #四核运算

5、安装依赖项:

1)Google Logging Library(glog),下载地址:https://code.google.com/p/google-glog/,然后解压安装:
$ tar zxvf glog-0.3.3.tar.gz
$ cd glog-0.3.3 
$./configure
$ make
$ sudo make install
如果没有权限就chmod a+x glog-0.3.3 -R , 或者索性 chmod 777 glog-0.3.3 -R 。


2)其他依赖项,确保都成功

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


6、安装Caffe,并用MNIST数据集测试:

1)安装pycaffe必须的一些依赖项:

sudo apt-get install -y python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython 


2)安装配置nVidia cuDNN 加速Caffe模型运算

1. $ sudo cp include/cudnn.h /usr/local/include  
2. $ sudo cp lib64/libcudnn.* /usr/local/lib
3. $ sudo ln -sf /usr/local/lib/libcudnn.so.5.1.10 /usr/local/lib/libcudnn.so.5  
4. $ sudo ln -sf /usr/local/lib/libcudnn.so.5 /usr/local/lib/libcudnn.so  
5. $ sudo ldconfig -v  
注:大家根据自己的cuDNN版本修改;如果懒于敲目录,可在Unity文件管理器下将文件夹拖入终端;终端下的“粘贴”快捷键:Ctrl+Shift+v。

3)切换到Caffe-master的文件夹,生成Makefile.config配置文件,执行:

$ cp Makefile.config.example Makefile.config

4)配置Makefile.config文件

a.去掉“USE_CUDNN := 1”前面的#

b.根据前面自己的需求,选择性去掉“OPENCV_VERSION :=3”前面的#

c.配置一些引用文件(增加部分主要是解决新版本下,HDF5的路径问题)
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

下面贴出我的Makefile.config文件

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
 USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#	You should not set this flag if you will be reading LMDBs with any
#	possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
		-gencode arch=compute_20,code=sm_21 \
		-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @



5)编译caffe-master!!!"-j4"是使用CPU的多核进行编译,可以极大地加速编译的速度,建议使用。

注:下面的make命令适当的时候加上sudo,建议都已super do来运行。

$ make all -j4
$ make test -j4 
$ make runtest -j4

期间会遇到下面的问题:

问题:mkl_alternate.hpp:14:19 fatal error: cblas.h: 没有那个文件或目录

解决:https://github.com/BVLC/caffe/issues/3599

sudo apt-get install libopenblas-dev


问题:找不到 -lablas、-latlas

解决:

sudo apt-get install libatlas-base-dev

可能问题:.build_release/lib/libcaffe.so.1.0.0 Error 1 /usr/bin/ld: 找不到 -lopencv_imgcodecs

解决:你没有安装好CV3,可选择加上b的井号,或参考

https://my.oschina.net/peterlie/blog/661994

http://blog.csdn.net/foolsnowman/article/details/50532226


问题:caffe libcudart.so.8.0 cannot open shared object file no such file or directory

解决:https://github.com/NVIDIA/DIGITS/issues/8

sudo ldconfig /usr/local/cuda/lib64


问题:nvcc warring: the 'compute_20', 'sm_20', and 'sm_21'

解决:我是不理会,不影响使用,想看一眼的可参考以下网址:

http://www.itwendao.com/article/detail/214390.html


6)编译Python和Matlab用到的caffe文件

$ make pycaffe -j4

7)测试

打开example -> MNIST -> Readme.md

按照最前面,cd到Caffe根目录,运行第一页的两个命令,进行下载和格式转换(不超过30MB的下载量)

再运行最下面的命令,Training,看命令行盖楼。。。


五、安装faster-r-cnn参考

bit_hammer大神:

http://blog.csdn.net/u011635764/article/details/52831167


cuDNN v5、v5.1的问题

http://blog.csdn.net/u010733679/article/details/52221404


大家按照bit_hammer大神的步骤安装就好,关于cuDNN v5.1的处理,两篇文章都一样的。

注:faster-r-cnn一定要从Git Clone,Download ZIP不全。


六、测试faster-r-cnn

从百度云盘下载训练好的模型:

VGG16_faster_rcnn_final.caffemodel (548.3MB)

2F_faster_rcnn_final.caffemodel (237.2MB)

将上述两个文件存放于:

py-faster-rcnn/data/faster_rcnn_models/

下,即可运行步骤五中的Demo。


七、使用py-faster-rcnn训练VOC2007数据集时遇到的问题

以下是我师姐整理的 ~_~

http://www.cnblogs.com/JZ-Ser/p/6924156.html


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值