From 58630571edbda26b6e74eee474c73225218ac396 Mon Sep 17 00:00:00 2001 From: "zhenxiong.duan1109" Date: Mon, 30 Oct 2023 15:45:27 +0800 Subject: [PATCH 1/4] new version of config adapts ResNet --- .../configs/_base_/datasets/imagenet_bs64.py | 60 +++++++++++++++++++ mmpretrain/configs/_base_/models/resnet101.py | 23 +++++++ .../configs/_base_/models/resnet101_cifar.py | 22 +++++++ mmpretrain/configs/_base_/models/resnet152.py | 22 +++++++ .../configs/_base_/models/resnet152_cifar.py | 21 +++++++ .../configs/_base_/models/resnet18_cifar.py | 21 +++++++ mmpretrain/configs/_base_/models/resnet34.py | 22 +++++++ .../configs/_base_/models/resnet34_cifar.py | 21 +++++++ .../configs/_base_/models/resnet34_gem.py | 22 +++++++ mmpretrain/configs/_base_/models/resnet50.py | 22 +++++++ .../configs/_base_/models/resnet50_cifar.py | 21 +++++++ .../_base_/models/resnet50_cifar_mixup.py | 22 +++++++ .../configs/_base_/models/resnet50_cutmix.py | 23 +++++++ .../_base_/schedules/imagenet_bs2048.py | 26 ++++++++ .../_base_/schedules/imagenet_bs256_coslr.py | 21 +++++++ .../configs/resnet/resnet101_8xb16_cifar10.py | 9 +++ .../configs/resnet/resnet101_8xb32_in1k.py | 9 +++ .../configs/resnet/resnet152_8xb16_cifar10.py | 9 +++ .../configs/resnet/resnet152_8xb32_in1k.py | 9 +++ .../configs/resnet/resnet18_8xb16_cifar10.py | 9 +++ .../configs/resnet/resnet34_8xb16_cifar10.py | 10 ++++ .../configs/resnet/resnet34_8xb32_in1k.py | 9 +++ .../resnet/resnet50_32xb64-warmup_in1k.py | 9 +++ .../resnet/resnet50_8xb16-mixup_cifar10.py | 9 +++ .../configs/resnet/resnet50_8xb16_cifar10.py | 9 +++ .../resnet50_8xb32-coslr-preciseBN_in1k.py | 23 +++++++ .../resnet/resnet50_8xb32-coslr_in1k.py | 9 +++ .../resnet/resnet50_8xb32-cutmix_in1k.py | 9 +++ .../configs/resnet/resnet50_8xb32_in1k.py | 9 +++ 29 files changed, 510 insertions(+) create mode 100644 mmpretrain/configs/_base_/datasets/imagenet_bs64.py create mode 100644 mmpretrain/configs/_base_/models/resnet101.py create mode 100644 mmpretrain/configs/_base_/models/resnet101_cifar.py create mode 100644 mmpretrain/configs/_base_/models/resnet152.py create mode 100644 mmpretrain/configs/_base_/models/resnet152_cifar.py create mode 100644 mmpretrain/configs/_base_/models/resnet18_cifar.py create mode 100644 mmpretrain/configs/_base_/models/resnet34.py create mode 100644 mmpretrain/configs/_base_/models/resnet34_cifar.py create mode 100644 mmpretrain/configs/_base_/models/resnet34_gem.py create mode 100644 mmpretrain/configs/_base_/models/resnet50.py create mode 100644 mmpretrain/configs/_base_/models/resnet50_cifar.py create mode 100644 mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py create mode 100644 mmpretrain/configs/_base_/models/resnet50_cutmix.py create mode 100644 mmpretrain/configs/_base_/schedules/imagenet_bs2048.py create mode 100644 mmpretrain/configs/_base_/schedules/imagenet_bs256_coslr.py create mode 100644 mmpretrain/configs/resnet/resnet101_8xb16_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet101_8xb32_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet152_8xb16_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet152_8xb32_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet34_8xb32_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet50_32xb64-warmup_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb16-mixup_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb16_cifar10.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb32-coslr-preciseBN_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb32-coslr_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb32-cutmix_in1k.py create mode 100644 mmpretrain/configs/resnet/resnet50_8xb32_in1k.py diff --git a/mmpretrain/configs/_base_/datasets/imagenet_bs64.py b/mmpretrain/configs/_base_/datasets/imagenet_bs64.py new file mode 100644 index 00000000000..2284b162815 --- /dev/null +++ b/mmpretrain/configs/_base_/datasets/imagenet_bs64.py @@ -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 diff --git a/mmpretrain/configs/_base_/models/resnet101.py b/mmpretrain/configs/_base_/models/resnet101.py new file mode 100644 index 00000000000..ca37353b348 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet101.py @@ -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, 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), + )) + diff --git a/mmpretrain/configs/_base_/models/resnet101_cifar.py b/mmpretrain/configs/_base_/models/resnet101_cifar.py new file mode 100644 index 00000000000..ab217ec7fe9 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet101_cifar.py @@ -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_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), + )) + diff --git a/mmpretrain/configs/_base_/models/resnet152.py b/mmpretrain/configs/_base_/models/resnet152.py new file mode 100644 index 00000000000..759f6832784 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet152.py @@ -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), + )) diff --git a/mmpretrain/configs/_base_/models/resnet152_cifar.py b/mmpretrain/configs/_base_/models/resnet152_cifar.py new file mode 100644 index 00000000000..1de83e5dc91 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet152_cifar.py @@ -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), + )) diff --git a/mmpretrain/configs/_base_/models/resnet18_cifar.py b/mmpretrain/configs/_base_/models/resnet18_cifar.py new file mode 100644 index 00000000000..62aa4d8c53d --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet18_cifar.py @@ -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), + )) \ No newline at end of file diff --git a/mmpretrain/configs/_base_/models/resnet34.py b/mmpretrain/configs/_base_/models/resnet34.py new file mode 100644 index 00000000000..f563a24c260 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet34.py @@ -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), + )) diff --git a/mmpretrain/configs/_base_/models/resnet34_cifar.py b/mmpretrain/configs/_base_/models/resnet34_cifar.py new file mode 100644 index 00000000000..98b74559de4 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet34_cifar.py @@ -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), + )) \ No newline at end of file diff --git a/mmpretrain/configs/_base_/models/resnet34_gem.py b/mmpretrain/configs/_base_/models/resnet34_gem.py new file mode 100644 index 00000000000..711f36e7a33 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet34_gem.py @@ -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), + )) diff --git a/mmpretrain/configs/_base_/models/resnet50.py b/mmpretrain/configs/_base_/models/resnet50.py new file mode 100644 index 00000000000..1540417cc42 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet50.py @@ -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), + )) \ No newline at end of file diff --git a/mmpretrain/configs/_base_/models/resnet50_cifar.py b/mmpretrain/configs/_base_/models/resnet50_cifar.py new file mode 100644 index 00000000000..8965876453e --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet50_cifar.py @@ -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), + )) diff --git a/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py b/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py new file mode 100644 index 00000000000..2f9df8937ab --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py @@ -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, MultiLabelLinearClsHead, ResNet_CIFAR, Mixup) + +# 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.)), +) diff --git a/mmpretrain/configs/_base_/models/resnet50_cutmix.py b/mmpretrain/configs/_base_/models/resnet50_cutmix.py new file mode 100644 index 00000000000..144eafec585 --- /dev/null +++ b/mmpretrain/configs/_base_/models/resnet50_cutmix.py @@ -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, MultiLabelLinearClsHead, ResNet, CutMix) + +# 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)), +) + diff --git a/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py b/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py new file mode 100644 index 00000000000..49f04583c17 --- /dev/null +++ b/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py @@ -0,0 +1,26 @@ +# Copyright (c) OpenMMLab. All rights reserved. +# This is a BETA new format config file, and the usage may change recently. +from mmengine.optim import MultiStepLR, LinearLR +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) diff --git a/mmpretrain/configs/_base_/schedules/imagenet_bs256_coslr.py b/mmpretrain/configs/_base_/schedules/imagenet_bs256_coslr.py new file mode 100644 index 00000000000..33d31cd0cc0 --- /dev/null +++ b/mmpretrain/configs/_base_/schedules/imagenet_bs256_coslr.py @@ -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) diff --git a/mmpretrain/configs/resnet/resnet101_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet101_8xb16_cifar10.py new file mode 100644 index 00000000000..30e54dc78e3 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet101_8xb16_cifar10.py @@ -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 * diff --git a/mmpretrain/configs/resnet/resnet101_8xb32_in1k.py b/mmpretrain/configs/resnet/resnet101_8xb32_in1k.py new file mode 100644 index 00000000000..bdd0121ef37 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet101_8xb32_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet101 import * + from .._base_.schedules.imagenet_bs256 import * diff --git a/mmpretrain/configs/resnet/resnet152_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet152_8xb16_cifar10.py new file mode 100644 index 00000000000..02c167534dd --- /dev/null +++ b/mmpretrain/configs/resnet/resnet152_8xb16_cifar10.py @@ -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.resnet152_cifar import * + from .._base_.schedules.cifar10_bs128 import * diff --git a/mmpretrain/configs/resnet/resnet152_8xb32_in1k.py b/mmpretrain/configs/resnet/resnet152_8xb32_in1k.py new file mode 100644 index 00000000000..7439eca6385 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet152_8xb32_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet152 import * + from .._base_.schedules.imagenet_bs256 import * diff --git a/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py new file mode 100644 index 00000000000..9fa5627d358 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py @@ -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.resnet18_cifar import * + from .._base_.schedules.cifar10_bs128 import * diff --git a/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py new file mode 100644 index 00000000000..f020567ae97 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py @@ -0,0 +1,10 @@ +# 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.resnet34_cifar import * + from .._base_.schedules.cifar10_bs128 import * + diff --git a/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py b/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py new file mode 100644 index 00000000000..086344f7faa --- /dev/null +++ b/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet34 import * + from .._base_.schedules.imagenet_bs256 import * \ No newline at end of file diff --git a/mmpretrain/configs/resnet/resnet50_32xb64-warmup_in1k.py b/mmpretrain/configs/resnet/resnet50_32xb64-warmup_in1k.py new file mode 100644 index 00000000000..3070d59fb72 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_32xb64-warmup_in1k.py @@ -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.imagenet_bs64 import * + from .._base_.default_runtime import * + from .._base_.models.resnet50 import * + from .._base_.schedules.imagenet_bs2048 import * diff --git a/mmpretrain/configs/resnet/resnet50_8xb16-mixup_cifar10.py b/mmpretrain/configs/resnet/resnet50_8xb16-mixup_cifar10.py new file mode 100644 index 00000000000..43035176c42 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb16-mixup_cifar10.py @@ -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.resnet50_cifar_mixup import * + from .._base_.schedules.cifar10_bs128 import * diff --git a/mmpretrain/configs/resnet/resnet50_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet50_8xb16_cifar10.py new file mode 100644 index 00000000000..6ae2703f36a --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb16_cifar10.py @@ -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.resnet50_cifar import * + from .._base_.schedules.cifar10_bs128 import * diff --git a/mmpretrain/configs/resnet/resnet50_8xb32-coslr-preciseBN_in1k.py b/mmpretrain/configs/resnet/resnet50_8xb32-coslr-preciseBN_in1k.py new file mode 100644 index 00000000000..b84c5c23737 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb32-coslr-preciseBN_in1k.py @@ -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 mmengine.config import read_base + +from mmpretrain.engine import PreciseBNHook + +with read_base(): + from .._base_.datasets.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet50 import * + from .._base_.schedules.imagenet_bs256_coslr import * + +# Precise BN hook will update the bn stats, so this hook should be executed +# before CheckpointHook(priority of 'VERY_LOW') and +# EMAHook(priority of 'NORMAL') So set the priority of PreciseBNHook to +# 'ABOVENORMAL' here. +custom_hooks = [ + dict( + type=PreciseBNHook, + num_samples=8192, + interval=1, + priority='ABOVE_NORMAL') +] diff --git a/mmpretrain/configs/resnet/resnet50_8xb32-coslr_in1k.py b/mmpretrain/configs/resnet/resnet50_8xb32-coslr_in1k.py new file mode 100644 index 00000000000..42f573c46f1 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb32-coslr_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet50 import * + from .._base_.schedules.imagenet_bs256_coslr import * diff --git a/mmpretrain/configs/resnet/resnet50_8xb32-cutmix_in1k.py b/mmpretrain/configs/resnet/resnet50_8xb32-cutmix_in1k.py new file mode 100644 index 00000000000..d1c7addc70b --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb32-cutmix_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet50_cutmix import * + from .._base_.schedules.imagenet_bs256 import * diff --git a/mmpretrain/configs/resnet/resnet50_8xb32_in1k.py b/mmpretrain/configs/resnet/resnet50_8xb32_in1k.py new file mode 100644 index 00000000000..75297f14ac4 --- /dev/null +++ b/mmpretrain/configs/resnet/resnet50_8xb32_in1k.py @@ -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.imagenet_bs32 import * + from .._base_.default_runtime import * + from .._base_.models.resnet50 import * + from .._base_.schedules.imagenet_bs256 import * From bbeca7aecb073239b86e1d2441fe33a2fe8535c0 Mon Sep 17 00:00:00 2001 From: "zhenxiong.duan1109" Date: Mon, 30 Oct 2023 16:00:55 +0800 Subject: [PATCH 2/4] new version of config adapts ResNet --- mmpretrain/configs/_base_/models/resnet101.py | 1 - mmpretrain/configs/_base_/models/resnet101_cifar.py | 1 - mmpretrain/configs/_base_/models/resnet18_cifar.py | 2 +- mmpretrain/configs/_base_/models/resnet34_cifar.py | 2 +- mmpretrain/configs/_base_/models/resnet50.py | 2 +- .../configs/_base_/models/resnet50_cifar_mixup.py | 5 +++-- mmpretrain/configs/_base_/models/resnet50_cutmix.py | 11 ++++++----- mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py | 1 - mmpretrain/configs/resnet/resnet34_8xb32_in1k.py | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mmpretrain/configs/_base_/models/resnet101.py b/mmpretrain/configs/_base_/models/resnet101.py index ca37353b348..c0517e3901e 100644 --- a/mmpretrain/configs/_base_/models/resnet101.py +++ b/mmpretrain/configs/_base_/models/resnet101.py @@ -20,4 +20,3 @@ loss=dict(type=CrossEntropyLoss, loss_weight=1.0), topk=(1, 5), )) - diff --git a/mmpretrain/configs/_base_/models/resnet101_cifar.py b/mmpretrain/configs/_base_/models/resnet101_cifar.py index ab217ec7fe9..6b5f9502477 100644 --- a/mmpretrain/configs/_base_/models/resnet101_cifar.py +++ b/mmpretrain/configs/_base_/models/resnet101_cifar.py @@ -19,4 +19,3 @@ in_channels=2048, loss=dict(type=CrossEntropyLoss, loss_weight=1.0), )) - diff --git a/mmpretrain/configs/_base_/models/resnet18_cifar.py b/mmpretrain/configs/_base_/models/resnet18_cifar.py index 62aa4d8c53d..0adba896d7f 100644 --- a/mmpretrain/configs/_base_/models/resnet18_cifar.py +++ b/mmpretrain/configs/_base_/models/resnet18_cifar.py @@ -18,4 +18,4 @@ num_classes=10, in_channels=512, loss=dict(type=CrossEntropyLoss, loss_weight=1.0), - )) \ No newline at end of file + )) diff --git a/mmpretrain/configs/_base_/models/resnet34_cifar.py b/mmpretrain/configs/_base_/models/resnet34_cifar.py index 98b74559de4..d86a7ae6db3 100644 --- a/mmpretrain/configs/_base_/models/resnet34_cifar.py +++ b/mmpretrain/configs/_base_/models/resnet34_cifar.py @@ -18,4 +18,4 @@ num_classes=10, in_channels=512, loss=dict(type=CrossEntropyLoss, loss_weight=1.0), - )) \ No newline at end of file + )) diff --git a/mmpretrain/configs/_base_/models/resnet50.py b/mmpretrain/configs/_base_/models/resnet50.py index 1540417cc42..7ca56c69bc3 100644 --- a/mmpretrain/configs/_base_/models/resnet50.py +++ b/mmpretrain/configs/_base_/models/resnet50.py @@ -19,4 +19,4 @@ in_channels=2048, loss=dict(type=CrossEntropyLoss, loss_weight=1.0), topk=(1, 5), - )) \ No newline at end of file + )) diff --git a/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py b/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py index 2f9df8937ab..6de7530060e 100644 --- a/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py +++ b/mmpretrain/configs/_base_/models/resnet50_cifar_mixup.py @@ -1,7 +1,8 @@ # 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, MultiLabelLinearClsHead, ResNet_CIFAR, Mixup) + ImageClassifier, Mixup, MultiLabelLinearClsHead, + ResNet_CIFAR) # model settings model = dict( @@ -10,7 +11,7 @@ type=ResNet_CIFAR, depth=50, num_stages=4, - out_indices=(3,), + out_indices=(3, ), style='pytorch'), neck=dict(type=GlobalAveragePooling), head=dict( diff --git a/mmpretrain/configs/_base_/models/resnet50_cutmix.py b/mmpretrain/configs/_base_/models/resnet50_cutmix.py index 144eafec585..eea990cf58e 100644 --- a/mmpretrain/configs/_base_/models/resnet50_cutmix.py +++ b/mmpretrain/configs/_base_/models/resnet50_cutmix.py @@ -1,7 +1,8 @@ # 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, MultiLabelLinearClsHead, ResNet, CutMix) +from mmpretrain.models import (CrossEntropyLoss, CutMix, GlobalAveragePooling, + ImageClassifier, MultiLabelLinearClsHead, + ResNet) # model settings model = dict( @@ -10,7 +11,7 @@ type=ResNet, depth=50, num_stages=4, - out_indices=(3,), + out_indices=(3, ), style='pytorch'), neck=dict(type=GlobalAveragePooling), head=dict( @@ -18,6 +19,6 @@ 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)), + train_cfg=dict( + augments=dict(type=CutMix, alpha=1.0, num_classes=1000, prob=1.0)), ) - diff --git a/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py b/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py index f020567ae97..e11f178e5a9 100644 --- a/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py +++ b/mmpretrain/configs/resnet/resnet34_8xb16_cifar10.py @@ -7,4 +7,3 @@ from .._base_.default_runtime import * from .._base_.models.resnet34_cifar import * from .._base_.schedules.cifar10_bs128 import * - diff --git a/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py b/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py index 086344f7faa..d15a957fc9a 100644 --- a/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py +++ b/mmpretrain/configs/resnet/resnet34_8xb32_in1k.py @@ -6,4 +6,4 @@ from .._base_.datasets.imagenet_bs32 import * from .._base_.default_runtime import * from .._base_.models.resnet34 import * - from .._base_.schedules.imagenet_bs256 import * \ No newline at end of file + from .._base_.schedules.imagenet_bs256 import * From ed8800288717e745825868b48decd5a6fae88347 Mon Sep 17 00:00:00 2001 From: "zhenxiong.duan1109" Date: Mon, 30 Oct 2023 16:44:48 +0800 Subject: [PATCH 3/4] new version of config adapts ResNet --- .../_base_/schedules/imagenet_bs2048.py | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 mmpretrain/configs/_base_/schedules/imagenet_bs2048.py diff --git a/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py b/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py deleted file mode 100644 index 49f04583c17..00000000000 --- a/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) OpenMMLab. All rights reserved. -# This is a BETA new format config file, and the usage may change recently. -from mmengine.optim import MultiStepLR, LinearLR -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) From a7f576de4602fe7d0b46c46924eacc81dd49b93f Mon Sep 17 00:00:00 2001 From: "zhenxiong.duan1109" Date: Mon, 30 Oct 2023 16:52:07 +0800 Subject: [PATCH 4/4] new version of config adapts ResNet --- .../_base_/schedules/imagenet_bs2048.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 mmpretrain/configs/_base_/schedules/imagenet_bs2048.py diff --git a/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py b/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py new file mode 100644 index 00000000000..cecf46b797e --- /dev/null +++ b/mmpretrain/configs/_base_/schedules/imagenet_bs2048.py @@ -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)