Ubuntu16.04 安装 Caffe(SSD版)

安装步骤

首先从github上面拷贝下来caffe项目:

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

安装caffe版的SSD拷贝步骤为:

git clone https://github.com/weiliu89/caffe.git
cd caffe
git checkout ssd

然后将caffe主目录下面的Makefile.config.example拷贝更名为Makefile.config,打开操作:

cp Makefile.config.example Makefile.config
gedit Makefile.config


将其中的:

#USE_CUDNN := 1
#WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

分别更改为:

USE_CUDNN := 1
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

打开 Makefile文件:

gedit makefile

将其中的:

NVCCFLAGS += -ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)

更改为:

NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

打开/usr/local/cuda/include/crt/host_config.h文件:

sudo gedit /usr/local/cuda/include/crt/host_config.h

将其中的:

#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

更改为:

//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

下面就是编译caffe并测试:

make clean -j8
make all -j8 
make runtest -j8

最后输出PASS说明测试成功。
配置环境变量:

vim ~/.bashrc

在文件末尾写入caffe-pathon的安装路径:

export PYTHONPATH=~/caffe/python:$PYTHONPATH

上述语句中的~表示caffe所在的根目录。
是环境变量生效:

source ~/.bashrc

然后执行:

make pycaffe

cuda9编译问题

错误:
NVCC src/caffe/layers/bnll_layer.cu
nvcc fatal   : Unsupported gpu architecture 'compute_20'
Makefile:594: recipe for target '.build_release/cuda/src/caffe/layers/bnll_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/bnll_layer.o] Error 1
make: *** Waiting for unfinished jobs....
原因

cuda9不支持‘ compute-20 ’

解决方案

修改Makefile.config文件中CUDA_ARCH设置,将

# 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.
# For CUDA >= 9.0, comment the *_20 and *_21 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

中的

-gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \

删除即可重新编译。

本人博客:寸山河
本人GitHub:王顺
欢迎大家一起交流学习。

猜你喜欢

转载自blog.csdn.net/wgshun616/article/details/81019574