用faster-rcnn训练自己的数据集(VOC2007格式,python版)
一. 配置caffe环境
二. 下载,编译及测试py-faster-rcnn源码
(一)下载源码
或者执行 git clone –recursive https://github.com/rbgirshick/py-faster-rcnn.git
注意加上–recursive关键字
(二)编译源码
编译过程中可能会出现缺失一些python模块,按提示安装
(1)编译Cython模块
cd $FRCN_ROOT/lib
make
(2)修改Markfile配置
参考ubunt16.04下caffe环境安装
中修改Makefile.config
(3)编译python接口
cd $FRCN_ROOT/caffe-fast-rcnn
make -j8 多核编译,时间较长
make pycaffe
(4)下载训练好的VGG16和ZF模型
cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh
时间太长的话可以考虑找网上别人分享的资源
(三)测试源码
cd $FRCN_ROOT
./tool/demo.py
三. 使用faster-rcnn训练自己的数据集
(一)下载预训练参数及模型
cd $FRCN_ROOT
./data/scripts/fetch_imagenet_models.sh
./data/scripts/fetch_selective_search_data.sh
(二)制作数据集
将制作好的VOC2007文件夹放置在data/VOCdevkit2007文件夹下,没有则新建VOCdevkit2007文件夹
(三)修改配置文件
(1)修改py-faster-rcnn/models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_fast_rcnn_train.pt和stage2_fast_rcnn_train.pt 两个文件
备注:3处修改及其附近的代码
name: "ZF"
layer {
name: 'data'
type: 'Python'
top: 'data'
top: 'rois'
top: 'labels'
top: 'bbox_targets'
top: 'bbox_inside_weights'
top: 'bbox_outside_weights'
python_param {
module: 'roi_data_layer.layer'
layer: 'RoIDataLayer'
param_str: "'num_classes': 2" #按训练集类别改,该值为类别数+1
}
}
layer {
name: "cls_score"
t