Faste R-CNN的安装及测试

一、拉取源码

下载 fast-rcnn

因下载解压后 caffe-fast-rcnn是空文件夹,故需要单独下
caffe-fast-rcnn-bcd9b4eadc7d8fbc433aeefd564e82ec63aaf69c.zip

unzip caffe-fast-rcnn-bcd9b4eadc7d8fbc433aeefd564e82ec63aaf69c.zip
cp ./caffe-fast-rcnn-bcd9b4eadc7d8fbc433aeefd564e82ec63aaf69c/ /home/cmwang/fast-rcnn-master/caffe-fast-rcnn/

二、copy缺失文件夹

因编译中出现缺失layer的问题,故需要copy缺失文件夹layers(caffe-fast-rcnn/include/caffe/ 无 layers文件夹)

可直接从caffe-master中copy或者从

cp /home/cmwang/caffe-master/include/caffe/layers/ /home/cmwang/fast-rcnn-master/caffe-fast-rcnn/include/caffe/layers/

或者
cp /home/cmwang/py-faster-rcnn/caffe-fast-rcnn/include/caffe/layers/ /home/cmwang/fast-rcnn-master/caffe-fast-rcnn/include/caffe/layers/

三、修改Makefile文件

终端输入

cd /home/cmwang/fast-rcnn-master/caffe-fast-rcnn/ 
cp Makefile.config.example Makefile.config #备份Makefile 
gedit Makefile.config

使用Python层
将# WITH_PYTHON_LAYER := 1修改为 WITH_PYTHON_LAYER := 1

调用matlab
将#MATLAB_DIR := / usr/local/MATLAB/R2015b 中的#去掉。

使用cudnn加速
将# USE_CUDNN := 1修改为USE_CUDNN := 1

保留# CPU_ONLY := 1不变,使用GPU运行faster r-cnn

四、编译Cython模块

终端输入

cd ~/caffe-fast-rcnn/lib/
make

五、编译caffe和pycaffe & matcaffe

终端输入

cd ~/caffe-fast-rcnn/caffe-fast-rcnn/ 
make -j8 && make pycaffe && make matcaffe

六、下载模型

终端输入

cd ~/caffe-fast-rcnn/

./data/scripts/fetch_faste_rcnn_models.sh 

七、Demo测试

终端输入

cd ~/caffe-fast-rcnn/

./tools/demo.py

出现的问题1

caffe —找不到lhdf5_hl和lhdf5的错误

解决方法:

cd 
gedit Makefile.config

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

这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径

建立软连接

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.8 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so

出现的问题2

When use fast R-CNN, got error like this:

I0310 08:26:43.672577 144950 net.cpp:340] Input 0 -> data
I0310 08:26:43.672601 144950 net.cpp:340] Input 1 -> rois
I0310 08:26:43.672621 144950 layer_factory.hpp:74] Creating layer conv1
I0310 08:26:43.672639 144950 net.cpp:84] Creating Layer conv1
I0310 08:26:43.672650 144950 net.cpp:380] conv1 <- data
I0310 08:26:43.672664 144950 net.cpp:338] conv1 -> conv1
I0310 08:26:43.672680 144950 net.cpp:113] Setting up conv1
Floating point exception(core dumped).

解决方案

gedit lib/fast_rcnn/train.py

添加 filter_roidb 范围,示范如下

def filter_roidb(roidb):
    """Remove roidb entries that have no usable RoIs."""

    def is_valid(entry):
        # Valid images have:
        # (1) At least one foreground RoI OR
        # (2) At least one background RoI
        overlaps = entry['max_overlaps']
        # find boxes with sufficient overlap
        fg_inds = np.where(overlaps >= cfg.TRAIN.FG_THRESH)[0]
        # Select background RoIs as those within [BG_THRESH_LO, BG_THRESH_HI)
        bg_inds = np.where((overlaps < cfg.TRAIN.BG_THRESH_HI) &
                           (overlaps >= cfg.TRAIN.BG_THRESH_LO))[0]
        # image is only valid if such boxes exist
        valid = len(fg_inds) > 0 or len(bg_inds) > 0
        return valid

    num = len(roidb)
    filtered_roidb = [entry for entry in roidb if is_valid(entry)]
    num_after = len(filtered_roidb)
    print 'Filtered {} roidb entries: {} -> {}'.format(num - num_after,
                                                       num, num_after)
    return filtered_roidb

It’s like something about box size. the solution is add filter_roidb function in lib/fast_rcnn/train.py file, like here.
Reference: https://github.com/rbgirshick/py-faster-rcnn/issues/159

其他的相关问题可参考
Faster R-CNN的安装及测试中常出现问题部分。

参考文献

caffe —找不到lhdf5_hl和lhdf5的错误

fast-rcnn github

fast-rcnn caffe-fast-rcnn

安装和运行Fast R-CNN的demo

caffe compilation troubleshooting

你可能感兴趣的:(Faste R-CNN的安装及测试)