-
Notifications
You must be signed in to change notification settings - Fork 203
/
imagenet_swin_tiny_patch4_window7_224_jpg_torchacc.py
136 lines (127 loc) · 3.64 KB
/
imagenet_swin_tiny_patch4_window7_224_jpg_torchacc.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
_base_ = 'configs/base.py'
# The bigger the log interval, the better, it will reduce the training speed
log_config = dict(
interval=200,
hooks=[
dict(type='TextLoggerHook'),
# dict(type='TensorboardLoggerHook')
])
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='PytorchImageModelWrapper',
model_name='swin_tiny_patch4_window7_224',
num_classes=1000,
),
head=dict(
type='ClsHead',
loss_config={
'type': 'SoftTargetCrossEntropy',
},
with_fc=False))
data_root = 'data/imagenet_raw/'
data_train_list = data_root + 'meta/train_labeled.txt'
data_train_root = data_root + 'train/'
data_test_list = data_root + 'meta/val_labeled.txt'
data_test_root = data_root + 'val/'
data_all_list = data_root + 'meta/all_labeled.txt'
dataset_type = 'ClsDataset'
img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
train_pipeline = [
dict(type='RandomResizedCrop', size=224),
dict(type='RandomHorizontalFlip'),
dict(
type='MMRandAugment',
num_policies=2,
total_level=10,
magnitude_level=9,
magnitude_std=0.5,
hparams=dict(
pad_val=[round(x * 255) for x in img_norm_cfg['mean'][::-1]],
interpolation='bicubic')),
dict(
type='MMRandomErasing',
erase_prob=0.25,
mode='rand',
min_area_ratio=0.02,
max_area_ratio=1 / 3,
fill_color=[x * 255 for x in img_norm_cfg['mean'][::-1]],
fill_std=[x * 255 for x in img_norm_cfg['std'][::-1]]),
dict(type='ToTensor'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Collect', keys=['img', 'gt_labels'])
]
test_pipeline = [
dict(type='Resize', size=256),
dict(type='CenterCrop', size=224),
dict(type='ToTensor'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Collect', keys=['img', 'gt_labels'])
]
data = dict(
imgs_per_gpu=64, # total 256
workers_per_gpu=8,
drop_last=True,
train_collate_hooks=[
dict(
type='MixupCollateHook',
mixup_alpha=0.8,
cutmix_alpha=1.0,
prob=0.5,
mode='batch',
label_smoothing=0.1,
num_classes=1000)
],
train=dict(
type=dataset_type,
data_source=dict(
list_file=data_train_list,
root=data_train_root,
type='ClsSourceImageList'),
pipeline=train_pipeline),
val=dict(
type=dataset_type,
data_source=dict(
list_file=data_test_list,
root=data_test_root,
type='ClsSourceImageList'),
pipeline=test_pipeline))
eval_config = dict(initial=False, interval=1, gpu_collect=True)
eval_pipelines = [
dict(
mode='test',
data=data['val'],
dist_eval=True,
evaluators=[dict(type='ClsEvaluator', topk=(1, 5))])
]
# additional hooks
custom_hooks = []
# optimizer
paramwise_options = {
'norm': dict(weight_decay=0.),
'bias': dict(weight_decay=0.),
'absolute_pos_embed': dict(weight_decay=0.),
'relative_position_bias_table': dict(weight_decay=0.)
}
optimizer = dict(
type='AdamW',
lr=5e-4 * 1024 / 512,
weight_decay=0.05,
eps=1e-8,
betas=(0.9, 0.999),
paramwise_options=paramwise_options)
optimizer_config = dict(grad_clip=dict(max_norm=5.0))
# learning policy
lr_config = dict(
policy='CosineAnnealing',
by_epoch=False,
min_lr_ratio=1e-2,
warmup='linear',
warmup_ratio=1e-3,
warmup_iters=20,
warmup_by_epoch=True)
checkpoint_config = dict(interval=30)
# runtime settings
total_epochs = 300