Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add MMClassification #34

Merged
merged 13 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
pip install mmcv-full==1.4.7 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
pip install nevergrad mmdet mmsegmentation
pip install nevergrad mmcls mmdet mmsegmentation protobuf==3.20
pip install -e .
- name: Run unittests and generate coverage report
run: |
Expand Down
36 changes: 36 additions & 0 deletions configs/mmcls/_base_/datasets/cifar100_bs16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# dataset settings
dataset_type = 'CIFAR100'
img_norm_cfg = dict(
mean=[129.304, 124.070, 112.434],
std=[68.170, 65.392, 70.418],
to_rgb=False)
train_pipeline = [
dict(type='RandomCrop', size=32, padding=4),
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='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
]
data = dict(
samples_per_gpu=16,
workers_per_gpu=2,
train=dict(
type=dataset_type,
data_prefix='data/cifar100',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
data_prefix='data/cifar100',
pipeline=test_pipeline,
test_mode=True),
test=dict(
type=dataset_type,
data_prefix='data/cifar100',
pipeline=test_pipeline,
test_mode=True))
35 changes: 35 additions & 0 deletions configs/mmcls/_base_/datasets/cifar10_bs16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# dataset settings
dataset_type = 'CIFAR10'
img_norm_cfg = dict(
mean=[125.307, 122.961, 113.8575],
std=[51.5865, 50.847, 51.255],
to_rgb=False)
train_pipeline = [
dict(type='RandomCrop', size=32, padding=4),
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='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
]
data = dict(
samples_per_gpu=16,
workers_per_gpu=2,
train=dict(
type=dataset_type, data_prefix='data/cifar10',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
data_prefix='data/cifar10',
pipeline=test_pipeline,
test_mode=True),
test=dict(
type=dataset_type,
data_prefix='data/cifar10',
pipeline=test_pipeline,
test_mode=True))
54 changes: 54 additions & 0 deletions configs/mmcls/_base_/datasets/cub_bs8_384.py
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
54 changes: 54 additions & 0 deletions configs/mmcls/_base_/datasets/cub_bs8_448.py
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
43 changes: 43 additions & 0 deletions configs/mmcls/_base_/datasets/imagenet21k_bs128.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# dataset settings
dataset_type = 'ImageNet21k'
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='RandomResizedCrop', size=224),
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=(256, -1)),
dict(type='CenterCrop', crop_size=224),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
]
data = dict(
samples_per_gpu=128,
workers_per_gpu=2,
train=dict(
type=dataset_type,
data_prefix='data/imagenet21k/train',
pipeline=train_pipeline,
recursion_subdir=True),
val=dict(
type=dataset_type,
data_prefix='data/imagenet21k/val',
ann_file='data/imagenet21k/meta/val.txt',
pipeline=test_pipeline,
recursion_subdir=True),
test=dict(
# replace `data/val` with `data/test` for standard test
type=dataset_type,
data_prefix='data/imagenet21k/val',
ann_file='data/imagenet21k/meta/val.txt',
pipeline=test_pipeline,
recursion_subdir=True))
evaluation = dict(interval=1, metric='accuracy')
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
_base_ = ['./pipelines/rand_aug.py']

# dataset settings
dataset_type = 'ImageNet'
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='RandomResizedCrop',
size=224,
backend='pillow',
interpolation='bicubic'),
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
dict(
type='RandAugment',
policies={{_base_.rand_increasing_policies}},
num_policies=2,
total_level=10,
magnitude_level=9,
magnitude_std=0.5,
hparams=dict(
pad_val=[round(x) for x in img_norm_cfg['mean'][::-1]],
interpolation='bicubic')),
dict(
type='RandomErasing',
erase_prob=0.25,
mode='rand',
min_area_ratio=0.02,
max_area_ratio=1 / 3,
fill_color=img_norm_cfg['mean'][::-1],
fill_std=img_norm_cfg['std'][::-1]),
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=(236, -1),
backend='pillow',
interpolation='bicubic'),
dict(type='CenterCrop', crop_size=224),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
]
data = dict(
samples_per_gpu=128,
workers_per_gpu=8,
train=dict(
type=dataset_type,
data_prefix='data/imagenet/train',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
data_prefix='data/imagenet/val',
ann_file='data/imagenet/meta/val.txt',
pipeline=test_pipeline),
test=dict(
# replace `data/val` with `data/test` for standard test
type=dataset_type,
data_prefix='data/imagenet/val',
ann_file='data/imagenet/meta/val.txt',
pipeline=test_pipeline))

evaluation = dict(interval=10, metric='accuracy')
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
_base_ = ['./pipelines/rand_aug.py']

# dataset settings
dataset_type = 'ImageNet'
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='RandomResizedCrop',
size=224,
backend='pillow',
interpolation='bicubic'),
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
dict(
type='RandAugment',
policies={{_base_.rand_increasing_policies}},
num_policies=2,
total_level=10,
magnitude_level=9,
magnitude_std=0.5,
hparams=dict(
pad_val=[round(x) for x in img_norm_cfg['mean'][::-1]],
interpolation='bicubic')),
dict(
type='RandomErasing',
erase_prob=0.25,
mode='rand',
min_area_ratio=0.02,
max_area_ratio=1 / 3,
fill_color=img_norm_cfg['mean'][::-1],
fill_std=img_norm_cfg['std'][::-1]),
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=(248, -1),
backend='pillow',
interpolation='bicubic'),
dict(type='CenterCrop', crop_size=224),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img'])
]
data = dict(
samples_per_gpu=128,
workers_per_gpu=8,
train=dict(
type=dataset_type,
data_prefix='data/imagenet/train',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
data_prefix='data/imagenet/val',
ann_file='data/imagenet/meta/val.txt',
pipeline=test_pipeline),
test=dict(
# replace `data/val` with `data/test` for standard test
type=dataset_type,
data_prefix='data/imagenet/val',
ann_file='data/imagenet/meta/val.txt',
pipeline=test_pipeline))

evaluation = dict(interval=10, metric='accuracy')
Loading