Skip to content

Commit d49038e

Browse files
add rotated rt detr
1 parent 9824bcc commit d49038e

20 files changed

Lines changed: 2636 additions & 0 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
default_scope = 'ai4rs'
2+
3+
default_hooks = dict(
4+
timer=dict(type='IterTimerHook'),
5+
logger=dict(type='LoggerHook', interval=50),
6+
param_scheduler=dict(type='ParamSchedulerHook'),
7+
checkpoint=dict(type='CheckpointHook', interval=1, max_keep_ckpts=99999),
8+
sampler_seed=dict(type='DistSamplerSeedHook'),
9+
visualization=dict(type='mmdet.DetVisualizationHook'))
10+
11+
env_cfg = dict(
12+
cudnn_benchmark=False,
13+
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
14+
dist_cfg=dict(backend='nccl'),
15+
)
16+
17+
vis_backends = [dict(type='LocalVisBackend')]
18+
visualizer = dict(
19+
type='RotLocalVisualizer', vis_backends=vis_backends, name='visualizer')
20+
log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True)
21+
22+
log_level = 'INFO'
23+
load_from = None
24+
resume = False
25+
26+
custom_hooks = [
27+
dict(type='mmdet.NumClassCheckHook'),
28+
dict(
29+
type='EMAHook',
30+
ema_type='mmdet.ExpMomentumEMA',
31+
momentum=0.0002,
32+
update_buffers=True,
33+
priority=49)
34+
]
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# dataset settings
2+
dataset_type = 'DOTADataset'
3+
data_root = 'data/split_ss_dota/'
4+
5+
backend_args = None
6+
7+
train_pipeline = [
8+
dict(type='mmdet.LoadImageFromFile', backend_args=backend_args),
9+
dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'),
10+
dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')),
11+
dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True),
12+
dict(
13+
type='mmdet.RandomFlip',
14+
prob=0.75,
15+
direction=['horizontal', 'vertical', 'diagonal']),
16+
dict(
17+
type='RandomRotate',
18+
prob=0.5,
19+
angle_range=180,
20+
rect_obj_labels=[9, 11]),
21+
dict(
22+
type='mmdet.Pad', size=(1024, 1024),
23+
pad_val=dict(img=(114, 114, 114))),
24+
dict(type='mmdet.PackDetInputs')
25+
]
26+
val_pipeline = [
27+
dict(type='mmdet.LoadImageFromFile', backend_args=backend_args),
28+
dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True),
29+
# avoid bboxes being resized
30+
dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'),
31+
dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')),
32+
dict(
33+
type='mmdet.Pad', size=(1024, 1024),
34+
pad_val=dict(img=(114, 114, 114))),
35+
dict(
36+
type='mmdet.PackDetInputs',
37+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
38+
'scale_factor'))
39+
]
40+
test_pipeline = [
41+
dict(type='mmdet.LoadImageFromFile', backend_args=backend_args),
42+
dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True),
43+
dict(
44+
type='mmdet.Pad', size=(1024, 1024),
45+
pad_val=dict(img=(114, 114, 114))),
46+
dict(
47+
type='mmdet.PackDetInputs',
48+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
49+
'scale_factor'))
50+
]
51+
train_dataloader = dict(
52+
batch_size=4,
53+
num_workers=4,
54+
persistent_workers=True,
55+
sampler=dict(type='DefaultSampler', shuffle=True),
56+
batch_sampler=None,
57+
pin_memory=False,
58+
dataset=dict(
59+
type=dataset_type,
60+
data_root=data_root,
61+
ann_file='trainval/annfiles/',
62+
data_prefix=dict(img_path='trainval/images/'),
63+
filter_cfg=dict(filter_empty_gt=True),
64+
pipeline=train_pipeline))
65+
val_dataloader = dict(
66+
batch_size=4,
67+
num_workers=4,
68+
persistent_workers=True,
69+
drop_last=False,
70+
sampler=dict(type='DefaultSampler', shuffle=False),
71+
dataset=dict(
72+
type=dataset_type,
73+
data_root=data_root,
74+
ann_file='trainval/annfiles/',
75+
data_prefix=dict(img_path='trainval/images/'),
76+
test_mode=True,
77+
pipeline=val_pipeline))
78+
# test_dataloader = val_dataloader
79+
80+
val_evaluator = dict(type='DOTAMetric', metric='mAP')
81+
# test_evaluator = val_evaluator
82+
83+
# inference on test dataset and format the output results
84+
# for submission. Note: the test set has no annotation.
85+
test_dataloader = dict(
86+
batch_size=4,
87+
num_workers=4,
88+
persistent_workers=False,
89+
drop_last=False,
90+
sampler=dict(type='DefaultSampler', shuffle=False),
91+
dataset=dict(
92+
type=dataset_type,
93+
data_root=data_root,
94+
data_prefix=dict(img_path='test/images/'),
95+
test_mode=True,
96+
pipeline=test_pipeline))
97+
test_evaluator = dict(
98+
type='DOTAMetric',
99+
format_only=True,
100+
merge_patches=True,
101+
outfile_prefix='./work_dirs/Task1')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from mmengine.config import read_base
2+
with read_base():
3+
from .o2_rtdetr_r50vd_2xb4_72e_dota import *
4+
5+
pretrained = ('https://www.modelscope.cn/models/wokaikaixinxin/ai4rs/resolve/'
6+
'master/rtdetr/resnet101vd_ssld_pretrained_64ed664a.pth') # noqa
7+
8+
model.update(
9+
backbone=dict(
10+
depth=101, init_cfg=dict(type='Pretrained', checkpoint=pretrained)),
11+
neck=dict(out_channels=384),
12+
encoder=dict(
13+
in_channels=[384, 384, 384],
14+
fpn_cfg=dict(in_channels=[384, 384, 384]),
15+
layer_cfg=dict(
16+
self_attn_cfg=dict(embed_dims=384),
17+
ffn_cfg=dict(embed_dims=384, feedforward_channels=2048))))
18+
19+
# optimizer
20+
optim_wrapper.update(
21+
paramwise_cfg=dict(
22+
custom_keys={'backbone': dict(lr_mult=0.01)}, norm_decay_mult=1))
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from mmengine.config import read_base
2+
with read_base():
3+
from .o2_rtdetr_r50vd_2xb4_72e_dota import *
4+
5+
pretrained = ('https://www.modelscope.cn/models/wokaikaixinxin/ai4rs/resolve/'
6+
'master/rtdetr/resnet18vd_pretrained_55f5a0d6.pth') # noqa
7+
8+
model.update(
9+
backbone=dict(
10+
depth=18,
11+
frozen_stages=-1,
12+
norm_cfg=dict(requires_grad=True),
13+
norm_eval=False,
14+
init_cfg=dict(type='Pretrained', checkpoint=pretrained)),
15+
neck=dict(in_channels=[128, 256, 512]),
16+
encoder=dict(fpn_cfg=dict(expansion=0.5)),
17+
decoder=dict(num_layers=3))
18+
19+
# set all norm layers in backbone to lr_mult=0.1 and decay_mult=0.0
20+
# set all other layers in backbone to lr_mult=0.1
21+
num_blocks_list = (2, 2, 2, 2) # r18
22+
downsample_norm_idx_list = (2, 3, 3, 3) # r18
23+
backbone_norm_multi = dict(lr_mult=0.1, decay_mult=0.0)
24+
custom_keys = {'backbone': dict(lr_mult=0.1)}
25+
custom_keys.update({
26+
f'backbone.layer{stage_id + 1}.{block_id}.bn': backbone_norm_multi
27+
for stage_id, num_blocks in enumerate(num_blocks_list)
28+
for block_id in range(num_blocks)
29+
})
30+
custom_keys.update({
31+
f'backbone.layer{stage_id + 1}.{block_id}.downsample.{downsample_norm_idx - 1}': # noqa
32+
backbone_norm_multi
33+
for stage_id, (num_blocks, downsample_norm_idx) in enumerate(
34+
zip(num_blocks_list, downsample_norm_idx_list))
35+
for block_id in range(num_blocks)
36+
})
37+
38+
# optimizer
39+
optim_wrapper.paramwise_cfg.pop('custom_keys')
40+
optim_wrapper.update(
41+
paramwise_cfg=dict(custom_keys=dict(**custom_keys)))
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from mmengine.config import read_base
2+
with read_base():
3+
from .o2_rtdetr_r50vd_2xb4_72e_dota import *
4+
5+
pretrained = ('https://www.modelscope.cn/models/wokaikaixinxin/ai4rs/resolve/'
6+
'master/rtdetr/resnet34vd_pretrained_f6a72dc5.pth') # noqa
7+
8+
model.update(
9+
backbone=dict(
10+
depth=34,
11+
frozen_stages=-1,
12+
norm_cfg=dict(requires_grad=True),
13+
norm_eval=False,
14+
init_cfg=dict(type='Pretrained', checkpoint=pretrained)),
15+
neck=dict(in_channels=[128, 256, 512]),
16+
encoder=dict(fpn_cfg=dict(expansion=0.5)),
17+
decoder=dict(num_layers=4))
18+
19+
# set all norm layers in backbone to lr_mult=0.1 and decay_mult=0.0
20+
# set all other layers in backbone to lr_mult=0.1
21+
num_blocks_list = (3, 4, 6, 3) # r34
22+
downsample_norm_idx_list = (2, 3, 3, 3) # r34
23+
backbone_norm_multi = dict(lr_mult=0.1, decay_mult=0.0)
24+
custom_keys = {'backbone': dict(lr_mult=0.1)}
25+
custom_keys.update({
26+
f'backbone.layer{stage_id + 1}.{block_id}.bn': backbone_norm_multi
27+
for stage_id, num_blocks in enumerate(num_blocks_list)
28+
for block_id in range(num_blocks)
29+
})
30+
custom_keys.update({
31+
f'backbone.layer{stage_id + 1}.{block_id}.downsample.{downsample_norm_idx - 1}': # noqa
32+
backbone_norm_multi
33+
for stage_id, (num_blocks, downsample_norm_idx) in enumerate(
34+
zip(num_blocks_list, downsample_norm_idx_list))
35+
for block_id in range(num_blocks)
36+
})
37+
38+
# optimizer
39+
optim_wrapper.paramwise_cfg.pop('custom_keys')
40+
optim_wrapper.update(
41+
paramwise_cfg=dict(custom_keys=dict(**custom_keys)))

0 commit comments

Comments
 (0)