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

[MMSIG] 334 The new version of config adapts ResNet algorithm #1828

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions mmpretrain/configs/_base_/datasets/imagenet_bs64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmengine.dataset import DefaultSampler

from mmpretrain.datasets import (CenterCrop, ImageNet, LoadImageFromFile,
PackInputs, RandomFlip, RandomResizedCrop,
ResizeEdge)
from mmpretrain.evaluation import Accuracy

# dataset settings
dataset_type = ImageNet
data_preprocessor = dict(
num_classes=1000,
# RGB format normalization parameters
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
# convert image from BGR to RGB
to_rgb=True,
)

train_pipeline = [
dict(type=LoadImageFromFile),
dict(type=RandomResizedCrop, scale=224),
dict(type=RandomFlip, prob=0.5, direction='horizontal'),
dict(type=PackInputs),
]

test_pipeline = [
dict(type=LoadImageFromFile),
dict(type=ResizeEdge, scale=256, edge='short'),
dict(type=CenterCrop, crop_size=224),
dict(type=PackInputs),
]

train_dataloader = dict(
batch_size=64,
num_workers=5,
dataset=dict(
type=dataset_type,
data_root='data/imagenet',
split='train',
pipeline=train_pipeline),
sampler=dict(type=DefaultSampler, shuffle=True),
)

val_dataloader = dict(
batch_size=64,
num_workers=5,
dataset=dict(
type=dataset_type,
data_root='data/imagenet',
split='val',
pipeline=test_pipeline),
sampler=dict(type=DefaultSampler, shuffle=False),
)
val_evaluator = dict(type=Accuracy, topk=(1, 5))

# If you want standard test, please manually configure the test dataset
test_dataloader = val_dataloader
test_evaluator = val_evaluator
22 changes: 22 additions & 0 deletions mmpretrain/configs/_base_/models/resnet101.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=101,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
topk=(1, 5),
))
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/models/resnet101_cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=101,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
))
22 changes: 22 additions & 0 deletions mmpretrain/configs/_base_/models/resnet152.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=152,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
topk=(1, 5),
))
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/models/resnet152_cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=152,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
))
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/models/resnet18_cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=18,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=10,
in_channels=512,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
))
22 changes: 22 additions & 0 deletions mmpretrain/configs/_base_/models/resnet34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=34,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=512,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
topk=(1, 5),
))
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/models/resnet34_cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=34,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=10,
in_channels=512,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
))
22 changes: 22 additions & 0 deletions mmpretrain/configs/_base_/models/resnet34_gem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GeneralizedMeanPooling,
ImageClassifier, LinearClsHead, ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=34,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GeneralizedMeanPooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=512,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
topk=(1, 5),
))
22 changes: 22 additions & 0 deletions mmpretrain/configs/_base_/models/resnet50.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=50,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
topk=(1, 5),
))
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/models/resnet50_cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, LinearClsHead, ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=50,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=LinearClsHead,
num_classes=10,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0),
))
23 changes: 23 additions & 0 deletions mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling,
ImageClassifier, Mixup, MultiLabelLinearClsHead,
ResNet_CIFAR)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet_CIFAR,
depth=50,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=MultiLabelLinearClsHead,
num_classes=10,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0, use_soft=True)),
train_cfg=dict(augments=dict(type=Mixup, alpha=1.)),
)
24 changes: 24 additions & 0 deletions mmpretrain/configs/_base_/models/resnet50_cutmix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmpretrain.models import (CrossEntropyLoss, CutMix, GlobalAveragePooling,
ImageClassifier, MultiLabelLinearClsHead,
ResNet)

# model settings
model = dict(
type=ImageClassifier,
backbone=dict(
type=ResNet,
depth=50,
num_stages=4,
out_indices=(3, ),
style='pytorch'),
neck=dict(type=GlobalAveragePooling),
head=dict(
type=MultiLabelLinearClsHead,
num_classes=1000,
in_channels=2048,
loss=dict(type=CrossEntropyLoss, loss_weight=1.0, use_soft=True)),
train_cfg=dict(
augments=dict(type=CutMix, alpha=1.0, num_classes=1000, prob=1.0)),
)
24 changes: 24 additions & 0 deletions mmpretrain/configs/_base_/schedules/imagenet_bs2048.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmengine.optim import LinearLR, MultiStepLR
from torch.optim import SGD

# optimizer
optim_wrapper = dict(
optimizer=dict(
type=SGD, lr=0.8, momentum=0.9, weight_decay=0.0001, nesterov=True))

# learning policy
param_scheduler = [
dict(type=LinearLR, start_factor=0.25, by_epoch=False, begin=0, end=2500),
dict(type=MultiStepLR, by_epoch=True, milestones=[30, 60, 90], gamma=0.1)
]

# train, val, test setting
train_cfg = dict(by_epoch=True, max_epochs=100, val_interval=1)
val_cfg = dict()
test_cfg = dict()

# NOTE: `auto_scale_lr` is for automatically scaling LR,
# based on the actual training batch size.
auto_scale_lr = dict(base_batch_size=2048)
21 changes: 21 additions & 0 deletions mmpretrain/configs/_base_/schedules/imagenet_bs256_coslr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmengine.optim import CosineAnnealingLR
from torch.optim import SGD

# optimizer
optim_wrapper = dict(
optimizer=dict(type=SGD, lr=0.1, momentum=0.9, weight_decay=0.0001))

# learning policy
param_scheduler = dict(
type=CosineAnnealingLR, T_max=100, by_epoch=True, begin=0, end=100)

# train, val, test setting
train_cfg = dict(by_epoch=True, max_epochs=100, val_interval=1)
val_cfg = dict()
test_cfg = dict()

# NOTE: `auto_scale_lr` is for automatically scaling LR,
# based on the actual training batch size.
auto_scale_lr = dict(base_batch_size=256)
9 changes: 9 additions & 0 deletions mmpretrain/configs/resnet/resnet101_8xb16_cifar10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.
# This is a BETA new format config file, and the usage may change recently.
from mmengine.config import read_base

with read_base():
from .._base_.datasets.cifar10_bs16 import *
from .._base_.default_runtime import *
from .._base_.models.resnet101_cifar import *
from .._base_.schedules.cifar10_bs128 import *
Loading
Loading