-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[CodeCamp2023-340] New Version of config Adapting MobileNet Algorithm #1774
Merged
fangyixiao18
merged 3 commits into
open-mmlab:main
from
DE009:DE009/new_config_mobilenet
Sep 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,52 @@ | ||
# 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 CIFAR10, PackInputs, RandomCrop, RandomFlip | ||
from mmpretrain.evaluation import Accuracy | ||
|
||
# dataset settings | ||
dataset_type = CIFAR10 | ||
data_preprocessor = dict( | ||
num_classes=10, | ||
# RGB format normalization parameters | ||
mean=[125.307, 122.961, 113.8575], | ||
std=[51.5865, 50.847, 51.255], | ||
# loaded images are already RGB format | ||
to_rgb=False) | ||
|
||
train_pipeline = [ | ||
dict(type=RandomCrop, crop_size=32, padding=4), | ||
dict(type=RandomFlip, prob=0.5, direction='horizontal'), | ||
dict(type=PackInputs), | ||
] | ||
|
||
test_pipeline = [ | ||
dict(type=PackInputs), | ||
] | ||
|
||
train_dataloader = dict( | ||
batch_size=16, | ||
num_workers=2, | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root='data/cifar10', | ||
split='train', | ||
pipeline=train_pipeline), | ||
sampler=dict(type=DefaultSampler, shuffle=True), | ||
) | ||
|
||
val_dataloader = dict( | ||
batch_size=16, | ||
num_workers=2, | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root='data/cifar10/', | ||
split='test', | ||
pipeline=test_pipeline), | ||
sampler=dict(type=DefaultSampler, shuffle=False), | ||
) | ||
val_evaluator = dict(type=Accuracy, topk=(1, )) | ||
|
||
test_dataloader = val_dataloader | ||
test_evaluator = val_evaluator |
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,75 @@ | ||
# 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 (AutoAugment, CenterCrop, ImageNet, | ||
LoadImageFromFile, PackInputs, RandomErasing, | ||
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, | ||
) | ||
|
||
bgr_mean = data_preprocessor['mean'][::-1] | ||
bgr_std = data_preprocessor['std'][::-1] | ||
|
||
train_pipeline = [ | ||
dict(type=LoadImageFromFile), | ||
dict(type=RandomResizedCrop, scale=224, backend='pillow'), | ||
dict(type=RandomFlip, prob=0.5, direction='horizontal'), | ||
dict( | ||
type=AutoAugment, | ||
policies='imagenet', | ||
hparams=dict(pad_val=[round(x) for x in bgr_mean])), | ||
dict( | ||
type=RandomErasing, | ||
erase_prob=0.2, | ||
mode='rand', | ||
min_area_ratio=0.02, | ||
max_area_ratio=1 / 3, | ||
fill_color=bgr_mean, | ||
fill_std=bgr_std), | ||
dict(type=PackInputs), | ||
] | ||
|
||
test_pipeline = [ | ||
dict(type=LoadImageFromFile), | ||
dict(type=ResizeEdge, scale=256, edge='short', backend='pillow'), | ||
dict(type=CenterCrop, crop_size=224), | ||
dict(type=PackInputs), | ||
] | ||
|
||
train_dataloader = dict( | ||
batch_size=128, | ||
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=128, | ||
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 |
60 changes: 60 additions & 0 deletions
60
mmpretrain/configs/_base_/datasets/imagenet_bs32_pil_resize.py
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,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, backend='pillow'), | ||
dict(type=RandomFlip, prob=0.5, direction='horizontal'), | ||
dict(type=PackInputs), | ||
] | ||
|
||
test_pipeline = [ | ||
dict(type=LoadImageFromFile), | ||
dict(type=ResizeEdge, scale=256, edge='short', backend='pillow'), | ||
dict(type=CenterCrop, crop_size=224), | ||
dict(type=PackInputs), | ||
] | ||
|
||
train_dataloader = dict( | ||
batch_size=32, | ||
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=32, | ||
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 |
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,17 @@ | ||
# 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, MobileNetV2) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV2, widen_factor=1.0), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=LinearClsHead, | ||
num_classes=1000, | ||
in_channels=1280, | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
topk=(1, 5), | ||
)) |
25 changes: 25 additions & 0 deletions
25
mmpretrain/configs/_base_/models/mobilenet_v3/mobilenet_v3_large_imagenet.py
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,25 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from mmengine.model.weight_init import NormalInit | ||
from torch.nn.modules.activation import Hardswish | ||
|
||
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling, | ||
ImageClassifier, MobileNetV3, | ||
StackedLinearClsHead) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV3, arch='large'), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=StackedLinearClsHead, | ||
num_classes=1000, | ||
in_channels=960, | ||
mid_channels=[1280], | ||
dropout_rate=0.2, | ||
act_cfg=dict(type=Hardswish), | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
init_cfg=dict( | ||
type=NormalInit, layer='Linear', mean=0., std=0.01, bias=0.), | ||
topk=(1, 5))) |
25 changes: 25 additions & 0 deletions
25
mmpretrain/configs/_base_/models/mobilenet_v3/mobilenet_v3_small_050_imagenet.py
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,25 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from mmengine.model.weight_init import NormalInit | ||
from torch.nn.modules.activation import Hardswish | ||
|
||
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling, | ||
ImageClassifier, MobileNetV3, | ||
StackedLinearClsHead) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV3, arch='small_050'), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=StackedLinearClsHead, | ||
num_classes=1000, | ||
in_channels=288, | ||
mid_channels=[1024], | ||
dropout_rate=0.2, | ||
act_cfg=dict(type=Hardswish), | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
init_cfg=dict( | ||
type=NormalInit, layer='Linear', mean=0., std=0.01, bias=0.), | ||
topk=(1, 5))) |
25 changes: 25 additions & 0 deletions
25
mmpretrain/configs/_base_/models/mobilenet_v3/mobilenet_v3_small_075_imagenet.py
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,25 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from mmengine.model.weight_init import NormalInit | ||
from torch.nn.modules.activation import Hardswish | ||
|
||
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling, | ||
ImageClassifier, MobileNetV3, | ||
StackedLinearClsHead) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV3, arch='small_075'), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=StackedLinearClsHead, | ||
num_classes=1000, | ||
in_channels=432, | ||
mid_channels=[1024], | ||
dropout_rate=0.2, | ||
act_cfg=dict(type=Hardswish), | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
init_cfg=dict( | ||
type=NormalInit, layer='Linear', mean=0., std=0.01, bias=0.), | ||
topk=(1, 5))) |
21 changes: 21 additions & 0 deletions
21
mmpretrain/configs/_base_/models/mobilenet_v3/mobilenet_v3_small_cifar.py
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,21 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from torch.nn.modules.activation import Hardswish | ||
|
||
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling, | ||
ImageClassifier, MobileNetV3, | ||
StackedLinearClsHead) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV3, arch='small'), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=StackedLinearClsHead, | ||
num_classes=10, | ||
in_channels=576, | ||
mid_channels=[1280], | ||
act_cfg=dict(type=Hardswish), | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
topk=(1, 5))) |
25 changes: 25 additions & 0 deletions
25
mmpretrain/configs/_base_/models/mobilenet_v3/mobilenet_v3_small_imagenet.py
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,25 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from mmengine.model.weight_init import NormalInit | ||
from torch.nn.modules.activation import Hardswish | ||
|
||
from mmpretrain.models import (CrossEntropyLoss, GlobalAveragePooling, | ||
ImageClassifier, MobileNetV3, | ||
StackedLinearClsHead) | ||
|
||
# model settings | ||
model = dict( | ||
type=ImageClassifier, | ||
backbone=dict(type=MobileNetV3, arch='small'), | ||
neck=dict(type=GlobalAveragePooling), | ||
head=dict( | ||
type=StackedLinearClsHead, | ||
num_classes=1000, | ||
in_channels=576, | ||
mid_channels=[1024], | ||
dropout_rate=0.2, | ||
act_cfg=dict(type=Hardswish), | ||
loss=dict(type=CrossEntropyLoss, loss_weight=1.0), | ||
init_cfg=dict( | ||
type=NormalInit, layer='Linear', mean=0., std=0.01, bias=0.), | ||
topk=(1, 5))) |
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,20 @@ | ||
# 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 | ||
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=MultiStepLR, by_epoch=True, milestones=[100, 150], gamma=0.1) | ||
|
||
# train, val, test setting | ||
train_cfg = dict(by_epoch=True, max_epochs=200, 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=128) |
20 changes: 20 additions & 0 deletions
20
mmpretrain/configs/_base_/schedules/imagenet_bs256_epochstep.py
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,20 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
# This is a BETA new format config file, and the usage may change recently. | ||
from mmengine.optim import StepLR | ||
from torch.optim import SGD | ||
|
||
# optimizer | ||
optim_wrapper = dict( | ||
optimizer=dict(type=SGD, lr=0.045, momentum=0.9, weight_decay=0.00004)) | ||
|
||
# learning policy | ||
param_scheduler = dict(type=StepLR, by_epoch=True, step_size=1, gamma=0.98) | ||
|
||
# train, val, test setting | ||
train_cfg = dict(by_epoch=True, max_epochs=300, 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) |
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,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_pil_resize import * | ||
from .._base_.default_runtime import * | ||
from .._base_.models.mobilenet_v2_1x import * | ||
from .._base_.schedules.imagenet_bs256_epochstep import * |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the folder
_base_/models/mobilenet_v3
, but only keep one file to set model config likemobilenet_v3_small.py
, and the training configs of mobile net v3 all inherit from thismobilenet_v3_small.py
fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can refer to
mmpretrain/configs/vision_transformer
, to find some examplesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the folder
_base_/models/mobilenet_v3
add base model config file
mobilenet_v3_small.py
in_base_/models/
modified all training configs of mobile net v3 in folder
mmpretrain/configs/mobilenet_v3/
to inheri the base model configmobilenet_v3_small.py