|
| 1 | +# Copyright (c) Shanghai AI Lab. All rights reserved. |
| 2 | +_base_ = [ |
| 3 | + '../_base_/models/mask2former_beit.py', |
| 4 | + '../_base_/datasets/ade20k.py', |
| 5 | + '../_base_/default_runtime.py', |
| 6 | + '../_base_/schedules/schedule_160k.py' |
| 7 | +] |
| 8 | +crop_size = (896, 896) |
| 9 | +# pretrained = 'https://conversationhub.blob.core.windows.net/beit-share-public/beitv2/beitv2_large_patch16_224_pt1k_ft21k.pth' |
| 10 | +pretrained = 'pretrained/beitv2_large_patch16_224_pt1k_ft21k.pth' |
| 11 | +model = dict( |
| 12 | + type='EncoderDecoderMask2Former', |
| 13 | + pretrained=pretrained, |
| 14 | + backbone=dict( |
| 15 | + type='BEiTAdapter', |
| 16 | + img_size=896, |
| 17 | + patch_size=16, |
| 18 | + embed_dim=1024, |
| 19 | + depth=24, |
| 20 | + num_heads=16, |
| 21 | + mlp_ratio=4, |
| 22 | + qkv_bias=True, |
| 23 | + use_abs_pos_emb=False, |
| 24 | + use_rel_pos_bias=True, |
| 25 | + init_values=1e-6, |
| 26 | + drop_path_rate=0.3, |
| 27 | + conv_inplane=64, |
| 28 | + n_points=4, |
| 29 | + deform_num_heads=16, |
| 30 | + cffn_ratio=0.25, |
| 31 | + deform_ratio=0.5, |
| 32 | + with_cp=True, # set with_cp=True to save memory |
| 33 | + interaction_indexes=[[0, 5], [6, 11], [12, 17], [18, 23]], |
| 34 | + ), |
| 35 | + decode_head=dict( |
| 36 | + in_channels=[1024, 1024, 1024, 1024], |
| 37 | + feat_channels=1024, |
| 38 | + out_channels=1024, |
| 39 | + num_queries=200, |
| 40 | + pixel_decoder=dict( |
| 41 | + type='MSDeformAttnPixelDecoder', |
| 42 | + num_outs=3, |
| 43 | + norm_cfg=dict(type='GN', num_groups=32), |
| 44 | + act_cfg=dict(type='ReLU'), |
| 45 | + encoder=dict( |
| 46 | + type='DetrTransformerEncoder', |
| 47 | + num_layers=6, |
| 48 | + transformerlayers=dict( |
| 49 | + type='BaseTransformerLayer', |
| 50 | + attn_cfgs=dict( |
| 51 | + type='MultiScaleDeformableAttention', |
| 52 | + embed_dims=1024, |
| 53 | + num_heads=32, |
| 54 | + num_levels=3, |
| 55 | + num_points=4, |
| 56 | + im2col_step=64, |
| 57 | + dropout=0.0, |
| 58 | + batch_first=False, |
| 59 | + norm_cfg=None, |
| 60 | + init_cfg=None), |
| 61 | + ffn_cfgs=dict( |
| 62 | + type='FFN', |
| 63 | + embed_dims=1024, |
| 64 | + feedforward_channels=4096, |
| 65 | + num_fcs=2, |
| 66 | + ffn_drop=0.0, |
| 67 | + with_cp=True, # set with_cp=True to save memory |
| 68 | + act_cfg=dict(type='ReLU', inplace=True)), |
| 69 | + operation_order=('self_attn', 'norm', 'ffn', 'norm')), |
| 70 | + init_cfg=None), |
| 71 | + positional_encoding=dict( |
| 72 | + type='SinePositionalEncoding', num_feats=512, normalize=True), |
| 73 | + init_cfg=None), |
| 74 | + positional_encoding=dict( |
| 75 | + type='SinePositionalEncoding', num_feats=512, normalize=True), |
| 76 | + transformer_decoder=dict( |
| 77 | + type='DetrTransformerDecoder', |
| 78 | + return_intermediate=True, |
| 79 | + num_layers=9, |
| 80 | + transformerlayers=dict( |
| 81 | + type='DetrTransformerDecoderLayer', |
| 82 | + attn_cfgs=dict( |
| 83 | + type='MultiheadAttention', |
| 84 | + embed_dims=1024, |
| 85 | + num_heads=32, |
| 86 | + attn_drop=0.0, |
| 87 | + proj_drop=0.0, |
| 88 | + dropout_layer=None, |
| 89 | + batch_first=False), |
| 90 | + ffn_cfgs=dict( |
| 91 | + embed_dims=1024, |
| 92 | + feedforward_channels=4096, |
| 93 | + num_fcs=2, |
| 94 | + act_cfg=dict(type='ReLU', inplace=True), |
| 95 | + ffn_drop=0.0, |
| 96 | + dropout_layer=None, |
| 97 | + with_cp=True, # set with_cp=True to save memory |
| 98 | + add_identity=True), |
| 99 | + feedforward_channels=4096, |
| 100 | + operation_order=('cross_attn', 'norm', 'self_attn', 'norm', |
| 101 | + 'ffn', 'norm')), |
| 102 | + init_cfg=None) |
| 103 | + ), |
| 104 | + test_cfg=dict(mode='slide', crop_size=crop_size, stride=(512, 512)) |
| 105 | +) |
| 106 | +# dataset settings |
| 107 | +img_norm_cfg = dict( |
| 108 | + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) |
| 109 | +train_pipeline = [ |
| 110 | + dict(type='LoadImageFromFile'), |
| 111 | + dict(type='LoadAnnotations', reduce_zero_label=True), |
| 112 | + dict(type='Resize', img_scale=(3584, 896), ratio_range=(0.5, 2.0)), |
| 113 | + dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), |
| 114 | + dict(type='RandomFlip', prob=0.5), |
| 115 | + dict(type='PhotoMetricDistortion'), |
| 116 | + dict(type='Normalize', **img_norm_cfg), |
| 117 | + dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255), |
| 118 | + dict(type='ToMask'), |
| 119 | + dict(type='DefaultFormatBundle'), |
| 120 | + dict(type='Collect', keys=['img', 'gt_semantic_seg', 'gt_masks', 'gt_labels']) |
| 121 | +] |
| 122 | +test_pipeline = [ |
| 123 | + dict(type='LoadImageFromFile'), |
| 124 | + dict( |
| 125 | + type='MultiScaleFlipAug', |
| 126 | + img_scale=(3584, 896), |
| 127 | + # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75], |
| 128 | + flip=False, |
| 129 | + transforms=[ |
| 130 | + dict(type='Resize', keep_ratio=True), |
| 131 | + dict(type='ResizeToMultiple', size_divisor=32), |
| 132 | + dict(type='RandomFlip'), |
| 133 | + dict(type='Normalize', **img_norm_cfg), |
| 134 | + dict(type='ImageToTensor', keys=['img']), |
| 135 | + dict(type='Collect', keys=['img']), |
| 136 | + ]) |
| 137 | +] |
| 138 | +optimizer = dict(_delete_=True, type='AdamW', lr=2e-5, betas=(0.9, 0.999), weight_decay=0.05, |
| 139 | + constructor='LayerDecayOptimizerConstructor', |
| 140 | + paramwise_cfg=dict(num_layers=24, layer_decay_rate=0.90)) |
| 141 | +lr_config = dict(_delete_=True, |
| 142 | + policy='poly', |
| 143 | + warmup='linear', |
| 144 | + warmup_iters=1500, |
| 145 | + warmup_ratio=1e-6, |
| 146 | + power=1.0, min_lr=0.0, by_epoch=False) |
| 147 | +data = dict(samples_per_gpu=1, |
| 148 | + train=dict(pipeline=train_pipeline), |
| 149 | + val=dict(pipeline=test_pipeline), |
| 150 | + test=dict(pipeline=test_pipeline)) |
| 151 | +runner = dict(type='IterBasedRunner') |
| 152 | +checkpoint_config = dict(by_epoch=False, interval=1000, max_keep_ckpts=1) |
| 153 | +evaluation = dict(interval=8000, metric='mIoU', save_best='mIoU') |
0 commit comments