-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvnext_base_bit.py
132 lines (125 loc) · 3.92 KB
/
convnext_base_bit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
_base_ = [
'../_base_/datasets/levir_cd.py',
'../_base_/default_runtime.py', '../_base_/schedules/schedule_20k.py'
]
# model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
bit_norm_cfg = dict(type='LN', requires_grad=True)
pretrained = '/share/home/dongzhe/Dongzhe/Foundation_Model/Downstream_Tasks/semantic_segmentation/pretrained/pretrained_convnext_base.pth' # noqa'
model = dict(
type='SiamEncoderDecoder',
pretrained=pretrained,
backbone=dict(
type='ConvNeXt',
in_chans=3,
depths=[3, 3, 27, 3],
dims=[128, 256, 512, 1024],
drop_path_rate=0.4,
layer_scale_init_value=1.0,
out_indices=[0, 1, 2, 3], ),
neck=dict(
type='FeatureFusionNeck',
policy='concat',
out_indices=(0,)),
decode_head=dict(
type='BITHead',
in_channels=128,
channels=32,
embed_dims=64,
enc_depth=1,
enc_with_pos=True,
dec_depth=8,
num_heads=8,
drop_rate=0.,
use_tokenizer=True,
token_len=4,
upsample_size=4,
num_classes=2,
norm_cfg=bit_norm_cfg,
align_corners=False,
loss_decode=dict(
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)),
# model training and testing settings
train_cfg=dict(),
test_cfg=dict(mode='whole'))
crop_size = (256, 256)
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
dict(type='MultiImgLoadImageFromFile'),
dict(type='MultiImgLoadAnnotations'),
dict(type='MultiImgRandomRotate', prob=0.5, degree=180),
dict(type='MultiImgRandomCrop', crop_size=crop_size),
dict(type='MultiImgRandomFlip', prob=0.5, direction='horizontal'),
dict(type='MultiImgRandomFlip', prob=0.5, direction='vertical'),
dict(type='MultiImgExchangeTime', prob=0.5),
dict(
type='MultiImgPhotoMetricDistortion',
brightness_delta=10,
contrast_range=(0.8, 1.2),
saturation_range=(0.8, 1.2),
hue_delta=10),
dict(type='MultiImgNormalize', **img_norm_cfg),
dict(type='MultiImgDefaultFormatBundle'),
dict(type='Collect', keys=['img', 'gt_semantic_seg']),
]
test_pipeline = [
dict(type='MultiImgLoadImageFromFile'),
dict(
type='MultiImgMultiScaleFlipAug',
img_scale=(256, 256),
# img_ratios=[0.75, 1.0, 1.25],
flip=True,
transforms=[
dict(type='MultiImgResize', keep_ratio=True),
dict(type='MultiImgRandomFlip'),
dict(type='MultiImgNormalize', **img_norm_cfg),
dict(type='MultiImgImageToTensor', keys=['img']),
dict(type='Collect', keys=['img']),
])
]
data = dict(
samples_per_gpu=8,
workers_per_gpu=4,
train=dict(
img_dir='crop_256/trainval',
ann_dir='crop_256/trainval/label',
pipeline=train_pipeline),
val=dict(
img_dir='crop_256/test',
ann_dir='crop_256/test/label',
pipeline=test_pipeline),
test=dict(
img_dir='crop_256/test',
ann_dir='crop_256/test/label',
pipeline=test_pipeline))
log_config = dict(
interval=50,
hooks=[
dict(type='TextLoggerHook', by_epoch=False),
])
# optimizer
optimizer = dict(
constructor='LearningRateDecayOptimizerConstructor',
_delete_=True,
type='AdamW',
lr=0.0001,
betas=(0.9, 0.999),
weight_decay=0.05,
paramwise_cfg={
'decay_rate': 0.9,
'decay_type': 'stage_wise',
'num_layers': 12
})
lr_config = dict(
_delete_=True,
policy='poly',
warmup='linear',
warmup_iters=1500,
warmup_ratio=1e-6,
power=1.0,
min_lr=0.0,
by_epoch=False)
runner = dict(type='IterBasedRunner', max_iters=20000)
checkpoint_config = dict(by_epoch=False, interval=4000)
evaluation = dict(interval=4000, metric=['mFscore', 'mIoU'], pre_eval=True, save_best='Fscore.changed', greater_keys=['Fscore'])