forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgca_r34_4x10_200k_comp1k.py
133 lines (129 loc) · 4.16 KB
/
gca_r34_4x10_200k_comp1k.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
# model settings
model = dict(
type='GCA',
backbone=dict(
type='SimpleEncoderDecoder',
encoder=dict(
type='ResGCAEncoder',
block='BasicBlock',
layers=[3, 4, 4, 2],
in_channels=6,
with_spectral_norm=True),
decoder=dict(
type='ResGCADecoder',
block='BasicBlockDec',
layers=[2, 3, 3, 2],
with_spectral_norm=True)),
loss_alpha=dict(type='L1Loss'),
pretrained='open-mmlab://mmedit/res34_en_nomixup')
train_cfg = dict(train_backbone=True)
test_cfg = dict(metrics=['SAD', 'MSE', 'GRAD', 'CONN'])
# dataset settings
dataset_type = 'AdobeComp1kDataset'
data_root = 'data/adobe_composition-1k'
bg_dir = './data/coco/train2017'
img_norm_cfg = dict(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], to_rgb=True)
train_pipeline = [
dict(type='LoadImageFromFile', key='alpha', flag='grayscale'),
dict(type='LoadImageFromFile', key='fg'),
dict(type='RandomLoadResizeBg', bg_dir=bg_dir),
dict(
type='CompositeFg',
fg_dirs=[
f'{data_root}/Training_set/Adobe-licensed images/fg',
f'{data_root}/Training_set/Other/fg'
],
alpha_dirs=[
f'{data_root}/Training_set/Adobe-licensed images/alpha',
f'{data_root}/Training_set/Other/alpha'
]),
dict(
type='RandomAffine',
keys=['alpha', 'fg'],
degrees=30,
scale=(0.8, 1.25),
shear=10,
flip_ratio=0.5),
dict(type='GenerateTrimap', kernel_size=(1, 30)),
dict(type='CropAroundCenter', crop_size=512),
dict(type='RandomJitter'),
dict(type='MergeFgAndBg'),
dict(type='RescaleToZeroOne', keys=['merged', 'alpha']),
dict(type='Normalize', keys=['merged'], **img_norm_cfg),
dict(type='Collect', keys=['merged', 'alpha', 'trimap'], meta_keys=[]),
dict(type='ImageToTensor', keys=['merged', 'alpha', 'trimap']),
dict(type='FormatTrimap', to_onehot=True),
]
test_pipeline = [
dict(
type='LoadImageFromFile',
key='alpha',
flag='grayscale',
save_original_img=True),
dict(
type='LoadImageFromFile',
key='trimap',
flag='grayscale',
save_original_img=True),
dict(type='LoadImageFromFile', key='merged'),
dict(type='Pad', keys=['trimap', 'merged'], mode='reflect'),
dict(type='RescaleToZeroOne', keys=['merged']),
dict(type='Normalize', keys=['merged'], **img_norm_cfg),
dict(
type='Collect',
keys=['merged', 'trimap'],
meta_keys=[
'merged_path', 'pad', 'merged_ori_shape', 'ori_alpha', 'ori_trimap'
]),
dict(type='ImageToTensor', keys=['merged', 'trimap']),
dict(type='FormatTrimap', to_onehot=True),
]
data = dict(
workers_per_gpu=8,
train_dataloader=dict(samples_per_gpu=10, drop_last=True),
val_dataloader=dict(samples_per_gpu=1),
test_dataloader=dict(samples_per_gpu=1),
train=dict(
type=dataset_type,
ann_file=f'{data_root}/training_list.json',
data_prefix=data_root,
pipeline=train_pipeline),
val=dict(
type=dataset_type,
ann_file=f'{data_root}/test_list.json',
data_prefix=data_root,
pipeline=test_pipeline),
test=dict(
type=dataset_type,
ann_file=f'{data_root}/test_list.json',
data_prefix=data_root,
pipeline=test_pipeline))
# optimizer
optimizers = dict(type='Adam', lr=4e-4, betas=[0.5, 0.999])
# learning policy
lr_config = dict(
policy='CosineAnnealing',
min_lr=0,
by_epoch=False,
warmup='linear',
warmup_iters=5000,
warmup_ratio=0.001)
# checkpoint saving
checkpoint_config = dict(interval=2000, by_epoch=False)
evaluation = dict(interval=2000, save_image=False, gpu_collect=False)
log_config = dict(
interval=10,
hooks=[
dict(type='TextLoggerHook', by_epoch=False),
# dict(type='TensorboardLoggerHook'),
# dict(type='PaviLoggerHook', init_kwargs=dict(project='gca'))
])
# runtime settings
total_iters = 200000
dist_params = dict(backend='nccl')
log_level = 'INFO'
work_dir = './work_dirs/gca'
load_from = None
resume_from = None
workflow = [('train', 1)]