通过mmpretrain使用骨干网
MMDet、MMPreTrain、MMSeg中的模型注册表都继承自MMEngine中的根注册表。这允许这些存储库直接使用彼此已经实现的模块。因此,用户可以在MMDetection中使用MMPretrain中的骨干网,而无需实现MMPretrain中已经存在的网络。
Use backbone network implemented in MMPretrain
假设您希望使用MobileNetV3-small作为RetinaNet的骨干网,配置示例如下:
_base_ = [
'../_base_/models/retinanet_r50_fpn.py',
'../_base_/datasets/coco_detection.py',
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(imports=['mmpretrain.models'], allow_failed_imports=False)
pretrained = 'https://download.openmmlab.com/mmclassification/v0/mobilenet_v3/convert/mobilenet_v3_small-8427ecf0.pth'
model = dict(
backbone=dict(
_delete_=True, # Delete the backbone field in _base_
type='mmpretrain.MobileNetV3', # Using MobileNetV3 from mmpretrain
arch='small',
out_indices=(3, 8, 11), # Modify out_indices
init_cfg=dict(
type='Pretrained',
checkpoint=pretrained,
prefix='backbone.')), # The pre-trained weights of backbone network in mmpretrain have prefix='backbone.'. The prefix in the keys will be removed so that these weights can be normally loaded.
# Modify in_channels
neck=dict(in_channels=[24, 48, 96], start_level=0))
利用mmpretrain中的simmim自监督预训练模型在mmdetection中的mask-rcnn模型进行微调训练
How to use the mmpretrain model in mmdetection