From 02f813822a96e0903a8c1f40cd2b8ae284942569 Mon Sep 17 00:00:00 2001 From: ZhaoCake Date: Thu, 27 Jul 2023 17:58:18 +0800 Subject: [PATCH 1/8] Finished Modify and Try to Train --- .../qdtrack_faster-rcnn_r50_fpn_4e_base.py | 118 --------------- ...xb2-4e_mot17halftrain_test-mot17halfval.py | 14 -- .../qdtrack_faster_rcnn_r50_fpn_4e_base.py | 140 ++++++++++++++++++ ...xb2-4e_mot17halftrain_test-mot17halfval.py | 17 +++ 4 files changed, 157 insertions(+), 132 deletions(-) delete mode 100644 configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py delete mode 100644 configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py create mode 100644 configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py create mode 100644 configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py diff --git a/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py b/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py deleted file mode 100644 index e3c17c3eb97..00000000000 --- a/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py +++ /dev/null @@ -1,118 +0,0 @@ -_base_ = [ - '../_base_/models/faster-rcnn_r50_fpn.py', '../_base_/default_runtime.py' -] - -detector = _base_.model -detector.pop('data_preprocessor') - -detector['backbone'].update( - dict( - norm_cfg=dict(type='BN', requires_grad=False), - style='caffe', - init_cfg=dict( - type='Pretrained', - checkpoint='open-mmlab://detectron2/resnet50_caffe'))) -detector.rpn_head.loss_bbox.update( - dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)) -detector.rpn_head.bbox_coder.update(dict(clip_border=False)) -detector.roi_head.bbox_head.update(dict(num_classes=1)) -detector.roi_head.bbox_head.bbox_coder.update(dict(clip_border=False)) -detector['init_cfg'] = dict( - type='Pretrained', - checkpoint= # noqa: E251 - 'https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/' - 'faster_rcnn_r50_fpn_1x_coco-person/' - 'faster_rcnn_r50_fpn_1x_coco-person_20201216_175929-d022e227.pth' - # noqa: E501 -) -del _base_.model - -model = dict( - type='QDTrack', - data_preprocessor=dict( - type='TrackDataPreprocessor', - mean=[103.530, 116.280, 123.675], - std=[1.0, 1.0, 1.0], - bgr_to_rgb=False, - pad_size_divisor=32), - detector=detector, - track_head=dict( - type='QuasiDenseTrackHead', - roi_extractor=dict( - type='SingleRoIExtractor', - roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0), - out_channels=256, - featmap_strides=[4, 8, 16, 32]), - embed_head=dict( - type='QuasiDenseEmbedHead', - num_convs=4, - num_fcs=1, - embed_channels=256, - norm_cfg=dict(type='GN', num_groups=32), - loss_track=dict(type='MultiPosCrossEntropyLoss', loss_weight=0.25), - loss_track_aux=dict( - type='MarginL2Loss', - neg_pos_ub=3, - pos_margin=0, - neg_margin=0.1, - hard_mining=True, - loss_weight=1.0)), - loss_bbox=dict(type='L1Loss', loss_weight=1.0), - train_cfg=dict( - assigner=dict( - type='MaxIoUAssigner', - pos_iou_thr=0.7, - neg_iou_thr=0.5, - min_pos_iou=0.5, - match_low_quality=False, - ignore_iof_thr=-1), - sampler=dict( - type='CombinedSampler', - num=256, - pos_fraction=0.5, - neg_pos_ub=3, - add_gt_as_proposals=True, - pos_sampler=dict(type='InstanceBalancedPosSampler'), - neg_sampler=dict(type='RandomSampler')))), - tracker=dict( - type='QuasiDenseTracker', - init_score_thr=0.9, - obj_score_thr=0.5, - match_score_thr=0.5, - memo_tracklet_frames=30, - memo_backdrop_frames=1, - memo_momentum=0.8, - nms_conf_thr=0.5, - nms_backdrop_iou_thr=0.3, - nms_class_iou_thr=0.7, - with_cats=True, - match_metric='bisoftmax')) -# optimizer -optim_wrapper = dict( - type='OptimWrapper', - optimizer=dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001), - clip_grad=dict(max_norm=35, norm_type=2)) -# learning policy -param_scheduler = [ - dict(type='MultiStepLR', begin=0, end=4, by_epoch=True, milestones=[3]) -] - -# runtime settings -train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=4, val_interval=4) -val_cfg = dict(type='ValLoop') -test_cfg = dict(type='TestLoop') - -default_hooks = dict( - logger=dict(type='LoggerHook', interval=50), - visualization=dict(type='TrackVisualizationHook', draw=False)) - -vis_backends = [dict(type='LocalVisBackend')] -visualizer = dict( - type='TrackLocalVisualizer', vis_backends=vis_backends, name='visualizer') - -# custom hooks -custom_hooks = [ - # Synchronize model buffers such as running_mean and running_var in BN - # at the end of each epoch - dict(type='SyncBuffersHook') -] diff --git a/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py deleted file mode 100644 index d87604dad6b..00000000000 --- a/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py +++ /dev/null @@ -1,14 +0,0 @@ -_base_ = [ - './qdtrack_faster-rcnn_r50_fpn_4e_base.py', - '../_base_/datasets/mot_challenge.py', -] - -# evaluator -val_evaluator = [ - dict(type='CocoVideoMetric', metric=['bbox'], classwise=True), - dict(type='MOTChallengeMetric', metric=['HOTA', 'CLEAR', 'Identity']) -] - -test_evaluator = val_evaluator -# The fluctuation of HOTA is about +-1. -randomness = dict(seed=6) diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py new file mode 100644 index 00000000000..a4e50906c59 --- /dev/null +++ b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py @@ -0,0 +1,140 @@ +from mmengine.config import read_base + +with read_base(): + from .._base_.models.faster_rcnn_r50_fpn import * + from .._base_.default_runtime import * + +import mmcv.ops.roi_align +from mmengine.hooks import LoggerHook, SyncBuffersHook +from mmengine.model.weight_init import PretrainedInit +from mmengine.optim import MultiStepLR, OptimWrapper +from mmengine.runner.runner import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.nn.modules.batchnorm import BatchNorm2d +from torch.nn.modules.normalization import GroupNorm +from torch.optim import SGD + +from mmdet.engine.hooks import TrackVisualizationHook +from mmdet.models import (QDTrack, QuasiDenseEmbedHead, QuasiDenseTracker, + QuasiDenseTrackHead, SingleRoIExtractor, + TrackDataPreprocessor) +from mmdet.models.losses import (L1Loss, MarginL2Loss, + MultiPosCrossEntropyLoss, SmoothL1Loss) +from mmdet.models.task_modules import (CombinedSampler, + InstanceBalancedPosSampler, + MaxIoUAssigner, RandomSampler) +from mmdet.visualization import TrackLocalVisualizer + +detector = model +detector.pop('data_preprocessor') + +detector['backbone'].update( + dict( + norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe'))) +detector.rpn_head.loss_bbox.update( + dict(type=SmoothL1Loss, beta=1.0 / 9.0, loss_weight=1.0)) +detector.rpn_head.bbox_coder.update(dict(clip_border=False)) +detector.roi_head.bbox_head.update(dict(num_classes=1)) +detector.roi_head.bbox_head.bbox_coder.update(dict(clip_border=False)) +detector['init_cfg'] = dict( + type=PretrainedInit, + checkpoint= # noqa: E251 + 'https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/' + 'faster_rcnn_r50_fpn_1x_coco-person/' + 'faster_rcnn_r50_fpn_1x_coco-person_20201216_175929-d022e227.pth' + # noqa: E501 +) +del model + +model = dict( + type=QDTrack, + data_preprocessor=dict( + type=TrackDataPreprocessor, + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False, + pad_size_divisor=32), + detector=detector, + track_head=dict( + type=QuasiDenseTrackHead, + roi_extractor=dict( + type=SingleRoIExtractor, + roi_layer=dict( + type=mmcv.ops.roi_align, output_size=7, sampling_ratio=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + embed_head=dict( + type=QuasiDenseEmbedHead, + num_convs=4, + num_fcs=1, + embed_channels=256, + norm_cfg=dict(type=GroupNorm, num_groups=32), + loss_track=dict(type=MultiPosCrossEntropyLoss, loss_weight=0.25), + loss_track_aux=dict( + type=MarginL2Loss, + neg_pos_ub=3, + pos_margin=0, + neg_margin=0.1, + hard_mining=True, + loss_weight=1.0)), + loss_bbox=dict(type=L1Loss, loss_weight=1.0), + train_cfg=dict( + assigner=dict( + type=MaxIoUAssigner, + pos_iou_thr=0.7, + neg_iou_thr=0.5, + min_pos_iou=0.5, + match_low_quality=False, + ignore_iof_thr=-1), + sampler=dict( + type=CombinedSampler, + num=256, + pos_fraction=0.5, + neg_pos_ub=3, + add_gt_as_proposals=True, + pos_sampler=dict(type=InstanceBalancedPosSampler), + neg_sampler=dict(type=RandomSampler)))), + tracker=dict( + type=QuasiDenseTracker, + init_score_thr=0.9, + obj_score_thr=0.5, + match_score_thr=0.5, + memo_tracklet_frames=30, + memo_backdrop_frames=1, + memo_momentum=0.8, + nms_conf_thr=0.5, + nms_backdrop_iou_thr=0.3, + nms_class_iou_thr=0.7, + with_cats=True, + match_metric='bisoftmax')) +# optimizer +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001), + clip_grad=dict(max_norm=35, norm_type=2)) +# learning policy +param_scheduler = [ + dict(type=MultiStepLR, begin=0, end=4, by_epoch=True, milestones=[3]) +] + +# runtime settings +train_cfg = dict(type=EpochBasedTrainLoop, max_epochs=4, val_interval=4) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +default_hooks.update( + logger=dict(type=LoggerHook, interval=50), + visualization=dict(type=TrackVisualizationHook, draw=False)) + +visualizer.update( + type=TrackLocalVisualizer, vis_backends=vis_backends, name='visualizer') + +# custom hooks +custom_hooks = [ + # Synchronize model buffers such as running_mean and running_var in BN + # at the end of each epoch + dict(type=SyncBuffersHook) +] diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py new file mode 100644 index 00000000000..bf32e6da62b --- /dev/null +++ b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py @@ -0,0 +1,17 @@ +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.mot_challenge import * + from .qdtrack_faster_rcnn_r50_fpn_4e_base import * + +from mmdet.evaluation import CocoVideoMetric, MOTChallengeMetric + +# evaluator +val_evaluator = [ + dict(type=CocoVideoMetric, metric=['bbox'], classwise=True), + dict(type=MOTChallengeMetric, metric=['HOTA', 'CLEAR', 'Identity']) +] + +test_evaluator = val_evaluator +# The fluctuation of HOTA is about +-1. +randomness = dict(seed=6) From c5c943dee0054ea5dbdab70b34d711f8f62ea3f4 Mon Sep 17 00:00:00 2001 From: ZhaoCake Date: Thu, 27 Jul 2023 19:32:29 +0800 Subject: [PATCH 2/8] Correct the use of RoIAlign --- configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py index a4e50906c59..c189b5d22d3 100644 --- a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py +++ b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py @@ -4,7 +4,7 @@ from .._base_.models.faster_rcnn_r50_fpn import * from .._base_.default_runtime import * -import mmcv.ops.roi_align +from mmcv.ops import RoIAlign from mmengine.hooks import LoggerHook, SyncBuffersHook from mmengine.model.weight_init import PretrainedInit from mmengine.optim import MultiStepLR, OptimWrapper @@ -63,7 +63,7 @@ roi_extractor=dict( type=SingleRoIExtractor, roi_layer=dict( - type=mmcv.ops.roi_align, output_size=7, sampling_ratio=0), + type=RoIAlign, output_size=7, sampling_ratio=0), out_channels=256, featmap_strides=[4, 8, 16, 32]), embed_head=dict( From 75c62043d24b87a95d883ebf3f7d6a0d36893ed6 Mon Sep 17 00:00:00 2001 From: ZhaoCake Date: Fri, 28 Jul 2023 19:26:57 +0800 Subject: [PATCH 3/8] Put the new config into ./mmdet/configs instead of ./configs --- .../qdtrack_faster_rcnn_r50_fpn_4e_base.py | 96 +++++------- ...xb2-4e_mot17halftrain_test-mot17halfval.py | 15 +- .../configs/_base_/datasets/mot_challenge.py | 101 +++++++++++++ .../qdtrack_faster_rcnn_r50_fpn_4e_base.py | 140 ++++++++++++++++++ ...xb2-4e_mot17halftrain_test-mot17halfval.py | 18 +++ 5 files changed, 302 insertions(+), 68 deletions(-) create mode 100644 mmdet/configs/_base_/datasets/mot_challenge.py create mode 100644 mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py create mode 100644 mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py index c189b5d22d3..e3c17c3eb97 100644 --- a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py +++ b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py @@ -1,104 +1,81 @@ -from mmengine.config import read_base - -with read_base(): - from .._base_.models.faster_rcnn_r50_fpn import * - from .._base_.default_runtime import * - -from mmcv.ops import RoIAlign -from mmengine.hooks import LoggerHook, SyncBuffersHook -from mmengine.model.weight_init import PretrainedInit -from mmengine.optim import MultiStepLR, OptimWrapper -from mmengine.runner.runner import EpochBasedTrainLoop, TestLoop, ValLoop -from torch.nn.modules.batchnorm import BatchNorm2d -from torch.nn.modules.normalization import GroupNorm -from torch.optim import SGD - -from mmdet.engine.hooks import TrackVisualizationHook -from mmdet.models import (QDTrack, QuasiDenseEmbedHead, QuasiDenseTracker, - QuasiDenseTrackHead, SingleRoIExtractor, - TrackDataPreprocessor) -from mmdet.models.losses import (L1Loss, MarginL2Loss, - MultiPosCrossEntropyLoss, SmoothL1Loss) -from mmdet.models.task_modules import (CombinedSampler, - InstanceBalancedPosSampler, - MaxIoUAssigner, RandomSampler) -from mmdet.visualization import TrackLocalVisualizer +_base_ = [ + '../_base_/models/faster-rcnn_r50_fpn.py', '../_base_/default_runtime.py' +] -detector = model +detector = _base_.model detector.pop('data_preprocessor') detector['backbone'].update( dict( - norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + norm_cfg=dict(type='BN', requires_grad=False), style='caffe', init_cfg=dict( - type=PretrainedInit, + type='Pretrained', checkpoint='open-mmlab://detectron2/resnet50_caffe'))) detector.rpn_head.loss_bbox.update( - dict(type=SmoothL1Loss, beta=1.0 / 9.0, loss_weight=1.0)) + dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)) detector.rpn_head.bbox_coder.update(dict(clip_border=False)) detector.roi_head.bbox_head.update(dict(num_classes=1)) detector.roi_head.bbox_head.bbox_coder.update(dict(clip_border=False)) detector['init_cfg'] = dict( - type=PretrainedInit, + type='Pretrained', checkpoint= # noqa: E251 'https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/' 'faster_rcnn_r50_fpn_1x_coco-person/' 'faster_rcnn_r50_fpn_1x_coco-person_20201216_175929-d022e227.pth' # noqa: E501 ) -del model +del _base_.model model = dict( - type=QDTrack, + type='QDTrack', data_preprocessor=dict( - type=TrackDataPreprocessor, + type='TrackDataPreprocessor', mean=[103.530, 116.280, 123.675], std=[1.0, 1.0, 1.0], bgr_to_rgb=False, pad_size_divisor=32), detector=detector, track_head=dict( - type=QuasiDenseTrackHead, + type='QuasiDenseTrackHead', roi_extractor=dict( - type=SingleRoIExtractor, - roi_layer=dict( - type=RoIAlign, output_size=7, sampling_ratio=0), + type='SingleRoIExtractor', + roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0), out_channels=256, featmap_strides=[4, 8, 16, 32]), embed_head=dict( - type=QuasiDenseEmbedHead, + type='QuasiDenseEmbedHead', num_convs=4, num_fcs=1, embed_channels=256, - norm_cfg=dict(type=GroupNorm, num_groups=32), - loss_track=dict(type=MultiPosCrossEntropyLoss, loss_weight=0.25), + norm_cfg=dict(type='GN', num_groups=32), + loss_track=dict(type='MultiPosCrossEntropyLoss', loss_weight=0.25), loss_track_aux=dict( - type=MarginL2Loss, + type='MarginL2Loss', neg_pos_ub=3, pos_margin=0, neg_margin=0.1, hard_mining=True, loss_weight=1.0)), - loss_bbox=dict(type=L1Loss, loss_weight=1.0), + loss_bbox=dict(type='L1Loss', loss_weight=1.0), train_cfg=dict( assigner=dict( - type=MaxIoUAssigner, + type='MaxIoUAssigner', pos_iou_thr=0.7, neg_iou_thr=0.5, min_pos_iou=0.5, match_low_quality=False, ignore_iof_thr=-1), sampler=dict( - type=CombinedSampler, + type='CombinedSampler', num=256, pos_fraction=0.5, neg_pos_ub=3, add_gt_as_proposals=True, - pos_sampler=dict(type=InstanceBalancedPosSampler), - neg_sampler=dict(type=RandomSampler)))), + pos_sampler=dict(type='InstanceBalancedPosSampler'), + neg_sampler=dict(type='RandomSampler')))), tracker=dict( - type=QuasiDenseTracker, + type='QuasiDenseTracker', init_score_thr=0.9, obj_score_thr=0.5, match_score_thr=0.5, @@ -112,29 +89,30 @@ match_metric='bisoftmax')) # optimizer optim_wrapper = dict( - type=OptimWrapper, - optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001), + type='OptimWrapper', + optimizer=dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001), clip_grad=dict(max_norm=35, norm_type=2)) # learning policy param_scheduler = [ - dict(type=MultiStepLR, begin=0, end=4, by_epoch=True, milestones=[3]) + dict(type='MultiStepLR', begin=0, end=4, by_epoch=True, milestones=[3]) ] # runtime settings -train_cfg = dict(type=EpochBasedTrainLoop, max_epochs=4, val_interval=4) -val_cfg = dict(type=ValLoop) -test_cfg = dict(type=TestLoop) +train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=4, val_interval=4) +val_cfg = dict(type='ValLoop') +test_cfg = dict(type='TestLoop') -default_hooks.update( - logger=dict(type=LoggerHook, interval=50), - visualization=dict(type=TrackVisualizationHook, draw=False)) +default_hooks = dict( + logger=dict(type='LoggerHook', interval=50), + visualization=dict(type='TrackVisualizationHook', draw=False)) -visualizer.update( - type=TrackLocalVisualizer, vis_backends=vis_backends, name='visualizer') +vis_backends = [dict(type='LocalVisBackend')] +visualizer = dict( + type='TrackLocalVisualizer', vis_backends=vis_backends, name='visualizer') # custom hooks custom_hooks = [ # Synchronize model buffers such as running_mean and running_var in BN # at the end of each epoch - dict(type=SyncBuffersHook) + dict(type='SyncBuffersHook') ] diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py index bf32e6da62b..d87604dad6b 100644 --- a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py +++ b/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py @@ -1,15 +1,12 @@ -from mmengine.config import read_base - -with read_base(): - from .._base_.datasets.mot_challenge import * - from .qdtrack_faster_rcnn_r50_fpn_4e_base import * - -from mmdet.evaluation import CocoVideoMetric, MOTChallengeMetric +_base_ = [ + './qdtrack_faster-rcnn_r50_fpn_4e_base.py', + '../_base_/datasets/mot_challenge.py', +] # evaluator val_evaluator = [ - dict(type=CocoVideoMetric, metric=['bbox'], classwise=True), - dict(type=MOTChallengeMetric, metric=['HOTA', 'CLEAR', 'Identity']) + dict(type='CocoVideoMetric', metric=['bbox'], classwise=True), + dict(type='MOTChallengeMetric', metric=['HOTA', 'CLEAR', 'Identity']) ] test_evaluator = val_evaluator diff --git a/mmdet/configs/_base_/datasets/mot_challenge.py b/mmdet/configs/_base_/datasets/mot_challenge.py new file mode 100644 index 00000000000..a71520a84e5 --- /dev/null +++ b/mmdet/configs/_base_/datasets/mot_challenge.py @@ -0,0 +1,101 @@ +# Copyright (c) OpenMMLab. All rights reserved. +from mmcv.transforms import (LoadImageFromFile, RandomResize, + TransformBroadcaster) + +from mmdet.datasets import MOTChallengeDataset +from mmdet.datasets.samplers import TrackImgSampler +from mmdet.datasets.transforms import (LoadTrackAnnotations, PackTrackInputs, + PhotoMetricDistortion, RandomCrop, + RandomFlip, Resize, + UniformRefFrameSample) +from mmdet.evaluation import MOTChallengeMetric + +# dataset settings +dataset_type = MOTChallengeDataset +data_root = 'data/MOT17/' +img_scale = (1088, 1088) + +backend_args = None +# data pipeline +train_pipeline = [ + dict( + type=UniformRefFrameSample, + num_ref_imgs=1, + frame_range=10, + filter_key_img=True), + dict( + type=TransformBroadcaster, + share_random_params=True, + transforms=[ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadTrackAnnotations), + dict( + type=RandomResize, + scale=img_scale, + ratio_range=(0.8, 1.2), + keep_ratio=True, + clip_object_border=False), + dict(type=PhotoMetricDistortion) + ]), + dict( + type=TransformBroadcaster, + # different cropped positions for different frames + share_random_params=False, + transforms=[ + dict(type=RandomCrop, crop_size=img_scale, bbox_clip_border=False) + ]), + dict( + type=TransformBroadcaster, + share_random_params=True, + transforms=[ + dict(type=RandomFlip, prob=0.5), + ]), + dict(type=PackTrackInputs) +] + +test_pipeline = [ + dict( + type=TransformBroadcaster, + transforms=[ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=img_scale, keep_ratio=True), + dict(type=LoadTrackAnnotations) + ]), + dict(type=PackTrackInputs) +] + +# dataloader +train_dataloader = dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + sampler=dict(type=TrackImgSampler), # image-based sampling + dataset=dict( + type=dataset_type, + data_root=data_root, + visibility_thr=-1, + ann_file='annotations/half-train_cocoformat.json', + data_prefix=dict(img_path='train'), + metainfo=dict(classes=('pedestrian', )), + pipeline=train_pipeline)) +val_dataloader = dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + # Now we support two ways to test, image_based and video_based + # if you want to use video_based sampling, you can use as follows + # sampler=dict(type='DefaultSampler', shuffle=False, round_up=False), + sampler=dict(type=TrackImgSampler), # image-based sampling + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/half-val_cocoformat.json', + data_prefix=dict(img_path='train'), + test_mode=True, + pipeline=test_pipeline)) +test_dataloader = val_dataloader + +# evaluator +val_evaluator = dict( + type=MOTChallengeMetric, metric=['HOTA', 'CLEAR', 'Identity']) +test_evaluator = val_evaluator diff --git a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py new file mode 100644 index 00000000000..40ceffc45ea --- /dev/null +++ b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py @@ -0,0 +1,140 @@ +# Copyright (c) OpenMMLab. All rights reserved. +from mmengine.config import read_base + +with read_base(): + from .._base_.models.faster_rcnn_r50_fpn import * + from .._base_.default_runtime import * + +from mmcv.ops import RoIAlign +from mmengine.hooks import LoggerHook, SyncBuffersHook +from mmengine.model.weight_init import PretrainedInit +from mmengine.optim import MultiStepLR, OptimWrapper +from mmengine.runner.runner import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.nn.modules.batchnorm import BatchNorm2d +from torch.nn.modules.normalization import GroupNorm +from torch.optim import SGD + +from mmdet.engine.hooks import TrackVisualizationHook +from mmdet.models import (QDTrack, QuasiDenseEmbedHead, QuasiDenseTracker, + QuasiDenseTrackHead, SingleRoIExtractor, + TrackDataPreprocessor) +from mmdet.models.losses import (L1Loss, MarginL2Loss, + MultiPosCrossEntropyLoss, SmoothL1Loss) +from mmdet.models.task_modules import (CombinedSampler, + InstanceBalancedPosSampler, + MaxIoUAssigner, RandomSampler) +from mmdet.visualization import TrackLocalVisualizer + +detector = model +detector.pop('data_preprocessor') + +detector['backbone'].update( + dict( + norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe'))) +detector.rpn_head.loss_bbox.update( + dict(type=SmoothL1Loss, beta=1.0 / 9.0, loss_weight=1.0)) +detector.rpn_head.bbox_coder.update(dict(clip_border=False)) +detector.roi_head.bbox_head.update(dict(num_classes=1)) +detector.roi_head.bbox_head.bbox_coder.update(dict(clip_border=False)) +detector['init_cfg'] = dict( + type=PretrainedInit, + checkpoint= # noqa: E251 + 'https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/' + 'faster_rcnn_r50_fpn_1x_coco-person/' + 'faster_rcnn_r50_fpn_1x_coco-person_20201216_175929-d022e227.pth' + # noqa: E501 +) +del model + +model = dict( + type=QDTrack, + data_preprocessor=dict( + type=TrackDataPreprocessor, + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False, + pad_size_divisor=32), + detector=detector, + track_head=dict( + type=QuasiDenseTrackHead, + roi_extractor=dict( + type=SingleRoIExtractor, + roi_layer=dict(type=RoIAlign, output_size=7, sampling_ratio=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + embed_head=dict( + type=QuasiDenseEmbedHead, + num_convs=4, + num_fcs=1, + embed_channels=256, + norm_cfg=dict(type=GroupNorm, num_groups=32), + loss_track=dict(type=MultiPosCrossEntropyLoss, loss_weight=0.25), + loss_track_aux=dict( + type=MarginL2Loss, + neg_pos_ub=3, + pos_margin=0, + neg_margin=0.1, + hard_mining=True, + loss_weight=1.0)), + loss_bbox=dict(type=L1Loss, loss_weight=1.0), + train_cfg=dict( + assigner=dict( + type=MaxIoUAssigner, + pos_iou_thr=0.7, + neg_iou_thr=0.5, + min_pos_iou=0.5, + match_low_quality=False, + ignore_iof_thr=-1), + sampler=dict( + type=CombinedSampler, + num=256, + pos_fraction=0.5, + neg_pos_ub=3, + add_gt_as_proposals=True, + pos_sampler=dict(type=InstanceBalancedPosSampler), + neg_sampler=dict(type=RandomSampler)))), + tracker=dict( + type=QuasiDenseTracker, + init_score_thr=0.9, + obj_score_thr=0.5, + match_score_thr=0.5, + memo_tracklet_frames=30, + memo_backdrop_frames=1, + memo_momentum=0.8, + nms_conf_thr=0.5, + nms_backdrop_iou_thr=0.3, + nms_class_iou_thr=0.7, + with_cats=True, + match_metric='bisoftmax')) +# optimizer +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001), + clip_grad=dict(max_norm=35, norm_type=2)) +# learning policy +param_scheduler = [ + dict(type=MultiStepLR, begin=0, end=4, by_epoch=True, milestones=[3]) +] + +# runtime settings +train_cfg = dict(type=EpochBasedTrainLoop, max_epochs=4, val_interval=4) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +default_hooks.update( + logger=dict(type=LoggerHook, interval=50), + visualization=dict(type=TrackVisualizationHook, draw=False)) + +visualizer.update( + type=TrackLocalVisualizer, vis_backends=vis_backends, name='visualizer') + +# custom hooks +custom_hooks = [ + # Synchronize model buffers such as running_mean and running_var in BN + # at the end of each epoch + dict(type=SyncBuffersHook) +] diff --git a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py new file mode 100644 index 00000000000..9bf96119f2e --- /dev/null +++ b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py @@ -0,0 +1,18 @@ +# Copyright (c) OpenMMLab. All rights reserved. +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.mot_challenge import * + from .qdtrack_faster_rcnn_r50_fpn_4e_base import * + +from mmdet.evaluation import CocoVideoMetric, MOTChallengeMetric + +# evaluator +val_evaluator = [ + dict(type=CocoVideoMetric, metric=['bbox'], classwise=True), + dict(type=MOTChallengeMetric, metric=['HOTA', 'CLEAR', 'Identity']) +] + +test_evaluator = val_evaluator +# The fluctuation of HOTA is about +-1. +randomness = dict(seed=6) From bf8ec7796c96ab76b2a3905b0ee3931140683950 Mon Sep 17 00:00:00 2001 From: ZhaoCake Date: Fri, 28 Jul 2023 19:37:25 +0800 Subject: [PATCH 4/8] Forgot to rename the old configuration as it used to be. --- ..._r50_fpn_4e_base.py => qdtrack_faster-rcnn_r50_fpn_4e_base.py} | 0 ...ster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename configs/qdtrack/{qdtrack_faster_rcnn_r50_fpn_4e_base.py => qdtrack_faster-rcnn_r50_fpn_4e_base.py} (100%) rename configs/qdtrack/{qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py => qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py} (100%) diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py similarity index 100% rename from configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py rename to configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_4e_base.py diff --git a/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py similarity index 100% rename from configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py rename to configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py From 06c9a46eb7b09813176a2336482f29fac2210019 Mon Sep 17 00:00:00 2001 From: Zhao Cake <113616514+ZhaoCake@users.noreply.github.com> Date: Mon, 31 Jul 2023 11:53:13 +0800 Subject: [PATCH 5/8] Update qdtrack_faster_rcnn_r50_fpn_4e_base.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 显式导入model。关于日志,由于我删了。所以需要重新训练。 --- mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py index 40ceffc45ea..c672e82c649 100644 --- a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py +++ b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_4e_base.py @@ -3,6 +3,7 @@ with read_base(): from .._base_.models.faster_rcnn_r50_fpn import * + from .._base_.models.faster_rcnn_r50_fpn import model from .._base_.default_runtime import * from mmcv.ops import RoIAlign From fcc36815999bb7378285101df2182a24774e499d Mon Sep 17 00:00:00 2001 From: Zhao Cake <113616514+ZhaoCake@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:20:36 +0800 Subject: [PATCH 6/8] Update qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py As Maintainer said. --- ...r_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py index 9bf96119f2e..2fa715e1b38 100644 --- a/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py +++ b/mmdet/configs/qdtrack/qdtrack_faster_rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py @@ -12,7 +12,3 @@ dict(type=CocoVideoMetric, metric=['bbox'], classwise=True), dict(type=MOTChallengeMetric, metric=['HOTA', 'CLEAR', 'Identity']) ] - -test_evaluator = val_evaluator -# The fluctuation of HOTA is about +-1. -randomness = dict(seed=6) From 59a705083051d0d65d0dd305e73ce3e67f2cd9fb Mon Sep 17 00:00:00 2001 From: zhaocake Date: Sun, 10 Sep 2023 10:24:23 +0800 Subject: [PATCH 7/8] Finish task 0910 --- .../_base_/models/mask_rcnn_r50_caffe_c4.py | 163 ++++++++++++++++++ .../_base_/models/mask_rcnn_r50_fpn.py | 4 +- mmdet/configs/_base_/schedules/schedule_2x.py | 33 ++++ .../configs/common/lsj_100e_coco_detection.py | 134 ++++++++++++++ .../configs/common/lsj_100e_coco_instance.py | 134 ++++++++++++++ .../configs/common/lsj_200e_coco_detection.py | 25 +++ .../configs/common/lsj_200e_coco_instance.py | 25 +++ mmdet/configs/common/ms_3x_coco.py | 130 ++++++++++++++ mmdet/configs/common/ms_3x_coco_instance.py | 136 +++++++++++++++ mmdet/configs/common/ms_90k_coco.py | 151 ++++++++++++++++ .../common/ms_poly_3x_coco_instance.py | 138 +++++++++++++++ .../common/ms_poly_90k_coco_instance.py | 153 ++++++++++++++++ mmdet/configs/common/ssj_270_coco_instance.py | 158 +++++++++++++++++ .../common/ssj_scp_270k_coco_instance.py | 70 ++++++++ .../mask_rcnn_r101_caffe_fpn_1x_coco.py | 19 ++ ...ask_rcnn_r101_caffe_fpn_ms_poly_3x_coco.py | 28 +++ .../mask_rcnn/mask_rcnn_r101_fpn_1x_coco.py | 18 ++ .../mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py | 18 ++ ...sk_rcnn_r101_fpn_8xb8_amp_lsj_200e_coco.py | 18 ++ .../mask_rcnn_r101_fpn_ms_poly_3x_coco.py | 19 ++ ...ask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco.py | 19 ++ .../mask_rcnn_r50_caffe_c4_1x_coco.py | 13 ++ .../mask_rcnn_r50_caffe_fpn_1x_coco.py | 25 +++ .../mask_rcnn_r50_caffe_fpn_ms_1x_coco.py | 40 +++++ ...mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco.py | 40 +++++ ...mask_rcnn_r50_caffe_fpn_ms_poly_2x_coco.py | 23 +++ ...mask_rcnn_r50_caffe_fpn_ms_poly_3x_coco.py | 23 +++ ...mask_rcnn_r50_caffe_fpn_poly_1x_coco_v1.py | 40 +++++ .../mask_rcnn_r50_fpn_1x_wandb_coco.py | 31 ++++ .../mask_rcnn/mask_rcnn_r50_fpn_2x_coco.py | 13 ++ ...ask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco.py | 1 + .../mask_rcnn_r50_fpn_amp_1x_coco.py | 14 ++ .../mask_rcnn_r50_fpn_ms_poly_-3x_coco.py | 11 ++ .../mask_rcnn_r50_fpn_poly_1x_coco.py | 23 +++ .../mask_rcnn_x101_32x4d_fpn_1x_coco.py | 28 +++ .../mask_rcnn_x101_32x4d_fpn_2x_coco.py | 28 +++ ...ask_rcnn_x101_32x4d_fpn_ms_poly_3x_coco.py | 29 ++++ .../mask_rcnn_x101_32x8d_fpn_1x_coco.py | 31 ++++ ...ask_rcnn_x101_32x8d_fpn_ms_poly_1x_coco.py | 54 ++++++ ...ask_rcnn_x101_32x8d_fpn_ms_poly_3x_coco.py | 34 ++++ .../mask_rcnn_x101_64_4d_fpn_1x_coco.py | 24 +++ .../mask_rcnn_x101_64x4d_fpn_2x_coco.py | 24 +++ ...ask_rcnn_x101_64x4d_fpn_ms_poly_3x_coco.py | 27 +++ 43 files changed, 2168 insertions(+), 1 deletion(-) create mode 100644 mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py create mode 100644 mmdet/configs/_base_/schedules/schedule_2x.py create mode 100644 mmdet/configs/common/lsj_100e_coco_detection.py create mode 100644 mmdet/configs/common/lsj_100e_coco_instance.py create mode 100644 mmdet/configs/common/lsj_200e_coco_detection.py create mode 100644 mmdet/configs/common/lsj_200e_coco_instance.py create mode 100644 mmdet/configs/common/ms_3x_coco.py create mode 100644 mmdet/configs/common/ms_3x_coco_instance.py create mode 100644 mmdet/configs/common/ms_90k_coco.py create mode 100644 mmdet/configs/common/ms_poly_3x_coco_instance.py create mode 100644 mmdet/configs/common/ms_poly_90k_coco_instance.py create mode 100644 mmdet/configs/common/ssj_270_coco_instance.py create mode 100644 mmdet/configs/common/ssj_scp_270k_coco_instance.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_ms_poly_3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_8xb8_amp_lsj_200e_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_ms_poly_3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_c4_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_2x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_poly_1x_coco_v1.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_1x_wandb_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_amp_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_ms_poly_-3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_poly_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_2x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_ms_poly_3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_3x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_64_4d_fpn_1x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_2x_coco.py create mode 100644 mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_ms_poly_3x_coco.py diff --git a/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py b/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py new file mode 100644 index 00000000000..70d6c042a10 --- /dev/null +++ b/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py @@ -0,0 +1,163 @@ +# Copyright (c) OpenMMLab. All rights reserved. +from mmcv.ops import RoIAlign, nms +from mmengine.model.weight_init import PretrainedInit +from torch.nn import BatchNorm2d + +from mmdet.models.backbones.resnet import ResNet +from mmdet.models.data_preprocessors.data_preprocessor import \ + DetDataPreprocessor +from mmdet.models.dense_heads.rpn_head import RPNHead +from mmdet.models.detectors.mask_rcnn import MaskRCNN +from mmdet.models.layers import ResLayer +from mmdet.models.losses.cross_entropy_loss import CrossEntropyLoss +from mmdet.models.losses.smooth_l1_loss import L1Loss +from mmdet.models.roi_heads.bbox_heads.bbox_head import BBoxHead +from mmdet.models.roi_heads.mask_heads.fcn_mask_head import FCNMaskHead +from mmdet.models.roi_heads.roi_extractors.single_level_roi_extractor import \ + SingleRoIExtractor +from mmdet.models.roi_heads.standard_roi_head import StandardRoIHead +from mmdet.models.task_modules.assigners.max_iou_assigner import MaxIoUAssigner +from mmdet.models.task_modules.coders.delta_xywh_bbox_coder import \ + DeltaXYWHBBoxCoder +from mmdet.models.task_modules.prior_generators.anchor_generator import \ + AnchorGenerator +from mmdet.models.task_modules.samplers.random_sampler import RandomSampler + +# model settings +norm_cfg = dict(type=BatchNorm2d, requires_grad=False) +# model settings +model = dict( + type=MaskRCNN, + data_preprocessor=dict( + type=DetDataPreprocessor, + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False, + pad_mask=True, + pad_size_divisor=32), + backbone=dict( + type=ResNet, + depth=50, + num_stages=3, + strides=(1, 2, 2), + dilations=(1, 1, 1), + out_indices=(2, ), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + norm_eval=True, + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe')), + # neck=dict( + # type=FPN, + # in_channels=[256, 512, 1024, 2048], + # out_channels=256, + # num_outs=5), + rpn_head=dict( + type=RPNHead, + in_channels=1024, + feat_channels=1024, + anchor_generator=dict( + type=AnchorGenerator, + scales=[2, 4, 8, 16, 32], + ratios=[0.5, 1.0, 2.0], + strides=[16]), + bbox_coder=dict( + type=DeltaXYWHBBoxCoder, + target_means=[.0, .0, .0, .0], + target_stds=[1.0, 1.0, 1.0, 1.0]), + loss_cls=dict( + type=CrossEntropyLoss, use_sigmoid=True, loss_weight=1.0), + loss_bbox=dict(type=L1Loss, loss_weight=1.0)), + roi_head=dict( + type=StandardRoIHead, + shared_head=dict( + type=ResLayer, + depth=50, + stage=3, + stride=2, + dilation=1, + style='caffe', + norm_cfg=norm_cfg, + norm_eval=True), + bbox_roi_extractor=dict( + type=SingleRoIExtractor, + roi_layer=dict(type=RoIAlign, output_size=14, sampling_ratio=0), + out_channels=1024, + featmap_strides=[16]), + bbox_head=dict( + type=BBoxHead, + with_avg_pool=True, + roi_feat_size=7, + in_channels=2048, + num_classes=80, + bbox_coder=dict( + type=DeltaXYWHBBoxCoder, + target_means=[0., 0., 0., 0.], + target_stds=[0.1, 0.1, 0.2, 0.2]), + reg_class_agnostic=False, + loss_cls=dict( + type=CrossEntropyLoss, use_sigmoid=False, loss_weight=1.0), + loss_bbox=dict(type=L1Loss, loss_weight=1.0)), + mask_roi_extractor=None, + mask_head=dict( + type=FCNMaskHead, + num_convs=0, + in_channels=2048, + conv_out_channels=256, + num_classes=80, + loss_mask=dict( + type=CrossEntropyLoss, use_mask=True, loss_weight=1.0))), + # model training and testing settings + train_cfg=dict( + rpn=dict( + assigner=dict( + type=MaxIoUAssigner, + pos_iou_thr=0.7, + neg_iou_thr=0.3, + min_pos_iou=0.3, + match_low_quality=True, + ignore_iof_thr=-1), + sampler=dict( + type=RandomSampler, + num=256, + pos_fraction=0.5, + neg_pos_ub=-1, + add_gt_as_proposals=False), + allowed_border=0, + pos_weight=-1, + debug=False), + rpn_proposal=dict( + nms_pre=12000, + max_per_img=2000, + nms=dict(type=nms, iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + assigner=dict( + type=MaxIoUAssigner, + pos_iou_thr=0.5, + neg_iou_thr=0.5, + min_pos_iou=0.5, + match_low_quality=False, + ignore_iof_thr=-1), + sampler=dict( + type=RandomSampler, + num=512, + pos_fraction=0.25, + neg_pos_ub=-1, + add_gt_as_proposals=True), + mask_size=14, + pos_weight=-1, + debug=False)), + test_cfg=dict( + rpn=dict( + nms_pre=6000, + max_per_img=1000, + nms=dict(type=nms, iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + score_thr=0.05, + nms=dict(type=nms, iou_threshold=0.5), + max_per_img=100, + mask_thr_binary=0.5))) diff --git a/mmdet/configs/_base_/models/mask_rcnn_r50_fpn.py b/mmdet/configs/_base_/models/mask_rcnn_r50_fpn.py index 96be6627d02..c8a0b031da5 100644 --- a/mmdet/configs/_base_/models/mask_rcnn_r50_fpn.py +++ b/mmdet/configs/_base_/models/mask_rcnn_r50_fpn.py @@ -1,5 +1,6 @@ # Copyright (c) OpenMMLab. All rights reserved. from mmcv.ops import RoIAlign, nms +from mmengine.model.weight_init import PretrainedInit from torch.nn import BatchNorm2d from mmdet.models.backbones.resnet import ResNet @@ -42,7 +43,8 @@ norm_cfg=dict(type=BatchNorm2d, requires_grad=True), norm_eval=True, style='pytorch', - init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')), + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet50')), neck=dict( type=FPN, in_channels=[256, 512, 1024, 2048], diff --git a/mmdet/configs/_base_/schedules/schedule_2x.py b/mmdet/configs/_base_/schedules/schedule_2x.py new file mode 100644 index 00000000000..51ba09a4723 --- /dev/null +++ b/mmdet/configs/_base_/schedules/schedule_2x.py @@ -0,0 +1,33 @@ +# Copyright (c) OpenMMLab. All rights reserved. +from mmengine.optim.optimizer.optimizer_wrapper import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.optim.sgd import SGD + +# training schedule for 1x +train_cfg = dict(type=EpochBasedTrainLoop, max_epochs=24, val_interval=1) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=24, + by_epoch=True, + milestones=[16, 22], + gamma=0.1) +] + +# optimizer +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001)) + +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr = dict(enable=False, base_batch_size=16) diff --git a/mmdet/configs/common/lsj_100e_coco_detection.py b/mmdet/configs/common/lsj_100e_coco_detection.py new file mode 100644 index 00000000000..ea2d6bad7f5 --- /dev/null +++ b/mmdet/configs/common/lsj_100e_coco_detection.py @@ -0,0 +1,134 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmengine.dataset.sampler import DefaultSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import CocoDataset, RepeatDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +image_size = (1024, 1024) + +backend_args = None + +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=RandomResize, + scale=image_size, + ratio_range=(0.1, 2.0), + keep_ratio=True), + dict( + type=RandomCrop, + crop_type='absolute_range', + crop_size=image_size, + recompute_bbox=True, + allow_negative_crop=True), + dict(type=FilterAnnotations, min_gt_bbox_wh=(1e-2, 1e-2)), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=LoadAnnotations, with_bbox=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] + +# Use RepeatDataset to speed up training +train_dataloader = dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + sampler=dict(type=DefaultSampler, shuffle=True), + dataset=dict( + type=RepeatDataset, + times=4, # simply change this from 2 to 16 for 50e - 400e training. + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader = dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args)) +test_dataloader = val_dataloader + +val_evaluator = dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + format_only=False, + backend_args=backend_args) +test_evaluator = val_evaluator + +max_epochs = 25 + +train_cfg = dict( + type=EpochBasedTrainLoop, max_epochs=max_epochs, val_interval=5) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +# optimizer assumes bs=64 +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.1, momentum=0.9, weight_decay=0.00004)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.067, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=max_epochs, + by_epoch=True, + milestones=[22, 24], + gamma=0.1) +] + +# only keep latest 2 checkpoints +default_hooks.update(dict(checkpoint=dict(max_keep_ckpts=2))) + +# NOTE: `auto_scale_lr` is for automatically scaling LR, +# USER SHOULD NOT CHANGE ITS VALUES. +# base_batch_size = (32 GPUs) x (2 samples per GPU) +auto_scale_lr = dict(base_batch_size=64) diff --git a/mmdet/configs/common/lsj_100e_coco_instance.py b/mmdet/configs/common/lsj_100e_coco_instance.py new file mode 100644 index 00000000000..90104ee503b --- /dev/null +++ b/mmdet/configs/common/lsj_100e_coco_instance.py @@ -0,0 +1,134 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmengine.dataset.sampler import DefaultSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import CocoDataset, RepeatDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +image_size = (1024, 1024) + +backend_args = None + +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=RandomResize, + scale=image_size, + ratio_range=(0.1, 2.0), + keep_ratio=True), + dict( + type=RandomCrop, + crop_type='absolute_range', + crop_size=image_size, + recompute_bbox=True, + allow_negative_crop=True), + dict(type=FilterAnnotations, min_gt_bbox_wh=(1e-2, 1e-2)), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] + +# Use RepeatDataset to speed up training +train_dataloader = dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + sampler=dict(type=DefaultSampler, shuffle=True), + dataset=dict( + type=RepeatDataset, + times=4, # simply change this from 2 to 16 for 50e - 400e training. + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader = dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args)) +test_dataloader = val_dataloader + +val_evaluator = dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + format_only=False, + backend_args=backend_args) +test_evaluator = val_evaluator + +max_epochs = 25 + +train_cfg = dict( + type=EpochBasedTrainLoop, max_epochs=max_epochs, val_interval=5) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +# optimizer assumes bs=64 +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.1, momentum=0.9, weight_decay=0.00004)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.067, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=max_epochs, + by_epoch=True, + milestones=[22, 24], + gamma=0.1) +] + +# only keep latest 2 checkpoints +default_hooks.update(dict(checkpoint=dict(max_keep_ckpts=2))) + +# NOTE: `auto_scale_lr` is for automatically scaling LR, +# USER SHOULD NOT CHANGE ITS VALUES. +# base_batch_size = (32 GPUs) x (2 samples per GPU) +auto_scale_lr = dict(base_batch_size=64) diff --git a/mmdet/configs/common/lsj_200e_coco_detection.py b/mmdet/configs/common/lsj_200e_coco_detection.py new file mode 100644 index 00000000000..5759499e95d --- /dev/null +++ b/mmdet/configs/common/lsj_200e_coco_detection.py @@ -0,0 +1,25 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .lsj_100e_coco_detection import * + +# 8x25=200e +train_dataloader.update(dict(dataset=dict(times=8))) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.067, by_epoch=False, begin=0, end=1000), + dict( + type=MultiStepLR, + begin=0, + end=25, + by_epoch=True, + milestones=[22, 24], + gamma=0.1) +] diff --git a/mmdet/configs/common/lsj_200e_coco_instance.py b/mmdet/configs/common/lsj_200e_coco_instance.py new file mode 100644 index 00000000000..77c5cdd44c4 --- /dev/null +++ b/mmdet/configs/common/lsj_200e_coco_instance.py @@ -0,0 +1,25 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .lsj_100e_coco_instance import * + +# 8x25=200e +train_dataloader.update(dict(dataset=dict(times=8))) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.067, by_epoch=False, begin=0, end=1000), + dict( + type=MultiStepLR, + begin=0, + end=25, + by_epoch=True, + milestones=[22, 24], + gamma=0.1) +] diff --git a/mmdet/configs/common/ms_3x_coco.py b/mmdet/configs/common/ms_3x_coco.py new file mode 100644 index 00000000000..c32b24d96ae --- /dev/null +++ b/mmdet/configs/common/ms_3x_coco.py @@ -0,0 +1,130 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import EpochBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import RandomFlip, Resize +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' + +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# In mstrain 3x config, img_scale=[(1333, 640), (1333, 800)], +# multiscale_mode='range' +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True), + dict(type=RandomResize, scale=[(1333, 640), (1333, 800)], keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=LoadAnnotations, with_bbox=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader = dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + pin_memory=True, + sampler=dict(type=DefaultSampler, shuffle=True), + batch_sampler=dict(type=AspectRatioBatchSampler), + dataset=dict( + type=RepeatDataset, + times=3, + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader = dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args)) +test_dataloader = val_dataloader + +val_evaluator = dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric='bbox', + backend_args=backend_args) +test_evaluator = val_evaluator + +# training schedule for 3x with `RepeatDataset` +train_cfg = dict(type=EpochBasedTrainLoop, max_iters=12, val_interval=1) +val_cfg = dict(type=ValLoop) +test_cfg = dict(type=TestLoop) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=12, + by_epoch=False, + milestones=[9, 11], + gamma=0.1) +] + +# optimizer +optim_wrapper = dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001)) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr = dict(enable=False, base_batch_size=16) diff --git a/mmdet/configs/common/ms_3x_coco_instance.py b/mmdet/configs/common/ms_3x_coco_instance.py new file mode 100644 index 00000000000..3c78909df80 --- /dev/null +++ b/mmdet/configs/common/ms_3x_coco_instance.py @@ -0,0 +1,136 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler, InfiniteSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import IterBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' + +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type='RandomResize', scale=[(1333, 640), (1333, 800)], + keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + sampler=dict(type=DefaultSampler, shuffle=True), + batch_sampler=dict(type=AspectRatioBatchSampler), + dataset=dict( + type=RepeatDataset, + times=3, + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args)))) +val_dataloader.update( + dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args))) +test_dataloader = val_dataloader + +val_evaluator.update( + dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric='bbox', + backend_args=backend_args)) +test_evaluator = val_evaluator + +# training schedule for 3x with `RepeatDataset` +train_cfg.update(dict(type=EpochBasedTrainLoop, max_epochs=12, val_interval=1)) +val_cfg.update(dict(type=ValLoop)) +test_cfg.update(dict(type=TestLoop)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=12, + by_epoch=False, + milestones=[9, 11], + gamma=0.1) +] + +# optimizer +optim_wrapper.update( + dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001))) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr.update(dict(enable=False, base_batch_size=16)) diff --git a/mmdet/configs/common/ms_90k_coco.py b/mmdet/configs/common/ms_90k_coco.py new file mode 100644 index 00000000000..3abf1d4a4a8 --- /dev/null +++ b/mmdet/configs/common/ms_90k_coco.py @@ -0,0 +1,151 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler, InfiniteSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import IterBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# Align with Detectron2 +backend = 'pillow' +train_pipeline = [ + dict( + type=LoadImageFromFile, + backend_args=backend_args, + imdecode_backend=backend), + dict(type=LoadAnnotations, with_bbox=True), + dict( + type=RandomChoiceResize, + scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), + (1333, 768), (1333, 800)], + keep_ratio=True, + backend=backend), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict( + type=LoadImageFromFile, + backend_args=backend_args, + imdecode_backend=backend), + dict(type=Resize, scale=(1333, 800), keep_ratio=True, backend=backend), + dict(type=LoadAnnotations, with_bbox=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + pin_memory=True, + sampler=dict(type=InfiniteSampler, shuffle=True), + batch_sampler=dict(type=AspectRatioBatchSampler), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader.update( + dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + pin_memory=True, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args))) +test_dataloader = val_dataloader + +val_evaluator.update( + dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric='bbox', + format_only=False, + backend_args=backend_args)) +test_evaluator = val_evaluator + +# training schedule for 90k +max_iter = 90000 +train_cfg.update( + dict(type=IterBasedTrainLoop, max_iters=max_iter, val_interval=10000)) +val_cfg.update(dict(type=ValLoop)) +test_cfg.update(dict(type=TestLoop)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=1000), + dict( + type=MultiStepLR, + begin=0, + end=max_iter, + by_epoch=False, + milestones=[60000, 80000], + gamma=0.1) +] + +# optimizer +optim_wrapper.update( + dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001))) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr.update(dict(enable=False, base_batch_size=16)) + +default_hooks.update(dict(checkpoint=dict(by_epoch=False, interval=10000))) +log_processor.update(dict(by_epoch=False)) diff --git a/mmdet/configs/common/ms_poly_3x_coco_instance.py b/mmdet/configs/common/ms_poly_3x_coco_instance.py new file mode 100644 index 00000000000..53913a059a4 --- /dev/null +++ b/mmdet/configs/common/ms_poly_3x_coco_instance.py @@ -0,0 +1,138 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler, InfiniteSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import IterBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# In mstrain 3x config, img_scale=[(1333, 640), (1333, 800)], +# multiscale_mode='range' +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type='RandomResize', scale=[(1333, 640), (1333, 800)], + keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + pin_memory=True, + sampler=dict(type=DefaultSampler, shuffle=True), + batch_sampler=dict(type=AspectRatioBatchSampler), + dataset=dict( + type=RepeatDataset, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + drop_last=False, + pin_memory=True, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args))) +test_dataloader = val_dataloader + +val_evaluator.update( + dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + backend_args=backend_args)) +test_evaluator = val_evaluator + +# training schedule for 3x with `RepeatDataset` +train_cfg.update(dict(type=EpochBasedTrainLoop, max_iters=12, val_interval=1)) +val_cfg.update(dict(type=ValLoop)) +test_cfg.update(dict(type=TestLoop)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=12, + by_epoch=False, + milestones=[9, 11], + gamma=0.1) +] + +# optimizer +optim_wrapper.update( + dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001))) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr.update(dict(enable=False, base_batch_size=16)) diff --git a/mmdet/configs/common/ms_poly_90k_coco_instance.py b/mmdet/configs/common/ms_poly_90k_coco_instance.py new file mode 100644 index 00000000000..52367350137 --- /dev/null +++ b/mmdet/configs/common/ms_poly_90k_coco_instance.py @@ -0,0 +1,153 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler, InfiniteSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import IterBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# Align with Detectron2 +backend = 'pillow' +train_pipeline = [ + dict( + type=LoadImageFromFile, + backend_args=backend_args, + imdecode_backend=backend), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type=RandomChoiceResize, + scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), + (1333, 768), (1333, 800)], + keep_ratio=True, + backend=backend), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict( + type=LoadImageFromFile, + backend_args=backend_args, + imdecode_backend=backend), + dict(type=Resize, scale=(1333, 800), keep_ratio=True, backend=backend), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + pin_memory=True, + sampler=dict(type=InfiniteSampler, shuffle=True), + batch_sampler=dict(type=AspectRatioBatchSampler), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader.update( + dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + pin_memory=True, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args))) +test_dataloader = val_dataloader + +val_evaluator.update( + dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + format_only=False, + backend_args=backend_args)) +test_evaluator = val_evaluator + +# training schedule for 90k +max_iter = 90000 +train_cfg.update( + dict(type=IterBasedTrainLoop, max_iters=max_iter, val_interval=10000)) +val_cfg.update(dict(type=ValLoop)) +test_cfg.update(dict(type=TestLoop)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=1000), + dict( + type=MultiStepLR, + begin=0, + end=max_iter, + by_epoch=False, + milestones=[60000, 80000], + gamma=0.1) +] + +# optimizer +optim_wrapper.update( + dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.02, momentum=0.9, weight_decay=0.0001))) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr.update(dict(enable=False, base_batch_size=16)) + +default_hooks.update(dict(checkpoint=dict(by_epoch=False, interval=10000))) +log_processor.update(dict(by_epoch=False)) diff --git a/mmdet/configs/common/ssj_270_coco_instance.py b/mmdet/configs/common/ssj_270_coco_instance.py new file mode 100644 index 00000000000..ee86fdad4ec --- /dev/null +++ b/mmdet/configs/common/ssj_270_coco_instance.py @@ -0,0 +1,158 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.default_runtime import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.dataset import RepeatDataset +from mmengine.dataset.sampler import DefaultSampler, InfiniteSampler +from mmengine.optim import OptimWrapper +from mmengine.optim.scheduler.lr_scheduler import LinearLR, MultiStepLR +from mmengine.runner.loops import IterBasedTrainLoop, TestLoop, ValLoop +from torch.optim import SGD + +from mmdet.datasets import AspectRatioBatchSampler, CocoDataset +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import (FilterAnnotations, + LoadAnnotations, + LoadImageFromFile) +from mmdet.datasets.transforms.transforms import (CachedMixUp, CachedMosaic, + Pad, RandomCrop, RandomFlip, + RandomResize, Resize) +from mmdet.evaluation import CocoMetric + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# Standard Scale Jittering (SSJ) resizes and crops an image +# with a resize range of 0.8 to 1.25 of the original image size. +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=RandomResize, + scale=image_size, + ratio_range=(0.8, 1.25), + keep_ratio=True), + dict( + type='RandomCrop', + crop_type='absolute_range', + crop_size=image_size, + recompute_bbox=True, + allow_negative_crop=True), + dict(type='FilterAnnotations', min_gt_bbox_wh=(1e-2, 1e-2)), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] +test_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=PackDetInputs, + meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', + 'scale_factor')) +] +train_dataloader.update( + dict( + batch_size=2, + num_workers=2, + persistent_workers=True, + sampler=dict(type=InfiniteSampler), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=train_pipeline, + backend_args=backend_args))) +val_dataloader.update( + dict( + batch_size=1, + num_workers=2, + persistent_workers=True, + drop_last=False, + sampler=dict(type=DefaultSampler, shuffle=False), + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_val2017.json', + data_prefix=dict(img='val2017/'), + test_mode=True, + pipeline=test_pipeline, + backend_args=backend_args))) +test_dataloader = val_dataloader + +val_evaluator.update( + dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + format_only=False, + backend_args=backend_args)) +test_evaluator = val_evaluator + +val_evaluator = dict( + type=CocoMetric, + ann_file=data_root + 'annotations/instances_val2017.json', + metric=['bbox', 'segm'], + format_only=False, + backend_args=backend_args) +test_evaluator = val_evaluator + +# The model is trained by 270k iterations with batch_size 64, +# which is roughly equivalent to 144 epochs. + +max_iter = 270000 +train_cfg.update( + dict(type=IterBasedTrainLoop, max_iters=max_iter, val_interval=10000)) +val_cfg.update(dict(type=ValLoop)) +test_cfg.update(dict(type=TestLoop)) + +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=1000), + dict( + type=MultiStepLR, + begin=0, + end=max_iter, + by_epoch=False, + milestones=[243000, 256500, 263250], + gamma=0.1) +] + +# optimizer +optim_wrapper.update( + dict( + type=OptimWrapper, + optimizer=dict(type=SGD, lr=0.1, momentum=0.9, weight_decay=0.00004))) +# Default setting for scaling LR automatically +# - `enable` means enable scaling LR automatically +# or not by default. +# - `base_batch_size` = (8 GPUs) x (2 samples per GPU). +auto_scale_lr.update(dict(base_batch_size=64)) + +default_hooks.update(dict(checkpoint=dict(by_epoch=False, interval=10000))) +log_processor.update(dict(by_epoch=False)) diff --git a/mmdet/configs/common/ssj_scp_270k_coco_instance.py b/mmdet/configs/common/ssj_scp_270k_coco_instance.py new file mode 100644 index 00000000000..68bb1f0904f --- /dev/null +++ b/mmdet/configs/common/ssj_scp_270k_coco_instance.py @@ -0,0 +1,70 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .ssj_270_coco_instance import * + +from mmdet.datasets import MultiImageMixDataset +from mmdet.datasets.transforms import CopyPaste + +# dataset settings +dataset_type = CocoDataset +data_root = 'data/coco/' +image_size = (1024, 1024) +# Example to use different file client +# Method 1: simply set the data root and let the file I/O module +# automatically infer from prefix (not support LMDB and Memcache yet) + +# data_root = 's3://openmmlab/datasets/detection/coco/' + +# Method 2: Use `backend_args`, `file_client_args` in versions before 3.0.0rc6 +# backend_args = dict( +# backend='petrel', +# path_mapping=dict({ +# './data/': 's3://openmmlab/datasets/detection/', +# 'data/': 's3://openmmlab/datasets/detection/' +# })) +backend_args = None + +# Standard Scale Jittering (SSJ) resizes and crops an image +# with a resize range of 0.8 to 1.25 of the original image size. +load_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=RandomResize, + scale=image_size, + ratio_range=(0.8, 1.25), + keep_ratio=True), + dict( + type='RandomCrop', + crop_type='absolute_range', + crop_size=image_size, + recompute_bbox=True, + allow_negative_crop=True), + dict(type='FilterAnnotations', min_gt_bbox_wh=(1e-2, 1e-2)), + dict(type=RandomFlip, prob=0.5), + dict(type=Pad, size=image_size), +] +train_pipeline = [ + dict(type=CopyPaste, max_num_pasted=100), + dict(type=PackDetInputs) +] + +train_dataloader.update( + dict( + type=MultiImageMixDataset, + dataset=dict( + type=dataset_type, + data_root=data_root, + ann_file='annotations/instances_train2017.json', + data_prefix=dict(img='train2017/'), + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=load_pipeline, + backend_args=backend_args), + pipeline=train_pipeline)) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_1x_coco.py new file mode 100644 index 00000000000..2780f4afddc --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_1x_coco.py @@ -0,0 +1,19 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_poly_1x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=101, + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet101_caffe'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..8a1badfc4f0 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_caffe_fpn_ms_poly_3x_coco.py @@ -0,0 +1,28 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from ..common.ms_poly_3x_coco_instance import * + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + # use caffe img_norm + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False), + backbone=dict( + depth=101, + norm_cfg=dict(requires_grad=False), + norm_eval=True, + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet101_caffe'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.py new file mode 100644 index 00000000000..6770cec8eeb --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.py @@ -0,0 +1,18 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=101, + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet101'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py new file mode 100644 index 00000000000..fd2aafb912c --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py @@ -0,0 +1,18 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_2x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=101, + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet101'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_8xb8_amp_lsj_200e_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_8xb8_amp_lsj_200e_coco.py new file mode 100644 index 00000000000..665808d5dc4 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_8xb8_amp_lsj_200e_coco.py @@ -0,0 +1,18 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=101, + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet101'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..14688795963 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r101_fpn_ms_poly_3x_coco.py @@ -0,0 +1,19 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from ..common.ms_poly_3x_coco_instance import * + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=101, + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet101'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco.py new file mode 100644 index 00000000000..67bd86fa0e8 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r18_fpn_8xb8_amp_lsj_200e_coco.py @@ -0,0 +1,19 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + backbone=dict( + depth=18, + init_cfg=dict( + type=PretrainedInit, checkpoint='torchvision://resnet18')), + neck=dict(in_channels=[64, 128, 256, 512])) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_c4_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_c4_1x_coco.py new file mode 100644 index 00000000000..494e6ba593e --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_c4_1x_coco.py @@ -0,0 +1,13 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.coco_instance import * + from .._base_.default_runtime import * + from .._base_.models.mask_rcnn_r50_caffe_c4 import * + from .._base_.schedules.schedule_1x import * diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_1x_coco.py new file mode 100644 index 00000000000..6481fcfd49e --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_1x_coco.py @@ -0,0 +1,25 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_1x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +model = dict( + # use caffe img_norm + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False), + backbone=dict( + norm_cfg=dict(requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_1x_coco.py new file mode 100644 index 00000000000..5952ed587a4 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_1x_coco.py @@ -0,0 +1,40 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_1x_coco import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.model.weight_init import PretrainedInit + +model = dict( + # use caffe img_norm + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False), + backbone=dict( + norm_cfg=dict(requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe'))) + +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args={{_base_.backend_args}}), + dict(type=LoadAnnotations, with_bbox=True, with_mask=True), + dict( + type=RandomChoiceResize, + scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), + (1333, 768), (1333, 800)], + keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs), +] + +train_dataloader.update(dict(dataset=dict(pipeline=train_pipeline))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco.py new file mode 100644 index 00000000000..d62b9ebe958 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco.py @@ -0,0 +1,40 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_1x_coco import * + +from mmcv.transforms import RandomChoiceResize +from mmengine.model.weight_init import PretrainedInit + +model = dict( + # use caffe img_norm + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False), + backbone=dict( + norm_cfg=dict(requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe'))) +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args={{_base_.backend_args}}), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type=RandomChoiceResize, + scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), + (1333, 768), (1333, 800)], + keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs) +] + +train_dataloader.update(dict(dataset=dict(pipeline=train_pipeline))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_2x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_2x_coco.py new file mode 100644 index 00000000000..fa41b7e00ca --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_2x_coco.py @@ -0,0 +1,23 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco import * + +train_cfg = dict(max_epochs=24) +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=24, + by_epoch=True, + milestones=[16, 22], + gamma=0.1) +] diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..c5f9b977b2d --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_ms_poly_3x_coco.py @@ -0,0 +1,23 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_caffe_fpn_ms_poly_1x_coco import * + +train_cfg = dict(max_epochs=36) +# learning rate +param_scheduler = [ + dict(type=LinearLR, start_factor=0.001, by_epoch=False, begin=0, end=500), + dict( + type=MultiStepLR, + begin=0, + end=24, + by_epoch=True, + milestones=[28, 34], + gamma=0.1) +] diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_poly_1x_coco_v1.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_poly_1x_coco_v1.py new file mode 100644 index 00000000000..28ba7c77ddf --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_poly_1x_coco_v1.py @@ -0,0 +1,40 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_1x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +from mmdet.models.losses import SmoothL1Loss + +model = dict( + # use caffe img_norm + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[1.0, 1.0, 1.0], + bgr_to_rgb=False), + backbone=dict( + norm_cfg=dict(requires_grad=False), + style='caffe', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnet50_caffe')), + rpn_head=dict( + loss_bbox=dict(type=SmoothL1Loss, beta=1.0 / 9.0, loss_weight=1.0)), + roi_head=dict( + bbox_roi_extractor=dict( + roi_layer=dict( + type=RoIAlign, output_size=7, sampling_ratio=2, + aligned=False)), + bbox_head=dict( + loss_bbox=dict(type=SmoothL1Loss, beta=1.0, loss_weight=1.0)), + mask_roi_extractor=dict( + roi_layer=dict( + type=RoIAlign, output_size=14, sampling_ratio=2, + aligned=False)))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_1x_wandb_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_1x_wandb_coco.py new file mode 100644 index 00000000000..d2c08765412 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_1x_wandb_coco.py @@ -0,0 +1,31 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.coco_instance import * + from .._base_.default_runtime import * + from .._base_.models.mask_rcnn_r50_fpn import * + from .._base_.schedules.schedule_1x import * + +from mmengine.visualization import LocalVisBackend, WandbVisBackend + +vis_backends.update(dict(type=WandbVisBackend)) +vis_backends.update(dict(type=LocalVisBackend)) +visualizer.update(dict(vis_backends=vis_backends)) + +# MMEngine support the following two ways, users can choose +# according to convenience +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +default_hooks.update(dict(checkpoint=dict(interval=4))) + +train_cfg.update(dict(val_interval=2)) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.py new file mode 100644 index 00000000000..6be010b4508 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.py @@ -0,0 +1,13 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.coco_instance import * + from .._base_.default_runtime import * + from .._base_.models.mask_rcnn_r50_fpn import * + from .._base_.schedules.schedule_2x import * diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco.py new file mode 100644 index 00000000000..ef101fec61e --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_8xb8_amp_lsj_200e_coco.py @@ -0,0 +1 @@ +# Copyright (c) OpenMMLab. All rights reserved. diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_amp_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_amp_1x_coco.py new file mode 100644 index 00000000000..110c3c47542 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_amp_1x_coco.py @@ -0,0 +1,14 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_1x_coco import * + +from mmengine.optim.optimizer.amp_optimizer_wrapper import AmpOptimWrapper + +optim_wrapper.update(dict(type=AmpOptimWrapper)) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_ms_poly_-3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_ms_poly_-3x_coco.py new file mode 100644 index 00000000000..ff4eec6d2be --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_ms_poly_-3x_coco.py @@ -0,0 +1,11 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.models.mask_rcnn_r50_fpn import * + from ..common.ms_poly_3x_coco_instance import * diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_poly_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_poly_1x_coco.py new file mode 100644 index 00000000000..012e711cb96 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_r50_fpn_poly_1x_coco.py @@ -0,0 +1,23 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .._base_.datasets.coco_instance import * + from .._base_.default_runtime import * + from .._base_.models.mask_rcnn_r50_fpn import * + from .._base_.schedules.schedule_1x import * + +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict(type=Resize, scale=(1333, 800), keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs), +] +train_dataloader.update(dict(dataset=dict(pipeline=train_pipeline))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_1x_coco.py new file mode 100644 index 00000000000..5429b1bd5a6 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_1x_coco.py @@ -0,0 +1,28 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r101_fpn_1x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +from mmdet.models.backbones.resnext import ResNeXt + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_32x4d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_2x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_2x_coco.py new file mode 100644 index 00000000000..ebae6c1dbc3 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_2x_coco.py @@ -0,0 +1,28 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r50_fpn_2x_coco import * + +from mmengine.model.weight_init import PretrainedInit + +from mmdet.models import ResNeXt + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_32x4d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..aff45d89f35 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x4d_fpn_ms_poly_3x_coco.py @@ -0,0 +1,29 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from ..common.ms_poly_3x_coco_instance import * + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmengine.model.weight_init import PretrainedInit + +from mmdet.models.backbones import ResNeXt + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_32x4d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_1x_coco.py new file mode 100644 index 00000000000..d9f2095dc2d --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_1x_coco.py @@ -0,0 +1,31 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_x101_32x4d_fpn_1x_coco import * + +model = dict( + # ResNeXt-101-32x8d model trained with Caffe2 at FB, + # so the mean and std need to be changed. + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[57.375, 57.120, 58.395], + bgr_to_rgb=False), + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=8, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnext101_32x8d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_1x_coco.py new file mode 100644 index 00000000000..8eded941751 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_1x_coco.py @@ -0,0 +1,54 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_r101_fpn_1x_coco import * + +from mmcv.transforms import RandomChoiceResize, RandomFlip +from mmcv.transforms.loading import LoadImageFromFile + +from mmdet.datasets.transforms.formatting import PackDetInputs +from mmdet.datasets.transforms.loading import LoadAnnotations +from mmdet.models.backbones import ResNeXt + +model = dict( + # ResNeXt-101-32x8d model trained with Caffe2 at FB, + # so the mean and std need to be changed. + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[57.375, 57.120, 58.395], + bgr_to_rgb=False), + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=8, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnext101_32x8d'))) + +backend_args = None +train_pipeline = [ + dict(type=LoadImageFromFile, backend_args=backend_args), + dict( + type=LoadAnnotations, with_bbox=True, with_mask=True, poly2mask=False), + dict( + type=RandomChoiceResize, + scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), + (1333, 768), (1333, 800)], + keep_ratio=True), + dict(type=RandomFlip, prob=0.5), + dict(type=PackDetInputs), +] + +train_dataloader = dict(dataset=dict(pipeline=train_pipeline)) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..b3f584675f6 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_32x8d_fpn_ms_poly_3x_coco.py @@ -0,0 +1,34 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from ..common.ms_poly_3x_coco_instance import * + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmdet.models.backbones import ResNeXt + +model = dict( + # ResNeXt-101-32x8d model trained with Caffe2 at FB, + # so the mean and std need to be changed. + data_preprocessor=dict( + mean=[103.530, 116.280, 123.675], + std=[57.375, 57.120, 58.395], + bgr_to_rgb=False), + backbone=dict( + type=ResNeXt, + depth=101, + groups=32, + base_width=8, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=False), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, + checkpoint='open-mmlab://detectron2/resnext101_32x8d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_64_4d_fpn_1x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64_4d_fpn_1x_coco.py new file mode 100644 index 00000000000..8bb6f636e64 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64_4d_fpn_1x_coco.py @@ -0,0 +1,24 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_x101_32x4d_fpn_1x_coco import * + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=64, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_64x4d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_2x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_2x_coco.py new file mode 100644 index 00000000000..d661076dcf3 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_2x_coco.py @@ -0,0 +1,24 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from .mask_rcnn_x101_32x4d_fpn_2x_coco import * + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=64, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_64x4d'))) diff --git a/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_ms_poly_3x_coco.py b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_ms_poly_3x_coco.py new file mode 100644 index 00000000000..d9ab3643ec2 --- /dev/null +++ b/mmdet/configs/mask_rcnn/mask_rcnn_x101_64x4d_fpn_ms_poly_3x_coco.py @@ -0,0 +1,27 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +# Please refer to https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta for more details. # noqa +# mmcv >= 2.0.1 +# mmengine >= 0.8.0 + +from mmengine.config import read_base + +with read_base(): + from ..common.ms_poly_3x_coco_instance import * + from .._base_.models.mask_rcnn_r50_fpn import * + +from mmdet.models.backbones import ResNeXt + +model = dict( + backbone=dict( + type=ResNeXt, + depth=101, + groups=64, + base_width=4, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type=BatchNorm2d, requires_grad=True), + style='pytorch', + init_cfg=dict( + type=PretrainedInit, checkpoint='open-mmlab://resnext101_64x4d'))) From 819296375dd8b19337479c14eb56608734af60ed Mon Sep 17 00:00:00 2001 From: Zhao Cake Date: Mon, 11 Sep 2023 22:16:53 +0800 Subject: [PATCH 8/8] Update mask_rcnn_r50_caffe_c4.py --- mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py b/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py index 70d6c042a10..3054818375f 100644 --- a/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py +++ b/mmdet/configs/_base_/models/mask_rcnn_r50_caffe_c4.py @@ -49,11 +49,6 @@ init_cfg=dict( type=PretrainedInit, checkpoint='open-mmlab://detectron2/resnet50_caffe')), - # neck=dict( - # type=FPN, - # in_channels=[256, 512, 1024, 2048], - # out_channels=256, - # num_outs=5), rpn_head=dict( type=RPNHead, in_channels=1024,