forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glean_x16_2xb8_ffhq.py
117 lines (110 loc) · 3.21 KB
/
glean_x16_2xb8_ffhq.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
_base_ = '../_base_/models/base_glean.py'
experiment_name = 'glean_x16_2xb8_ffhq'
work_dir = f'./work_dirs/{experiment_name}'
save_dir = './work_dirs'
scale = 16
# model settings
model = dict(
type='SRGAN',
generator=dict(
type='GLEANStyleGANv2',
in_size=64,
out_size=1024,
style_channels=512,
init_cfg=dict(
type='Pretrained',
checkpoint='http://download.openmmlab.com/mmediting/stylegan2/'
'official_weights/stylegan2-ffhq-config-f-official_20210327'
'_171224-bce9310c.pth',
prefix='generator_ema')),
discriminator=dict(
type='StyleGANv2Discriminator',
in_size=1024,
init_cfg=dict(
type='Pretrained',
checkpoint='http://download.openmmlab.com/mmediting/stylegan2/'
'official_weights/stylegan2-ffhq-config-f-official_20210327'
'_171224-bce9310c.pth',
prefix='discriminator')),
pixel_loss=dict(type='MSELoss', loss_weight=1.0, reduction='mean'),
perceptual_loss=dict(
type='PerceptualLoss',
layer_weights={'21': 1.0},
vgg_type='vgg16',
perceptual_weight=1e-2,
style_weight=0,
norm_img=False,
criterion='mse',
pretrained='torchvision://vgg16'),
gan_loss=dict(
type='GANLoss',
gan_type='vanilla',
loss_weight=1e-2,
real_label_val=1.0,
fake_label_val=0),
train_cfg=dict(),
test_cfg=dict(),
data_preprocessor=dict(
type='DataPreprocessor',
mean=[127.5, 127.5, 127.5],
std=[127.5, 127.5, 127.5],
),
)
train_pipeline = [
dict(
type='LoadImageFromFile',
key='img',
color_type='color',
channel_order='rgb'),
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb'),
dict(
type='Flip',
keys=['img', 'gt'],
flip_ratio=0.5,
direction='horizontal'),
dict(type='PackInputs')
]
test_pipeline = [
dict(
type='LoadImageFromFile',
key='img',
color_type='color',
channel_order='rgb'),
dict(
type='LoadImageFromFile',
key='gt',
color_type='color',
channel_order='rgb'),
dict(type='PackInputs')
]
# dataset settings
dataset_type = 'BasicImageDataset'
train_dataloader = dict(
num_workers=8,
batch_size=8,
persistent_workers=False,
sampler=dict(type='InfiniteSampler', shuffle=True),
dataset=dict(
type=dataset_type,
metainfo=dict(dataset_type='ffhq', task_name='sisr'),
data_root='data/ffhq',
data_prefix=dict(img='BIx16_down', gt='images'),
ann_file='meta_info_FFHQ_GT.txt',
pipeline=train_pipeline))
val_dataloader = dict(
num_workers=8,
persistent_workers=False,
drop_last=False,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type=dataset_type,
metainfo=dict(dataset_type='ffhq', task_name='sisr'),
data_root='data/CelebA-HQ',
data_prefix=dict(img='BIx16_down', gt='GT'),
ann_file='meta_info_CelebAHQ_val100_GT.txt',
pipeline=test_pipeline))
test_dataloader = val_dataloader