forked from open-mmlab/mmyolo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yolov5_ins_s-v61_syncbn_fast_8xb16-300e_coco_instance.py
126 lines (118 loc) · 4.24 KB
/
yolov5_ins_s-v61_syncbn_fast_8xb16-300e_coco_instance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
_base_ = '../yolov5_s-v61_syncbn_fast_8xb16-300e_coco.py' # noqa
# ========================modified parameters======================
# YOLOv5RandomAffine
use_mask2refine = True
max_aspect_ratio = 100
min_area_ratio = 0.01
# Polygon2Mask
downsample_ratio = 4
mask_overlap = True
# LeterResize
# half_pad_param: if set to True, left and right pad_param will
# be given by dividing padding_h by 2. If set to False, pad_param is
# in int format. We recommend setting this to False for object
# detection tasks, and True for instance segmentation tasks.
# Default to False.
half_pad_param = True
# Testing take a long time due to model_test_cfg.
# If you want to speed it up, you can increase score_thr
# or decraese nms_pre and max_per_img
model_test_cfg = dict(
multi_label=True,
nms_pre=30000,
min_bbox_size=0,
score_thr=0.001,
nms=dict(type='nms', iou_threshold=0.6),
max_per_img=300,
mask_thr_binary=0.5,
# fast_test: Whether to use fast test methods. When set
# to False, the implementation here is the same as the
# official, with higher mAP. If set to True, mask will first
# be upsampled to origin image shape through Pytorch, and
# then use mask_thr_binary to determine which pixels belong
# to the object. If set to False, will first use
# mask_thr_binary to determine which pixels belong to the
# object , and then use opencv to upsample mask to origin
# image shape. Default to False.
fast_test=True)
# ===============================Unmodified in most cases====================
model = dict(
type='YOLODetector',
bbox_head=dict(
type='YOLOv5InsHead',
head_module=dict(
type='YOLOv5InsHeadModule', mask_channels=32, proto_channels=256),
mask_overlap=mask_overlap,
loss_mask=dict(
type='mmdet.CrossEntropyLoss', use_sigmoid=True, reduction='none'),
loss_mask_weight=0.05),
test_cfg=model_test_cfg)
pre_transform = [
dict(type='LoadImageFromFile', backend_args=_base_.backend_args),
dict(
type='LoadAnnotations',
with_bbox=True,
with_mask=True,
mask2bbox=use_mask2refine)
]
train_pipeline = [
*pre_transform,
dict(
type='Mosaic',
img_scale=_base_.img_scale,
pad_val=114.0,
pre_transform=pre_transform),
dict(
type='YOLOv5RandomAffine',
max_rotate_degree=0.0,
max_shear_degree=0.0,
scaling_ratio_range=(1 - _base_.affine_scale, 1 + _base_.affine_scale),
border=(-_base_.img_scale[0] // 2, -_base_.img_scale[1] // 2),
border_val=(114, 114, 114),
min_area_ratio=min_area_ratio,
max_aspect_ratio=max_aspect_ratio,
use_mask_refine=use_mask2refine),
# TODO: support mask transform in albu
# Geometric transformations are not supported in albu now.
dict(
type='mmdet.Albu',
transforms=_base_.albu_train_transforms,
bbox_params=dict(
type='BboxParams',
format='pascal_voc',
label_fields=['gt_bboxes_labels', 'gt_ignore_flags']),
keymap={
'img': 'image',
'gt_bboxes': 'bboxes'
}),
dict(type='YOLOv5HSVRandomAug'),
dict(type='mmdet.RandomFlip', prob=0.5),
dict(
type='Polygon2Mask',
downsample_ratio=downsample_ratio,
mask_overlap=mask_overlap),
dict(
type='PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'flip',
'flip_direction'))
]
test_pipeline = [
dict(type='LoadImageFromFile', backend_args=_base_.backend_args),
dict(type='YOLOv5KeepRatioResize', scale=_base_.img_scale),
dict(
type='LetterResize',
scale=_base_.img_scale,
allow_scale_up=False,
half_pad_param=half_pad_param,
pad_val=dict(img=114)),
dict(type='LoadAnnotations', with_bbox=True, _scope_='mmdet'),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
'scale_factor', 'pad_param'))
]
train_dataloader = dict(dataset=dict(pipeline=train_pipeline))
val_dataloader = dict(dataset=dict(pipeline=test_pipeline))
test_dataloader = val_dataloader
val_evaluator = dict(metric=['bbox', 'segm'])
test_evaluator = val_evaluator