-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support CUB dataset. (#703)
* support cub dataset * support cub dataset * fix train lint error * add docs * fix class label Co-authored-by: Ezra-Yu <1105212286@qq.com> * del debug code * skip docformatter problem * add unit tests * add CUB baseline configs and chpts * fix some typos * fix name style * update flops Co-authored-by: Ezra-Yu <1105212286@qq.com>
- Loading branch information
Showing
12 changed files
with
441 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# dataset settings | ||
dataset_type = 'CUB' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', size=510), | ||
dict(type='RandomCrop', size=384), | ||
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='ToTensor', keys=['gt_label']), | ||
dict(type='Collect', keys=['img', 'gt_label']) | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', size=510), | ||
dict(type='CenterCrop', crop_size=384), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='Collect', keys=['img']) | ||
] | ||
|
||
data_root = 'data/CUB_200_2011/' | ||
data = dict( | ||
samples_per_gpu=8, | ||
workers_per_gpu=2, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
test_mode=True, | ||
pipeline=test_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
test_mode=True, | ||
pipeline=test_pipeline)) | ||
|
||
evaluation = dict( | ||
interval=1, metric='accuracy', | ||
save_best='auto') # save the checkpoint with highest accuracy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# dataset settings | ||
dataset_type = 'CUB' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', size=600), | ||
dict(type='RandomCrop', size=448), | ||
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='ToTensor', keys=['gt_label']), | ||
dict(type='Collect', keys=['img', 'gt_label']) | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', size=600), | ||
dict(type='CenterCrop', crop_size=448), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='Collect', keys=['img']) | ||
] | ||
|
||
data_root = 'data/CUB_200_2011/' | ||
data = dict( | ||
samples_per_gpu=8, | ||
workers_per_gpu=2, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
test_mode=True, | ||
pipeline=test_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'images.txt', | ||
image_class_labels_file=data_root + 'image_class_labels.txt', | ||
train_test_split_file=data_root + 'train_test_split.txt', | ||
data_prefix=data_root + 'images', | ||
test_mode=True, | ||
pipeline=test_pipeline)) | ||
|
||
evaluation = dict( | ||
interval=1, metric='accuracy', | ||
save_best='auto') # save the checkpoint with highest accuracy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# optimizer | ||
optimizer = dict( | ||
type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005, nesterov=True) | ||
optimizer_config = dict(grad_clip=None) | ||
# learning policy | ||
lr_config = dict( | ||
policy='CosineAnnealing', | ||
min_lr=0, | ||
warmup='linear', | ||
warmup_iters=5, | ||
warmup_ratio=0.01, | ||
warmup_by_epoch=True) | ||
runner = dict(type='EpochBasedRunner', max_epochs=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
_base_ = [ | ||
'../_base_/models/resnet50.py', '../_base_/datasets/cub_bs8_448.py', | ||
'../_base_/schedules/cub_bs64.py', '../_base_/default_runtime.py' | ||
] | ||
|
||
# use pre-train weight converted from https://github.com/Alibaba-MIIL/ImageNet21K # noqa | ||
checkpoint = 'https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_mill_3rdparty_in21k_20220307-bdb3a68b.pth' # noqa | ||
|
||
model = dict( | ||
type='ImageClassifier', | ||
backbone=dict( | ||
init_cfg=dict( | ||
type='Pretrained', checkpoint=checkpoint, prefix='backbone')), | ||
head=dict(num_classes=200, )) | ||
|
||
log_config = dict(interval=20) # log every 20 intervals | ||
|
||
checkpoint_config = dict( | ||
interval=1, max_keep_ckpts=3) # save last three checkpoints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
_base_ = [ | ||
'../_base_/models/swin_transformer/large_384.py', | ||
'../_base_/datasets/cub_bs8_384.py', '../_base_/schedules/cub_bs64.py', | ||
'../_base_/default_runtime.py' | ||
] | ||
|
||
# model settings | ||
checkpoint = 'https://download.openmmlab.com/mmclassification/v0/swin-transformer/convert/swin-large_3rdparty_in21k-384px.pth' # noqa | ||
model = dict( | ||
type='ImageClassifier', | ||
backbone=dict( | ||
init_cfg=dict( | ||
type='Pretrained', checkpoint=checkpoint, prefix='backbone')), | ||
head=dict(num_classes=200, )) | ||
|
||
paramwise_cfg = dict( | ||
norm_decay_mult=0.0, | ||
bias_decay_mult=0.0, | ||
custom_keys={ | ||
'.absolute_pos_embed': dict(decay_mult=0.0), | ||
'.relative_position_bias_table': dict(decay_mult=0.0) | ||
}) | ||
|
||
optimizer = dict( | ||
_delete_=True, | ||
type='AdamW', | ||
lr=5e-6, | ||
weight_decay=0.0005, | ||
eps=1e-8, | ||
betas=(0.9, 0.999), | ||
paramwise_cfg=paramwise_cfg) | ||
optimizer_config = dict(grad_clip=dict(max_norm=5.0), _delete_=True) | ||
|
||
log_config = dict(interval=20) # log every 20 intervals | ||
|
||
checkpoint_config = dict( | ||
interval=1, max_keep_ckpts=3) # save last three checkpoints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.