Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support to test mmdet inference with mmcls backbone #343

Merged
merged 4 commits into from
Jul 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
ZwwWayne committed Jul 5, 2021
commit a27096f05aae0f1f1e85220889205ee5be05515e
65 changes: 32 additions & 33 deletions tests/test_mmdet_inference.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
from mmdet import build_detector
from mmdet.models import build_detector

from mmcls.models import (MobileNetV2, MobileNetV3, RegNet, ResNeSt, ResNet,
ResNeXt, SEResNet, SEResNeXt, SwinTransformer)

backbone_configs = dict(
mobilenetv2=dict(
backbone=dict(
_delete_=True,
type='mmcv.MobileNetV2',
type='mmcls.MobileNetV2',
widen_factor=1.0,
norm_cfg=dict(type='GN', num_groups=2, requires_grad=True),
out_indices=range(3, 7))),
out_indices=(4, 7))),
mobilenetv3=dict(
backbone=dict(
_delete_=True,
type='mmcv.MobileNetV3',
widen_factor=1.0,
type='mmcls.MobileNetV3',
norm_cfg=dict(type='GN', num_groups=2, requires_grad=True),
out_indices=range(7, 12))),
regnet=dict(
backbone=dict(
_delete_=True, type='mmcv.RegNet', arch_name='regnetx_400mf')),
regnet=dict(backbone=dict(type='mmcls.RegNet', arch='regnetx_400mf')),
resnext=dict(
backbone=dict(
_delete_=True,
type='mmcv.ResNeXt',
depth=50,
groups=32,
base_width=4)),
resnet=dict(backbone=dict(_delete_=True, type='mmcv.ResNet', depth=50)),
seresnet=dict(
backbone=dict(_delete_=True, type='mmcv.SEResNet', depth=50)),
type='mmcls.ResNeXt', depth=50, groups=32, width_per_group=4)),
resnet=dict(backbone=dict(type='mmcls.ResNet', depth=50)),
seresnet=dict(backbone=dict(type='mmcls.SEResNet', depth=50)),
seresnext=dict(
backbone=dict(
_delete_=True,
type='mmcv.SEResNeXt',
depth=50,
groups=32,
base_width=4)),
type='mmcls.SEResNeXt', depth=50, groups=32, width_per_group=4)),
resnest=dict(
backbone=dict(
_delete_=True,
type='mmcv.ResNeSt',
type='mmcls.ResNeSt',
depth=50,
radix=2,
reduction_factor=4,
out_indices=(0, 1, 2, 3))),
swin=dict(
backbone=dict(
_delete_=True,
type='mmcv.SwinTransformer',
arch='small',
drop_path_rate=0.2)))
type='mmcls.SwinTransformer', arch='small', drop_path_rate=0.2)))

module_mapping = {
'mobilenetv2': MobileNetV2,
'mobilenetv3': MobileNetV3,
'regnet': RegNet,
'resnext': ResNeXt,
'resnet': ResNet,
'seresnext': SEResNeXt,
'seresnet': SEResNet,
'resnest': ResNeSt,
'swin': SwinTransformer
}


def test_mmdet_inference():
from mmcv import Config
config_path = './test/data/retinanet.py'
config_path = './tests/data/retinanet.py'
config = Config.fromfile(config_path)

for backbone_config in backbone_configs.items():
config.merge_from_dict(backbone_config)
build_detector(config)
for module_name, backbone_config in backbone_configs.items():
config.model.backbone = backbone_config['backbone']
model = build_detector(config.model)
module = module_mapping[module_name]
assert isinstance(model.backbone, module)