Skip to content

Commit d568f7b

Browse files
committed
add voc training configs and eval script
1 parent 60d5bc5 commit d568f7b

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# model settings
2+
model = dict(
3+
type='FasterRCNN',
4+
pretrained='modelzoo://resnet50',
5+
backbone=dict(
6+
type='ResNet',
7+
depth=50,
8+
num_stages=4,
9+
out_indices=(0, 1, 2, 3),
10+
frozen_stages=1,
11+
style='pytorch'),
12+
neck=dict(
13+
type='FPN',
14+
in_channels=[256, 512, 1024, 2048],
15+
out_channels=256,
16+
num_outs=5),
17+
rpn_head=dict(
18+
type='RPNHead',
19+
in_channels=256,
20+
feat_channels=256,
21+
anchor_scales=[8],
22+
anchor_ratios=[0.5, 1.0, 2.0],
23+
anchor_strides=[4, 8, 16, 32, 64],
24+
target_means=[.0, .0, .0, .0],
25+
target_stds=[1.0, 1.0, 1.0, 1.0],
26+
use_sigmoid_cls=True),
27+
bbox_roi_extractor=dict(
28+
type='SingleRoIExtractor',
29+
roi_layer=dict(type='RoIAlign', out_size=7, sample_num=2),
30+
out_channels=256,
31+
featmap_strides=[4, 8, 16, 32]),
32+
bbox_head=dict(
33+
type='SharedFCBBoxHead',
34+
num_fcs=2,
35+
in_channels=256,
36+
fc_out_channels=1024,
37+
roi_feat_size=7,
38+
num_classes=21,
39+
target_means=[0., 0., 0., 0.],
40+
target_stds=[0.1, 0.1, 0.2, 0.2],
41+
reg_class_agnostic=False))
42+
# model training and testing settings
43+
train_cfg = dict(
44+
rpn=dict(
45+
assigner=dict(
46+
type='MaxIoUAssigner',
47+
pos_iou_thr=0.7,
48+
neg_iou_thr=0.3,
49+
min_pos_iou=0.3,
50+
ignore_iof_thr=-1),
51+
sampler=dict(
52+
type='RandomSampler',
53+
num=256,
54+
pos_fraction=0.5,
55+
neg_pos_ub=-1,
56+
add_gt_as_proposals=False),
57+
allowed_border=0,
58+
pos_weight=-1,
59+
smoothl1_beta=1 / 9.0,
60+
debug=False),
61+
rcnn=dict(
62+
assigner=dict(
63+
type='MaxIoUAssigner',
64+
pos_iou_thr=0.5,
65+
neg_iou_thr=0.5,
66+
min_pos_iou=0.5,
67+
ignore_iof_thr=-1),
68+
sampler=dict(
69+
type='RandomSampler',
70+
num=512,
71+
pos_fraction=0.25,
72+
neg_pos_ub=-1,
73+
add_gt_as_proposals=True),
74+
pos_weight=-1,
75+
debug=False))
76+
test_cfg = dict(
77+
rpn=dict(
78+
nms_across_levels=False,
79+
nms_pre=2000,
80+
nms_post=2000,
81+
max_num=2000,
82+
nms_thr=0.7,
83+
min_bbox_size=0),
84+
rcnn=dict(
85+
score_thr=0.05, nms=dict(type='nms', iou_thr=0.5), max_per_img=100)
86+
# soft-nms is also supported for rcnn testing
87+
# e.g., nms=dict(type='soft_nms', iou_thr=0.5, min_score=0.05)
88+
)
89+
# dataset settings
90+
dataset_type = 'VOCDataset'
91+
data_root = 'data/VOCdevkit/'
92+
img_norm_cfg = dict(
93+
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
94+
data = dict(
95+
imgs_per_gpu=2,
96+
workers_per_gpu=2,
97+
train=dict(
98+
type='RepeatDataset', # to avoid reloading datasets frequently
99+
times=3,
100+
dataset=dict(
101+
type=dataset_type,
102+
ann_file=[
103+
data_root + 'VOC2007/ImageSets/Main/trainval.txt',
104+
data_root + 'VOC2012/ImageSets/Main/trainval.txt'
105+
],
106+
img_prefix=[data_root + 'VOC2007/', data_root + 'VOC2012/'],
107+
img_scale=(1000, 600),
108+
img_norm_cfg=img_norm_cfg,
109+
size_divisor=32,
110+
flip_ratio=0.5,
111+
with_mask=False,
112+
with_crowd=True,
113+
with_label=True)),
114+
val=dict(
115+
type=dataset_type,
116+
ann_file=data_root + 'VOC2007/ImageSets/Main/test.txt',
117+
img_prefix=data_root + 'VOC2007/',
118+
img_scale=(1000, 600),
119+
img_norm_cfg=img_norm_cfg,
120+
size_divisor=32,
121+
flip_ratio=0,
122+
with_mask=False,
123+
with_crowd=True,
124+
with_label=True),
125+
test=dict(
126+
type=dataset_type,
127+
ann_file=data_root + 'VOC2007/ImageSets/Main/test.txt',
128+
img_prefix=data_root + 'VOC2007/',
129+
img_scale=(1000, 600),
130+
img_norm_cfg=img_norm_cfg,
131+
size_divisor=32,
132+
flip_ratio=0,
133+
with_mask=False,
134+
with_label=False,
135+
test_mode=True))
136+
# optimizer
137+
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
138+
optimizer_config = dict(grad_clip=dict(max_norm=35, norm_type=2))
139+
# learning policy
140+
lr_config = dict(policy='step', step=[3]) # actual epoch = 3 * 3 = 9
141+
checkpoint_config = dict(interval=1)
142+
# yapf:disable
143+
log_config = dict(
144+
interval=50,
145+
hooks=[
146+
dict(type='TextLoggerHook'),
147+
# dict(type='TensorboardLoggerHook')
148+
])
149+
# yapf:enable
150+
# runtime settings
151+
total_epochs = 4 # actual epoch = 4 * 3 = 12
152+
dist_params = dict(backend='nccl')
153+
log_level = 'INFO'
154+
work_dir = './work_dirs/faster_rcnn_r50_fpn_1x_voc0712'
155+
load_from = None
156+
resume_from = None
157+
workflow = [('train', 1)]

tools/voc_eval.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from argparse import ArgumentParser
2+
3+
import mmcv
4+
import numpy as np
5+
6+
from mmdet import datasets
7+
from mmdet.core import eval_map
8+
9+
10+
def voc_eval(result_file, dataset, iou_thr=0.5):
11+
det_results = mmcv.load(result_file)
12+
gt_bboxes = []
13+
gt_labels = []
14+
gt_ignore = []
15+
for i in range(len(dataset)):
16+
ann = dataset.get_ann_info(i)
17+
bboxes = ann['bboxes']
18+
labels = ann['labels']
19+
if 'bboxes_ignore' in ann:
20+
ignore = np.concatenate([
21+
np.zeros(bboxes.shape[0], dtype=np.bool),
22+
np.ones(ann['bboxes_ignore'].shape[0], dtype=np.bool)
23+
])
24+
gt_ignore.append(ignore)
25+
bboxes = np.vstack([bboxes, ann['bboxes_ignore']])
26+
labels = np.concatenate([labels, ann['labels_ignore']])
27+
gt_bboxes.append(bboxes)
28+
gt_labels.append(labels)
29+
if not gt_ignore:
30+
gt_ignore = gt_ignore
31+
if hasattr(dataset, 'year') and dataset.year == 2007:
32+
dataset_name = 'voc07'
33+
else:
34+
dataset_name = dataset.CLASSES
35+
eval_map(
36+
det_results,
37+
gt_bboxes,
38+
gt_labels,
39+
gt_ignore=gt_ignore,
40+
scale_ranges=None,
41+
iou_thr=iou_thr,
42+
dataset=dataset_name,
43+
print_summary=True)
44+
45+
46+
def main():
47+
parser = ArgumentParser(description='VOC Evaluation')
48+
parser.add_argument('result', help='result file path')
49+
parser.add_argument('config', help='config file path')
50+
parser.add_argument(
51+
'--iou-thr',
52+
type=float,
53+
default=0.5,
54+
help='IoU threshold for evaluation')
55+
args = parser.parse_args()
56+
cfg = mmcv.Config.fromfile(args.config)
57+
test_dataset = mmcv.runner.obj_from_dict(cfg.data.test, datasets)
58+
voc_eval(args.result, test_dataset, args.iou_thr)
59+
60+
61+
if __name__ == '__main__':
62+
main()

0 commit comments

Comments
 (0)