caffe-ssd-gpu安装
1.安装步骤
1.1 安装依赖项
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev
sudo apt-get install libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
1.2 clone caffe-ssd 源码
git clone https://github.com/weiliu89/caffe.git caffe-ssd
cd caffe
git checkout ssd
这里需要出现分支成功的提示方可继续:
Branch ssd set up to track remote branch ssd from origin. Switched to a new branch ‘ssd’
1.3 文件配置
cd caffe-ssd
cp Makefile.config.example Makefile.Config
修改Makefile.config
1.若使用Cudnn
将# USE_CUDNN := 1 前的注释取消
即:USE_CUDNN := 1
2.若使用opencv3.x
取消 # OPENCV_VERSION := 3 前的注释
即:OPENCV_VERSION := 3
3.若是用Python编程
取消 # WITH_PYTHON_LAYER := 1 前的注释
即:WITH_PYTHON_LAYER := 1
4.加入hdf5的目录:
将
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
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
5. 如果使用的是Cuda>8.0,则将
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_61,code=sm_61
修改为:
CUDA_ARCH := -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_61,code=sm_61
如果计算能力大于61,还应该加上自己的,比如:
-gencode arch=compute_75,code=sm_75
修改Makefile
1. LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
修改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
2. NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
修改为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
3. LIBRARIES += boost_thread stdc++后加boost_regex
修改为:
LIBRARIES += boost_thread stdc++ boost_regex
1.4 编译
make -j16
make py
make runtest -j16
make test -j16
变异过程中出现问题:
1.caffe stdlib.h:没有那个文件或目录 #include_next <stdlib.h>
这个问题出现的原因很奇怪,重新执行了之前的所有步骤就解决了。出现原因暂时不明。
2.make: *** [.build_release/cuda/src/caffe/layers/detection_output_layer.o] Error 1
解决办法:降低gcc的版本。参考链接
本来电脑默认安装的gcc版本有两个,分别为是7.4和5.5。切换gcc版本即可。
切换的方法:
查看gcc的可用版本
sudo update-alternatives --config gcc
如果目录中存在gcc-5,则直接切换。如果不存在,则使用
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100
其中100 为优先级,需要设置得比gcc-7高。
(如果设置为一样的,则需要再次执行sudo update-alternatives --config gcc进行切换)
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail_106501::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail_106501::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
collect2: error: ld returned 1 exit status
出现上述错误的解决办法。出现原因为缺少有关boost包,那么重新编译安装boost即可。
4.make runtest -j16过程中出现
Check failed: error == cudaSuccess (8 vs. 0) invalid device function
错误原因就是Makefile.config 中没有加上自己的计算能力。
1.5 配置环境变量
gedit ~/.bashrc
export PYTHONPATH=~/caffe/python:$PATHONPATH
source ~/.bashrc
1.6测试
$python
>>> import caffe
>>>
这样就表示配置成功了,但是如果报各种稀奇古怪的错,那就
cd caffe/python
for req in $(cat requirements.txt); do pip install $req; done
这样就会安装pycaffe需要的所有的包,而且不会出现版本错误,当然这个还是提前执行的好,如果放在make all之前。