forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swinir_x4s48w8d6e180_8xb4-lr2e-4-500k_div2k.py
133 lines (120 loc) · 3.66 KB
/
swinir_x4s48w8d6e180_8xb4-lr2e-4-500k_div2k.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
133
_base_ = [
'../_base_/default_runtime.py', '../_base_/datasets/sisr_x4_test_config.py'
]
experiment_name = 'swinir_x4s48w8d6e180_8xb4-lr2e-4-500k_div2k'
work_dir = f'./work_dirs/{experiment_name}'
save_dir = './work_dirs/'
scale = 4
img_size = 48
# evaluated on Y channels
test_evaluator = _base_.test_evaluator
for evaluator in test_evaluator:
for metric in evaluator['metrics']:
metric['convert_to'] = 'Y'
# model settings
model = dict(
type='BaseEditModel',
generator=dict(
type='SwinIRNet',
upscale=scale,
in_chans=3,
img_size=img_size,
window_size=8,
img_range=1.0,
depths=[6, 6, 6, 6, 6, 6],
embed_dim=180,
num_heads=[6, 6, 6, 6, 6, 6],
mlp_ratio=2,
upsampler='pixelshuffle',
resi_connection='1conv'),
pixel_loss=dict(type='L1Loss', loss_weight=1.0, reduction='mean'),
data_preprocessor=dict(
type='EditDataPreprocessor', mean=[0., 0., 0.], std=[255., 255.,
255.]))
train_pipeline = [
dict(
type='LoadImageFromFile',
key='img',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(type='SetValues', dictionary=dict(scale=scale)),
dict(type='PairedRandomCrop', gt_patch_size=img_size * scale),
dict(
type='Flip',
keys=['img', 'gt'],
flip_ratio=0.5,
direction='horizontal'),
dict(
type='Flip', keys=['img', 'gt'], flip_ratio=0.5, direction='vertical'),
dict(type='RandomTransposeHW', keys=['img', 'gt'], transpose_ratio=0.5),
dict(type='PackEditInputs')
]
val_pipeline = [
dict(
type='LoadImageFromFile',
key='img',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(type='PackEditInputs')
]
# dataset settings
dataset_type = 'BasicImageDataset'
data_root = 'data'
train_dataloader = dict(
num_workers=4,
batch_size=4,
drop_last=True,
persistent_workers=False,
sampler=dict(type='InfiniteSampler', shuffle=True),
dataset=dict(
type=dataset_type,
ann_file='meta_info_DIV2K800sub_GT.txt',
metainfo=dict(dataset_type='div2k', task_name='sisr'),
data_root=data_root + '/DIV2K',
data_prefix=dict(
img='DIV2K_train_LR_bicubic/X4_sub', gt='DIV2K_train_HR_sub'),
filename_tmpl=dict(img='{}', gt='{}'),
pipeline=train_pipeline))
val_dataloader = dict(
num_workers=4,
persistent_workers=False,
drop_last=False,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type=dataset_type,
metainfo=dict(dataset_type='set5', task_name='sisr'),
data_root=data_root + '/Set5',
data_prefix=dict(img='LRbicx4', gt='GTmod12'),
pipeline=val_pipeline))
val_evaluator = [
dict(type='PSNR', crop_border=scale),
dict(type='SSIM', crop_border=scale),
]
train_cfg = dict(
type='IterBasedTrainLoop', max_iters=500_000, val_interval=5000)
val_cfg = dict(type='ValLoop')
# optimizer
optim_wrapper = dict(
constructor='DefaultOptimWrapperConstructor',
type='OptimWrapper',
optimizer=dict(type='Adam', lr=2e-4, betas=(0.9, 0.999)))
# learning policy
param_scheduler = dict(
type='MultiStepLR',
by_epoch=False,
milestones=[250000, 400000, 450000, 475000],
gamma=0.5)