使用faster rcnn訓練自己的資料(py-faster-rcnn )
出於在csdn上面學到很多東西這裡也幫自己的一些收穫和大家分享一下
直奔主題~~
前提是已經安裝好caffe的環境 本文是在Ubuntu 15.04下做的測試 $Faster_rcnn表示py-faster-rcnn根目錄
1. 修改資料介面 ($Faster_rcnn/lib/datasets)
目錄下面的pascal_voc.py是主要的資料讀取介面
- self._classes = ('__background__', # always index 0
'bottle', 'bus', 'car', 'cat', 'chair',
'cow', 'diningtable', 'dog', 'horse',
'motorbike', 'person', 'pottedplant',
'sheep', 'sofa', 'train', 'tvmonitor')
這裡定義了要訓練的類別,修改這裡為自己需要訓練資料的類標籤,注意總類別包括背景
- 如果需要使用PASCAL資料庫中的個別類 需要在
if not self.config['use_diff']:
# Exclude the samples labeled as difficult
non_diff_objs = [
obj for obj in objs if int(obj.find('difficult').text) == 0]
# if len(non_diff_objs) != len(objs):
# print 'Removed {} difficult objects'.format(
# len(objs) - len(non_diff_objs))
objs = non_diff_objs
########################################
valid_class_objs = [
obj for obj in objs if obj.find('name').text in self._classes]
objs = valid_class_objs
########################################
num_objs = len(objs)
新增#兩行中間部分
2. 修改模型引數($Faster_rcnn/models/pascal_voc)
其中有三種網路模型 VGG16 ZF VGG_CNN_M_1024
硬體需要參考RGB大神寫的
Requirements: hardware
- For training smaller networks (ZF, VGG_CNN_M_1024) a good GPU (e.g., Titan, K20, K40, ...) with at least 3G of memory suffices
- For training Fast R-CNN with VGG16, you'll need a K40 (~11G of memory)
Usage
To train and test a Faster R-CNN detector using the alternating optimization algorithm from our NIPS 2015 paper, useexperiments/scripts/faster_rcnn_alt_opt.sh
.
Output is written underneath $FRCN_ROOT/output
.
cd $FRCN_ROOT ./experiments/scripts/faster_rcnn_alt_opt.sh [GPU_ID] [NET] [--set ...] # GPU_ID is the GPU you want to train on # NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use # --set ... allows you to specify fast_rcnn.config options, e.g. # --set EXP_DIR seed_rng1701 RNG_SEED 1701
("alt opt" refers to the alternating optimization training algorithm described in the NIPS paper.)
To train and test a Faster R-CNN detector using the approximate joint training method, useexperiments/scripts/faster_rcnn_end2end.sh
.
Output is written underneath $FRCN_ROOT/output
.
cd $FRCN_ROOT ./experiments/scripts/faster_rcnn_end2end.sh [GPU_ID] [NET] [--set ...] # GPU_ID is the GPU you want to train on # NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use # --set ... allows you to specify fast_rcnn.config options, e.g. # --set EXP_DIR seed_rng1701 RNG_SEED 1701參考 https://github.com/rbgirshick/py-faster-rcnn