forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdic_x8c48b6_4xb2-150k_celeba-hq.py
171 lines (156 loc) · 4.29 KB
/
dic_x8c48b6_4xb2-150k_celeba-hq.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
_base_ = '../_base_/default_runtime.py'
experiment_name = 'dic_x8c48b6_4xb2-150k_celeba-hq'
work_dir = f'./work_dirs/{experiment_name}'
save_dir = './work_dirs/'
scale = 8
# DistributedDataParallel
model_wrapper_cfg = dict(type='MMSeparateDistributedDataParallel')
# model settings
model = dict(
type='DIC',
generator=dict(
type='DICNet', in_channels=3, out_channels=3, mid_channels=48),
pixel_loss=dict(type='L1Loss', loss_weight=1.0, reduction='mean'),
align_loss=dict(type='MSELoss', loss_weight=0.1, reduction='mean'),
train_cfg=dict(),
test_cfg=dict(),
data_preprocessor=dict(
type='DataPreprocessor',
mean=[129.795, 108.12, 96.39],
std=[255, 255, 255],
))
train_pipeline = [
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(
type='Resize',
scale=(128, 128),
keys=['gt'],
interpolation='bicubic',
backend='pillow'),
dict(
type='Resize',
scale=1 / 8,
keep_ratio=True,
keys=['gt'],
output_keys=['img'],
interpolation='bicubic',
backend='pillow'),
dict(
type='GenerateFacialHeatmap',
image_key='gt',
ori_size=128,
target_size=32,
sigma=1.0),
dict(type='PackInputs')
]
valid_pipeline = [
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(
type='Resize',
scale=(128, 128),
keys=['gt'],
interpolation='bicubic',
backend='pillow'),
dict(
type='Resize',
scale=1 / 8,
keep_ratio=True,
keys=['gt'],
output_keys=['img'],
interpolation='bicubic',
backend='pillow'),
dict(type='PackInputs')
]
test_pipeline = valid_pipeline
inference_pipeline = [
dict(
type='LoadImageFromFile',
key='img',
color_type='color',
channel_order='rgb',
imdecode_backend='cv2'),
dict(
type='Resize',
scale=(128, 128),
keys=['img'],
interpolation='bicubic',
backend='pillow'),
dict(
type='Resize',
scale=1 / 8,
keep_ratio=True,
keys=['img'],
output_keys=['img'],
interpolation='bicubic',
backend='pillow'),
dict(type='PackInputs')
]
# dataset settings
dataset_type = 'BasicImageDataset'
data_root = 'data'
train_dataloader = dict(
num_workers=4,
batch_size=2, # gpus 4
persistent_workers=False,
sampler=dict(type='InfiniteSampler', shuffle=True),
dataset=dict(
type=dataset_type,
metainfo=dict(dataset_type='celeba', task_name='fsr'),
data_root=data_root + '/CelebA-HQ',
data_prefix=dict(gt='train_256/all_256'),
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='celeba', task_name='fsr'),
data_root=data_root + '/CelebA-HQ',
data_prefix=dict(gt='test_256/all_256'),
pipeline=test_pipeline))
test_dataloader = val_dataloader
val_evaluator = [
dict(type='MAE'),
dict(type='PSNR', crop_border=scale),
dict(type='SSIM', crop_border=scale),
]
test_evaluator = val_evaluator
train_cfg = dict(
type='IterBasedTrainLoop', max_iters=150_000, val_interval=2000)
val_cfg = dict(type='MultiValLoop')
test_cfg = dict(type='MultiTestLoop')
# optimizer
optim_wrapper = dict(
constructor='MultiOptimWrapperConstructor',
generator=dict(type='OptimWrapper', optimizer=dict(type='Adam', lr=1e-4)))
# learning policy
param_scheduler = dict(
type='MultiStepLR',
by_epoch=False,
milestones=[10000, 20000, 40000, 80000],
gamma=0.5)
default_hooks = dict(
checkpoint=dict(
type='CheckpointHook',
interval=2000,
save_optimizer=True,
by_epoch=False,
out_dir=save_dir,
),
timer=dict(type='IterTimerHook'),
logger=dict(type='LoggerHook', interval=100),
param_scheduler=dict(type='ParamSchedulerHook'),
sampler_seed=dict(type='DistSamplerSeedHook'),
)