Skip to content

Commit

Permalink
feat: mnv2 configs
Browse files Browse the repository at this point in the history
  • Loading branch information
LutingWang committed Aug 26, 2022
1 parent 3ecf4fa commit 3bd5887
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 271 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ pip install mmdet==2.20
```

```bash
pip install commitizen
pip install -U pre-commit
pre-commit install
pre-commit install -t commit-msg
brew install commitizen
```

## TODO
Expand Down
9 changes: 9 additions & 0 deletions configs/HEAD/HEAD_retina_faster_mnv2_fpn_mstrain_1x_coco.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_base_ = [
'../_base_/models/HEAD_retina_faster.py',
'../_base_/models/mnv2_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
'../_base_/default_runtime.py',
]

optimizer = dict(lr=0.01)
51 changes: 6 additions & 45 deletions configs/HEAD/head_retina_faster_r18_fpn_mstrain_1x_coco.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
_base_ = [
'../HEAD_dag/head_dag_retina_faster_r18_fpn_mstrain_1x_coco.py',
'../_base_/models/HEAD_retina_faster.py',
'../_base_/models/r18_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
'../_base_/default_runtime.py',
]

model = dict(
distiller=dict(
student_hooks=dict(
retina_cls=dict(
type='MultiCallsHook',
path='.rpn_head.cls_convs[-1]',
),
),
adapts={
'retina_cls_reshaped': dict(
type='Rearrange',
fields=['retina_cls'],
parallel=True,
pattern='bs dim h w -> bs h w dim',
),
('teacher_rcnn_bbox_filtered', 'bbox_poses', 'anchor_ids'): dict(
type='CustomAdapt',
fields=['teacher_rcnn_bbox', 'bbox_ids'],
stride=1,
),
'retina_cls_indexed': dict(
type='Index',
fields=['retina_cls_reshaped', 'bbox_poses'],
),
'retina_cls_decoupled': dict(
type='Linear',
fields=['retina_cls_indexed'],
in_features=256,
out_features=1024,
),
},
losses=dict(
loss_cross=dict(
type='MSELoss',
fields=['retina_cls_decoupled', 'teacher_rcnn_bbox_filtered'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
),
),
)
optimizer = dict(lr=0.01)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_base_ = [
'../_base_/models/HEAD_dag_retina_faster.py',
'../_base_/models/mnv2_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
'../_base_/default_runtime.py',
]

optimizer = dict(lr=0.01)
77 changes: 6 additions & 71 deletions configs/HEAD_dag/head_dag_retina_faster_r18_fpn_mstrain_1x_coco.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,9 @@
_base_ = [
'../assist/retina_faster_r18_fpn_mstrain_1x_coco.py',
'../_base_/models/HEAD_dag_retina_faster.py',
'../_base_/models/r18_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
'../_base_/default_runtime.py',
]

model = dict(
type='CrossStageHEAD',
distiller=dict(
teacher=dict(
config='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py',
ckpt=(
'pretrained/mmdetection/'
'faster_rcnn_r50_fpn_mstrain_3x_coco_'
'20210524_110822-e10bd31c.pth'
),
),
weight_transfer={
'.student.roi_head': '.teacher.roi_head',
},
student_hooks=dict(
rcnn_bbox=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[-1]',
),
rcnn_bbox_aux=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[0]',
),
),
teacher_hooks=dict(
teacher_rcnn_bbox_aux=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[0]',
),
teacher_rcnn_bbox=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[-1]',
),
),
adapts={
'rcnn_bbox_aux_adapted': dict(
type='Linear',
fields=['rcnn_bbox_aux'],
in_features=1024,
out_features=1024,
),
'rcnn_bbox_adapted': dict(
type='Linear',
fields=['rcnn_bbox'],
in_features=1024,
out_features=1024,
),
},
losses=dict(
loss_mimic_rcnn_aux=dict(
type='MSELoss',
fields=['rcnn_bbox_aux_adapted', 'teacher_rcnn_bbox_aux'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
loss_mimic_rcnn=dict(
type='MSELoss',
fields=['rcnn_bbox_adapted', 'teacher_rcnn_bbox'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
),
),
)
optimizer = dict(lr=0.01)
29 changes: 9 additions & 20 deletions configs/_base_/datasets/coco_detection_mstrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@
'coco_detection.py',
]

img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=True,
data = dict(
train=dict(
pipeline={
2: dict(
img_scale=[(1333, 640), (1333, 800)],
multiscale_mode='range',
)
}
)
)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations', with_bbox=True),
dict(
type='Resize',
img_scale=[(1333, 640), (1333, 800)],
multiscale_mode='range',
keep_ratio=True,
),
dict(type='RandomFlip', flip_ratio=0.5),
dict(type='Normalize', **img_norm_cfg),
dict(type='Pad', size_divisor=32),
dict(type='DefaultFormatBundle'),
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
]
data = dict(train=dict(pipeline=train_pipeline))
74 changes: 74 additions & 0 deletions configs/_base_/models/HEAD_dag_retina_faster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
_base_ = [
'retina_faster.py',
]

model = dict(
type='CrossStageHEAD',
distiller=dict(
teacher=dict(
config='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py',
ckpt=(
'pretrained/mmdetection/'
'faster_rcnn_r50_fpn_mstrain_3x_coco_'
'20210524_110822-e10bd31c.pth'
),
),
weight_transfer={
'.student.roi_head': '.teacher.roi_head',
},
student_hooks=dict(
rcnn_bbox=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[-1]',
),
rcnn_bbox_aux=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[0]',
),
),
teacher_hooks=dict(
teacher_rcnn_bbox_aux=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[0]',
),
teacher_rcnn_bbox=dict(
type='StandardHook',
path='.roi_head.bbox_head.shared_fcs[-1]',
),
),
adapts={
'rcnn_bbox_aux_adapted': dict(
type='Linear',
fields=['rcnn_bbox_aux'],
in_features=1024,
out_features=1024,
),
'rcnn_bbox_adapted': dict(
type='Linear',
fields=['rcnn_bbox'],
in_features=1024,
out_features=1024,
),
},
losses=dict(
loss_mimic_rcnn_aux=dict(
type='MSELoss',
fields=['rcnn_bbox_aux_adapted', 'teacher_rcnn_bbox_aux'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
loss_mimic_rcnn=dict(
type='MSELoss',
fields=['rcnn_bbox_adapted', 'teacher_rcnn_bbox'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
),
),
)
48 changes: 48 additions & 0 deletions configs/_base_/models/HEAD_retina_faster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
_base_ = [
'HEAD_dag_retina_faster.py',
]

model = dict(
distiller=dict(
student_hooks=dict(
retina_cls=dict(
type='MultiCallsHook',
path='.rpn_head.cls_convs[-1]',
),
),
adapts={
'retina_cls_reshaped': dict(
type='Rearrange',
fields=['retina_cls'],
parallel=True,
pattern='bs dim h w -> bs h w dim',
),
('teacher_rcnn_bbox_filtered', 'bbox_poses', 'anchor_ids'): dict(
type='CustomAdapt',
fields=['teacher_rcnn_bbox', 'bbox_ids'],
stride=1,
),
'retina_cls_indexed': dict(
type='Index',
fields=['retina_cls_reshaped', 'bbox_poses'],
),
'retina_cls_decoupled': dict(
type='Linear',
fields=['retina_cls_indexed'],
in_features=256,
out_features=1024,
),
},
losses=dict(
loss_cross=dict(
type='MSELoss',
fields=['retina_cls_decoupled', 'teacher_rcnn_bbox_filtered'],
weight=dict(
type='WarmupScheduler',
value=2.0,
iter_=2000,
),
),
),
),
)
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
# model settings
model = dict(
type='FasterRCNN',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=True),
norm_eval=True,
style='pytorch',
init_cfg=dict(
type='Pretrained',
checkpoint='pretrained/torchvision/resnet50-0676ba61.pth',
),
),
neck=dict(
type='FPN',
in_channels=[256, 512, 1024, 2048],
out_channels=256,
num_outs=5,
),
rpn_head=dict(
type='RPNHead',
in_channels=256,
Expand Down
12 changes: 12 additions & 0 deletions configs/_base_/models/mnv2_fpn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
model = dict(
backbone=dict(
_delete_=True,
type='MobileNetV2',
act_cfg=dict(type='LeakyReLU', negative_slope=0.1),
init_cfg=dict(
type='Pretrained',
checkpoint='open-mmlab://mmdet/mobilenet_v2',
),
),
neck=dict(in_channels=[24, 32, 96, 1280]),
)
13 changes: 13 additions & 0 deletions configs/_base_/models/r18_fpn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_base_ = [
'r50_fpn.py',
]

model = dict(
backbone=dict(
depth=18,
init_cfg=dict(
checkpoint='pretrained/torchvision/resnet18-f37072fd.pth',
),
),
neck=dict(in_channels=[64, 128, 256, 512]),
)
Loading

0 comments on commit 3bd5887

Please sign in to comment.