_base_ = [ './datasets/hsi_detection4x.py', '../_base_/default_runtime.py' # './datasets/hsi_detection.py', '../_base_/default_runtime.py' ] fp16 = dict(loss_scale=512.) # pretrained = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_large_patch4_window12_384_22k.pth' # noqa pretrained = 'https://download.openmmlab.com/mmclassification/v0/swin-transformer/convert/swin_large_patch4_window12_384_22kto1k-0a40944b.pth' num_levels = 5 in_channels = 30 model = dict( type='DINO', num_queries=900, # num_matching_queries 900 with_box_refine=True, as_two_stage=True, num_feature_levels=num_levels, data_preprocessor=dict( type='HSIDetDataPreprocessor', pad_size_divisor=1), backbone=dict( type='SwinTransformer', pretrain_img_size=384, in_channels=in_channels, embed_dims=192, depths=[2, 2, 18, 2], num_heads=[6, 12, 24, 48], window_size=12, mlp_ratio=4, qkv_bias=True, qk_scale=None, drop_rate=0., attn_drop_rate=0., drop_path_rate=0.2, patch_norm=True, out_indices=(0, 1, 2, 3), # Please only add indices that would be used # in FPN, otherwise some parameter will not be used with_cp=True, convert_weights=True, init_cfg=dict(type='Pretrained', checkpoint=pretrained) ), neck=dict( type='ChannelMapper', in_channels=[192, 384, 768, 1536], kernel_size=1, out_channels=256, act_cfg=None, norm_cfg=dict(type='GN', num_groups=32), num_outs=num_levels), encoder=dict( num_layers=6, layer_cfg=dict( self_attn_cfg=dict(embed_dims=256, num_levels=num_levels, dropout=0.0), # 0.1 for DeformDETR ffn_cfg=dict( embed_dims=256, feedforward_channels=2048, # 1024 for DeformDETR ffn_drop=0.0))), # 0.1 for DeformDETR decoder=dict( num_layers=6, return_intermediate=True, layer_cfg=dict( self_attn_cfg=dict(embed_dims=256, num_heads=8, dropout=0.0), # 0.1 for DeformDETR cross_attn_cfg=dict(embed_dims=256, num_levels=num_levels, dropout=0.0), # 0.1 for DeformDETR ffn_cfg=dict( embed_dims=256, feedforward_channels=2048, # 1024 for DeformDETR ffn_drop=0.0)), # 0.1 for DeformDETR post_norm_cfg=None), positional_encoding=dict( num_feats=128, normalize=True, offset=0.0, # -0.5 for DeformDETR temperature=20), # 10000 for DeformDETR bbox_head=dict( type='DINOHead', num_classes=8, sync_cls_avg_factor=True, loss_cls=dict( type='FocalLoss', use_sigmoid=True, gamma=2.0, alpha=0.25, loss_weight=1.0), # 2.0 in DeformDETR loss_bbox=dict(type='L1Loss', loss_weight=5.0), loss_iou=dict(type='GIoULoss', loss_weight=2.0)), dn_cfg=dict( # TODO: Move to model.train_cfg ? label_noise_scale=0.5, box_noise_scale=1.0, # 0.4 for DN-DETR group_cfg=dict(dynamic=True, num_groups=None, num_dn_queries=100)), # TODO: half num_dn_queries # training and testing settings train_cfg=dict( assigner=dict( type='HungarianAssigner', match_costs=[ dict(type='FocalLossCost', weight=2.0), dict(type='BBoxL1Cost', weight=5.0, box_format='xywh'), dict(type='IoUCost', iou_mode='giou', weight=2.0) ])), test_cfg=dict(max_per_img=300)) # 100 for DeformDETR # optimizer optim_wrapper = dict( type='OptimWrapper', optimizer=dict( type='AdamW', lr=0.0001, # 0.0002 for DeformDETR weight_decay=0.0001), clip_grad=dict(max_norm=0.1, norm_type=2), paramwise_cfg=dict(custom_keys={'backbone': dict(lr_mult=0.1)}) ) # custom_keys contains sampling_offsets and reference_points in DeformDETR # noqa # learning policy max_epochs = 12 train_cfg = dict( type='EpochBasedTrainLoop', max_epochs=max_epochs, val_interval=12) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') param_scheduler = [ dict( type='MultiStepLR', begin=0, end=max_epochs, by_epoch=True, milestones=[11], gamma=0.1) ] train_dataloader = dict( batch_size=4,) test_dataloader = dict( batch_size=1,) # NOTE: `auto_scale_lr` is for automatically scaling LR, # USER SHOULD NOT CHANGE ITS VALUES. # base_batch_size = (8 GPUs) x (2 samples per GPU) auto_scale_lr = dict(base_batch_size=4)