2023-02-23 11:17:16 +08:00
|
|
|
_base_ = [
|
|
|
|
'../../_base_/datasets/imagenet_bs64_swin_224.py',
|
|
|
|
'../../_base_/schedules/imagenet_bs1024_adamw_swin.py',
|
|
|
|
'../../_base_/default_runtime.py'
|
|
|
|
]
|
|
|
|
|
|
|
|
# dataset settings
|
|
|
|
train_pipeline = [
|
|
|
|
dict(type='LoadImageFromFile'),
|
|
|
|
dict(
|
|
|
|
type='RandomResizedCrop',
|
|
|
|
scale=224,
|
|
|
|
backend='pillow',
|
|
|
|
interpolation='bicubic'),
|
|
|
|
dict(type='RandomFlip', prob=0.5, direction='horizontal'),
|
|
|
|
dict(
|
|
|
|
type='RandAugment',
|
|
|
|
policies='timm_increasing',
|
|
|
|
num_policies=2,
|
|
|
|
total_level=10,
|
|
|
|
magnitude_level=9,
|
|
|
|
magnitude_std=0.5,
|
|
|
|
hparams=dict(pad_val=[104, 116, 124], interpolation='bicubic')),
|
|
|
|
dict(
|
|
|
|
type='RandomErasing',
|
|
|
|
erase_prob=0.25,
|
|
|
|
mode='rand',
|
|
|
|
min_area_ratio=0.02,
|
|
|
|
max_area_ratio=0.3333333333333333,
|
|
|
|
fill_color=[103.53, 116.28, 123.675],
|
|
|
|
fill_std=[57.375, 57.12, 58.395]),
|
2023-03-03 15:01:11 +08:00
|
|
|
dict(type='PackInputs')
|
2023-02-23 11:17:16 +08:00
|
|
|
]
|
|
|
|
test_pipeline = [
|
|
|
|
dict(type='LoadImageFromFile'),
|
|
|
|
dict(
|
|
|
|
type='ResizeEdge',
|
|
|
|
scale=256,
|
|
|
|
edge='short',
|
|
|
|
backend='pillow',
|
|
|
|
interpolation='bicubic'),
|
|
|
|
dict(type='CenterCrop', crop_size=224),
|
2023-03-03 15:01:11 +08:00
|
|
|
dict(type='PackInputs')
|
2023-02-23 11:17:16 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
train_dataloader = dict(batch_size=128, dataset=dict(pipeline=train_pipeline))
|
|
|
|
val_dataloader = dict(batch_size=128, dataset=dict(pipeline=test_pipeline))
|
|
|
|
test_dataloader = val_dataloader
|
|
|
|
|
|
|
|
# model settings
|
|
|
|
model = dict(
|
|
|
|
type='ImageClassifier',
|
|
|
|
backbone=dict(
|
|
|
|
type='VisionTransformer',
|
|
|
|
arch='huge',
|
|
|
|
img_size=224,
|
|
|
|
patch_size=14,
|
|
|
|
drop_path_rate=0.3, # set to 0.3
|
|
|
|
avg_token=True,
|
|
|
|
output_cls_token=False,
|
|
|
|
final_norm=False,
|
|
|
|
init_cfg=dict(type='Pretrained', checkpoint='')),
|
|
|
|
neck=None,
|
|
|
|
head=dict(
|
|
|
|
type='LinearClsHead',
|
|
|
|
num_classes=1000,
|
|
|
|
in_channels=1280,
|
|
|
|
loss=dict(
|
|
|
|
type='LabelSmoothLoss', label_smooth_val=0.1, mode='original'),
|
|
|
|
init_cfg=[dict(type='TruncNormal', layer='Linear', std=2e-5)]),
|
|
|
|
train_cfg=dict(augments=[
|
|
|
|
dict(type='Mixup', alpha=0.8),
|
|
|
|
dict(type='CutMix', alpha=1.0)
|
|
|
|
]))
|
|
|
|
|
|
|
|
# optimizer wrapper
|
|
|
|
# learning rate and layer decay rate are set to 0.004 and 0.75 respectively
|
|
|
|
optim_wrapper = dict(
|
|
|
|
optimizer=dict(
|
|
|
|
type='AdamW',
|
|
|
|
lr=4e-3,
|
|
|
|
weight_decay=0.05,
|
|
|
|
eps=1e-8,
|
|
|
|
betas=(0.9, 0.999),
|
|
|
|
model_type='vit', # layer-wise lr decay type
|
|
|
|
layer_decay_rate=0.75), # layer-wise lr decay factor
|
|
|
|
constructor='LearningRateDecayOptimWrapperConstructor',
|
|
|
|
paramwise_cfg=dict(
|
|
|
|
custom_keys={
|
|
|
|
'.ln': dict(decay_mult=0.0),
|
|
|
|
'.bias': dict(decay_mult=0.0),
|
|
|
|
'.cls_token': dict(decay_mult=0.0),
|
|
|
|
'.pos_embed': dict(decay_mult=0.0)
|
|
|
|
}))
|
|
|
|
|
|
|
|
# learning rate scheduler
|
|
|
|
param_scheduler = [
|
|
|
|
dict(
|
|
|
|
type='LinearLR',
|
|
|
|
start_factor=1e-4,
|
|
|
|
by_epoch=True,
|
|
|
|
begin=0,
|
|
|
|
end=5,
|
|
|
|
convert_to_iter_based=True),
|
|
|
|
dict(
|
|
|
|
type='CosineAnnealingLR',
|
|
|
|
T_max=45,
|
|
|
|
by_epoch=True,
|
|
|
|
begin=5,
|
|
|
|
end=50,
|
|
|
|
eta_min=1e-6,
|
|
|
|
convert_to_iter_based=True)
|
|
|
|
]
|
|
|
|
|
|
|
|
# runtime settings
|
|
|
|
train_cfg = dict(by_epoch=True, max_epochs=50)
|
|
|
|
default_hooks = dict(
|
|
|
|
# save checkpoint per epoch.
|
|
|
|
checkpoint=dict(type='CheckpointHook', interval=1, max_keep_ckpts=3))
|
|
|
|
|
|
|
|
randomness = dict(seed=0, diff_rank_seed=True)
|