Upload rtmdet-m.py
Browse files- rtmdet-m.py +179 -5
rtmdet-m.py
CHANGED
@@ -1,7 +1,181 @@
|
|
1 |
-
_base_ =
|
2 |
-
|
|
|
|
|
|
|
|
|
3 |
model = dict(
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
_base_ = [
|
2 |
+
"mmdet::_base_/default_runtime.py",
|
3 |
+
"mmdet::_base_/schedules/schedule_1x.py",
|
4 |
+
"mmdet::_base_/datasets/coco_detection.py",
|
5 |
+
"mmdet::rtmdet/rtmdet_tta.py",
|
6 |
+
]
|
7 |
model = dict(
|
8 |
+
type="RTMDet",
|
9 |
+
data_preprocessor=dict(
|
10 |
+
type="DetDataPreprocessor",
|
11 |
+
mean=[103.53, 116.28, 123.675],
|
12 |
+
std=[57.375, 57.12, 58.395],
|
13 |
+
bgr_to_rgb=False,
|
14 |
+
batch_augments=None,
|
15 |
+
),
|
16 |
+
backbone=dict(
|
17 |
+
type="CSPNeXt",
|
18 |
+
arch="P5",
|
19 |
+
expand_ratio=0.5,
|
20 |
+
deepen_factor=0.67,
|
21 |
+
widen_factor=0.75,
|
22 |
+
channel_attention=True,
|
23 |
+
norm_cfg=dict(type="SyncBN"),
|
24 |
+
act_cfg=dict(type="SiLU", inplace=True),
|
25 |
+
),
|
26 |
+
neck=dict(
|
27 |
+
type="CSPNeXtPAFPN",
|
28 |
+
in_channels=[192, 384, 768],
|
29 |
+
out_channels=192,
|
30 |
+
num_csp_blocks=2,
|
31 |
+
expand_ratio=0.5,
|
32 |
+
norm_cfg=dict(type="SyncBN"),
|
33 |
+
act_cfg=dict(type="SiLU", inplace=True),
|
34 |
+
),
|
35 |
+
bbox_head=dict(
|
36 |
+
type="RTMDetSepBNHead",
|
37 |
+
num_classes=80,
|
38 |
+
in_channels=192,
|
39 |
+
stacked_convs=2,
|
40 |
+
feat_channels=192,
|
41 |
+
anchor_generator=dict(type="MlvlPointGenerator", offset=0, strides=[8, 16, 32]),
|
42 |
+
bbox_coder=dict(type="DistancePointBBoxCoder"),
|
43 |
+
loss_cls=dict(
|
44 |
+
type="QualityFocalLoss", use_sigmoid=True, beta=2.0, loss_weight=1.0
|
45 |
+
),
|
46 |
+
loss_bbox=dict(type="GIoULoss", loss_weight=2.0),
|
47 |
+
with_objectness=False,
|
48 |
+
exp_on_reg=True,
|
49 |
+
share_conv=True,
|
50 |
+
pred_kernel_size=1,
|
51 |
+
norm_cfg=dict(type="SyncBN"),
|
52 |
+
act_cfg=dict(type="SiLU", inplace=True),
|
53 |
+
),
|
54 |
+
train_cfg=dict(
|
55 |
+
assigner=dict(type="DynamicSoftLabelAssigner", topk=13),
|
56 |
+
allowed_border=-1,
|
57 |
+
pos_weight=-1,
|
58 |
+
debug=False,
|
59 |
+
),
|
60 |
+
test_cfg=dict(
|
61 |
+
nms_pre=30000,
|
62 |
+
min_bbox_size=0,
|
63 |
+
score_thr=0.001,
|
64 |
+
nms=dict(type="nms", iou_threshold=0.65),
|
65 |
+
max_per_img=300,
|
66 |
+
),
|
67 |
+
)
|
68 |
+
|
69 |
+
train_pipeline = [
|
70 |
+
dict(type="LoadImageFromFile", backend_args={{_base_.backend_args}}),
|
71 |
+
dict(type="LoadAnnotations", with_bbox=True),
|
72 |
+
dict(type="CachedMosaic", img_scale=(640, 640), pad_val=114.0),
|
73 |
+
dict(
|
74 |
+
type="RandomResize", scale=(1280, 1280), ratio_range=(0.1, 2.0), keep_ratio=True
|
75 |
+
),
|
76 |
+
dict(type="RandomCrop", crop_size=(640, 640)),
|
77 |
+
dict(type="YOLOXHSVRandomAug"),
|
78 |
+
dict(type="RandomFlip", prob=0.5),
|
79 |
+
dict(type="Pad", size=(640, 640), pad_val=dict(img=(114, 114, 114))),
|
80 |
+
dict(
|
81 |
+
type="CachedMixUp",
|
82 |
+
img_scale=(640, 640),
|
83 |
+
ratio_range=(1.0, 1.0),
|
84 |
+
max_cached_images=20,
|
85 |
+
pad_val=(114, 114, 114),
|
86 |
+
),
|
87 |
+
dict(type="mmdet.PackDetInputs"),
|
88 |
+
]
|
89 |
+
|
90 |
+
train_pipeline_stage2 = [
|
91 |
+
dict(type="LoadImageFromFile", backend_args={{_base_.backend_args}}),
|
92 |
+
dict(type="LoadAnnotations", with_bbox=True),
|
93 |
+
dict(
|
94 |
+
type="RandomResize", scale=(640, 640), ratio_range=(0.1, 2.0), keep_ratio=True
|
95 |
+
),
|
96 |
+
dict(type="RandomCrop", crop_size=(640, 640)),
|
97 |
+
dict(type="YOLOXHSVRandomAug"),
|
98 |
+
dict(type="RandomFlip", prob=0.5),
|
99 |
+
dict(type="Pad", size=(640, 640), pad_val=dict(img=(114, 114, 114))),
|
100 |
+
dict(type="mmdet.PackDetInputs"),
|
101 |
+
]
|
102 |
+
|
103 |
+
test_pipeline = [
|
104 |
+
dict(type="LoadImageFromFile", backend_args={{_base_.backend_args}}),
|
105 |
+
dict(type="Resize", scale=(640, 640), keep_ratio=True),
|
106 |
+
dict(type="Pad", size=(640, 640), pad_val=dict(img=(114, 114, 114))),
|
107 |
+
dict(
|
108 |
+
type="mmdet.PackDetInputs",
|
109 |
+
meta_keys=("img_id", "img_path", "ori_shape", "img_shape", "scale_factor"),
|
110 |
+
),
|
111 |
+
]
|
112 |
+
|
113 |
+
train_dataloader = dict(
|
114 |
+
batch_size=32,
|
115 |
+
num_workers=10,
|
116 |
+
batch_sampler=None,
|
117 |
+
pin_memory=True,
|
118 |
+
dataset=dict(pipeline=train_pipeline),
|
119 |
+
)
|
120 |
+
val_dataloader = dict(
|
121 |
+
batch_size=5, num_workers=10, dataset=dict(pipeline=test_pipeline)
|
122 |
+
)
|
123 |
+
test_dataloader = val_dataloader
|
124 |
+
|
125 |
+
max_epochs = 300
|
126 |
+
stage2_num_epochs = 20
|
127 |
+
base_lr = 0.004
|
128 |
+
interval = 10
|
129 |
+
|
130 |
+
train_cfg = dict(
|
131 |
+
max_epochs=max_epochs,
|
132 |
+
val_interval=interval,
|
133 |
+
dynamic_intervals=[(max_epochs - stage2_num_epochs, 1)],
|
134 |
+
)
|
135 |
+
|
136 |
+
val_evaluator = dict(proposal_nums=(100, 1, 10))
|
137 |
+
test_evaluator = val_evaluator
|
138 |
+
|
139 |
+
# optimizer
|
140 |
+
optim_wrapper = dict(
|
141 |
+
_delete_=True,
|
142 |
+
type="OptimWrapper",
|
143 |
+
optimizer=dict(type="AdamW", lr=base_lr, weight_decay=0.05),
|
144 |
+
paramwise_cfg=dict(norm_decay_mult=0, bias_decay_mult=0, bypass_duplicate=True),
|
145 |
+
)
|
146 |
+
|
147 |
+
# learning rate
|
148 |
+
param_scheduler = [
|
149 |
+
dict(type="LinearLR", start_factor=1.0e-5, by_epoch=False, begin=0, end=1000),
|
150 |
+
dict(
|
151 |
+
# use cosine lr from 150 to 300 epoch
|
152 |
+
type="CosineAnnealingLR",
|
153 |
+
eta_min=base_lr * 0.05,
|
154 |
+
begin=max_epochs // 2,
|
155 |
+
end=max_epochs,
|
156 |
+
T_max=max_epochs // 2,
|
157 |
+
by_epoch=True,
|
158 |
+
convert_to_iter_based=True,
|
159 |
+
),
|
160 |
+
]
|
161 |
+
|
162 |
+
# hooks
|
163 |
+
default_hooks = dict(
|
164 |
+
checkpoint=dict(
|
165 |
+
interval=interval, max_keep_ckpts=3 # only keep latest 3 checkpoints
|
166 |
+
)
|
167 |
)
|
168 |
+
custom_hooks = [
|
169 |
+
dict(
|
170 |
+
type="EMAHook",
|
171 |
+
ema_type="ExpMomentumEMA",
|
172 |
+
momentum=0.0002,
|
173 |
+
update_buffers=True,
|
174 |
+
priority=49,
|
175 |
+
),
|
176 |
+
dict(
|
177 |
+
type="PipelineSwitchHook",
|
178 |
+
switch_epoch=max_epochs - stage2_num_epochs,
|
179 |
+
switch_pipeline=train_pipeline_stage2,
|
180 |
+
),
|
181 |
+
]
|