配置fast-rcnn并进行二分类实验

参考原作者github:https://github.com/rbgirshick/fast-rcnn

1. 下载fast-rcnn

git clone --recursive https://github.com/rbgirshick/fast-rcnn.git
如果caffe-fast-rcnn目录没有下下来,则执行:

git submodule update --init --recursive
2. 编译fast-rcnn

cd $FRCN_ROOT/lib
make
进入caffe-fast-rcnn目录,复制Makefile.config.example文件,重命名为Makefile.config。

执行:

cd $FRCN_ROOT/caffe-fast-rcnn
make -j8 && make pycaffe

运行demo:

cd $FRCN_ROOT
./tools/demo.py



3. 修改数据集

1.修改lib/datasetsfactory.py文件

    factory.py调用pascal_voc.py。修改数据集名。

2.修改pascal_voc.py文件

pascal_voc.py初始化数据集。主要修改以下方面:

1) 数据集地址相关

2) selective_search生成的.mat文件

      可使用的selective_search代码:https://github.com/AlpacaDB/selectivesearch

      生成备选框的代码:

from selectivesearch import selective_search
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from numpy import *  
import scipy.io as scio
import os

def generateBoxes(pic_name, im_path, mat_dir):
    img = cv2.imread(im_path)
    # perform selective search
    img_lbl, regions = selective_search(
        img, scale=200, sigma=0.8, min_size=100)

    candidates = []
    for r in regions:
        # excluding same rectangle (with different segments)
        if r['rect'] in candidates:
            continue
        # excluding regions smaller than 2000 pixels
        if r['size'] < 2:
            continue
        # distorted rects
        x, y, w, h = r['rect']
        if w==0 or h==0:
            continue
        if w/h > 4 or h/w > 10:
            continue
        candidates.append([x,y,x+w,y+h])
    # draw_boxes()
    # result = {'boxes': array(candidates)}
    # print '{} candidates in picture {}.'.format(len(candidates), pic_name)
    # mat_dir = os.path.join(mat_dir, pic_name+'.mat')
    # scio.savemat(mat_dir, result)  
    return candidates

def draw_boxes(img, candidates):
    # draw rectangles on the original image
    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    ax.imshow(img)
    for x, y, w, h in candidates:
        rect = mpatches.Rectangle(
            (x, y), w, h, fill=False, edgecolor='red', linewidth=1)
        ax.add_patch(rect)

    plt.show()
    return

3) _load_selective_search_roidb()函数

    如果.mat文件格式(尤其是box坐标)有修改

4) _load_pascal_annotation()函数

    我只要voc数据集中的person的数据,则要修改num_objs的赋值和obj的遍历。

5) self._classes

TIPS:

* 如果报错:

Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python
参考:https://blog.csdn.net/huobanjishijian/article/details/78582315  (重新make之前先make clean)

asd

asd


阅读更多
上一篇Ubuntu14.04安装配置深度网络SSD
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭