一、环境准备
装cuda9.0时make runtest会出现,Check failed: status == CUBLAS_STATUS_SUCCESS (13 vs. 0) CUBLAS_STATUS_EXECUTION_FAILED
改装成cuda8.0之后一切OK,目测是cuda9.0和显卡驱动的兼容问题影响的。
1、anaconda3创建虚拟环境激活环境create -n py2.7 python=2.7
2、克隆py-faster-rcnn源码,参数递归克隆
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
二、依赖安装
进入到caffe-faster-rcnn目录执行pip install -r requirement.s.txt
sudo apt-get install 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 python-yaml
sudo pip install easydict
安装opencv及其组件
pip install opencv-python
pip install opencv-contrib-python
安装openblas(BLAS是为caffe打造的基于c++的矩阵运算库,类似numpy)
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS
make -j8
make install
#设置环境变量
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/:$LD_LIBRARY_PATH
condalist截图:
pip list结
三、修改Makefile.configue 编译文件取消注释并修改
USE_CUDNN := 1
# OPENCV_VERSION := 3 如果使用的是opencv3就取消注释,否则不。
BLAS := open
BLAS_INCLUDE := /opt/OpenBLAS/include
BLAS_LIB := /opt/OpenBLAS/lib
#cuda8.0要求把_20,_21删除,加上
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_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61 \
WITH_PYTHON_LAYER := 1 #开启python
替换
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
#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
将:NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
蓝色的这一句好像改不改都不影响,建议先不改,后面报错了再改吧。
五、Faster R-CNN 并不支持CUDNN5.1以上, 所以需要合并Caffe来支持。
替换py-faster-rcnn中/include/caffe/layers/cudnn_*
/src/caffe/layers/cudnn_*
/include/caffe/utils/cudnn.hpp
以上三个必换,还有就是网上说有换src/caffe/utils/cudnn_*的,不换好像也不影响,反正能不换就不换。
六、编译
修改python_layer.hp
版本合并后,打开caffe-fast-rcnn/include/caffe/layers/python_layer.hp,self_.attr("phase") = static_cast<int>(this->phase_);这一行(line29)删除(如果有的话就删除,没有就不修改,可能会没有)
cd $FRCN_ROOT/lib (或者cd py-faster-rcnn/lib) make #编译Cython
cd py-faster-rcnn
make -j8
make test
make runtest
make pycaffe
七、报错:CXX .build_release/src/caffe/proto/caffe.pb.cc
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: 找不到 -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:554: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
解决办法:修改Makefile :LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
报错:src/caffe/test/test_smooth_L1_loss_layer.cpp:11:35: fatal error: caffe/vision_layers.hpp: 没有那个文件或目录
compilation terminated.
Makefile:564: recipe for target '.build_release/src/caffe/test/test_smooth_L1_loss_layer.o' failed
make: *** [.build_release/src/caffe/test/test_smooth_L1_loss_layer.o] Error 1
解决办法:vim ~/py-faster-rcnn/caffe-fast-rcnn/src/caffe/tes/test_smooth_L1_loss_layer.cpp 屏蔽
//#include "caffe/vision_layers.hpp"