forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseline_r34_4xb10-200k_comp1k.py
137 lines (127 loc) · 3.53 KB
/
baseline_r34_4xb10-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
134
135
136
137
_base_ = [
'../_base_/datasets/comp1k.py', '../_base_/matting_default_runtime.py'
]
experiment_name = 'baseline_r34_4xb10-200k_comp1k'
work_dir = f'./work_dirs/{experiment_name}'
save_dir = './work_dirs/'
# model settings
model = dict(
type='GCA',
data_preprocessor=dict(
type='MattorPreprocessor',
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
proc_trimap='as_is', # proc by pipeline FormatTrimap
),
backbone=dict(
type='SimpleEncoderDecoder',
encoder=dict(
type='ResShortcutEnc',
block='BasicBlock',
layers=[3, 4, 4, 2],
in_channels=6,
with_spectral_norm=True,
init_cfg=dict(
type='Pretrained',
checkpoint='open-mmlab://mmedit/res34_en_nomixup')),
decoder=dict(
type='ResShortcutDec',
block='BasicBlockDec',
layers=[2, 3, 3, 2],
with_spectral_norm=True)),
loss_alpha=dict(type='L1Loss'),
test_cfg=dict(
resize_method='pad',
resize_mode='reflect',
size_divisor=32,
))
# dataset settings
data_root = 'data/adobe_composition-1k'
bg_dir = 'data/coco/train2017'
train_pipeline = [
dict(type='LoadImageFromFile', key='alpha', color_type='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='FormatTrimap', to_onehot=True),
dict(type='PackInputs'),
]
test_pipeline = [
dict(
type='LoadImageFromFile',
key='alpha',
color_type='grayscale',
save_original_img=True),
dict(
type='LoadImageFromFile',
key='trimap',
color_type='grayscale',
save_original_img=True),
dict(type='LoadImageFromFile', key='merged'),
dict(type='FormatTrimap', to_onehot=True),
dict(type='PackInputs'),
]
train_dataloader = dict(
batch_size=10,
num_workers=8,
dataset=dict(pipeline=train_pipeline),
)
val_dataloader = dict(
batch_size=1,
dataset=dict(pipeline=test_pipeline),
)
test_dataloader = val_dataloader
train_cfg = dict(
type='IterBasedTrainLoop',
max_iters=200_000,
val_interval=10_000,
)
val_cfg = dict(type='MultiValLoop')
test_cfg = dict(type='MultiTestLoop')
# optimizer
optim_wrapper = dict(
constructor='DefaultOptimWrapperConstructor',
type='OptimWrapper',
optimizer=dict(type='Adam', lr=4e-4, betas=[0.5, 0.999]))
# learning policy
param_scheduler = [
dict(
type='LinearLR',
start_factor=0.001,
begin=0,
end=5000,
by_epoch=False,
),
dict(
type='CosineAnnealingLR',
T_max=200_000, # TODO, need more check
eta_min=0,
begin=0,
end=200_000,
by_epoch=False,
)
]
# checkpoint saving
# inheritate from default_runtime.py
# runtime settings
# inheritate from default_runtime.py