Skip to content

Commit

Permalink
configs: update classification config files
Browse files Browse the repository at this point in the history
  • Loading branch information
mjq2020 committed Aug 16, 2023
1 parent 6c3414c commit 1c3933c
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 69 deletions.
2 changes: 1 addition & 1 deletion configs/_base_/default_runtime_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# set visualizer
vis_backends = [dict(type='LocalVisBackend')]
# visualizer = dict(type='mmcls.UniversalVisualizer', vis_backends=vis_backends)
visualizer = dict(type='mmcls.ClsVisualizer', vis_backends=vis_backends)

# set log level
log_level = 'INFO'
Expand Down
18 changes: 10 additions & 8 deletions configs/classification/mobnetv2_0.35_rep_1bx16_300e_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,34 @@
data_root = 'datasets'
height = 32
width = 32
batch_size = 16
workers = 1
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 300
epochs = 100


model = dict(
type='edgelab.ImageClassifier',
backbone=dict(type='MobileNetv2', widen_factor=0.35, out_indices=(2,), rep=True),
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0]),
backbone=dict(type='MobileNetv2', gray_input=False, widen_factor=0.35, out_indices=(2,), rep=True),
neck=dict(type='mmcls.GlobalAveragePooling'),
head=dict(
type='mmcls.LinearClsHead',
in_channels=16,
in_channels=32,
num_classes=num_classes,
loss=dict(type='mmcls.CrossEntropyLoss', loss_weight=1.0),
topk=(1, 5),
),
)

train_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.ColorJitter', brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

Expand Down Expand Up @@ -93,12 +95,12 @@
type='MultiStepLR',
begin=1,
end=500,
milestones=[100, 200, 250],
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs)
train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
14 changes: 8 additions & 6 deletions configs/classification/mobnetv2_0.35_rep_1bx16_300e_cifar100.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
data_root = 'datasets'
height = 32
width = 32
batch_size = 16
workers = 1
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 300
epochs = 100


model = dict(
type='edgelab.ImageClassifier',
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0]),
backbone=dict(type='MobileNetv2', widen_factor=0.35, out_indices=(2,), rep=True),
neck=dict(type='mmcls.GlobalAveragePooling'),
head=dict(
Expand All @@ -33,9 +34,10 @@
)

train_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.ColorJitter', brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

Expand Down Expand Up @@ -93,12 +95,12 @@
type='MultiStepLR',
begin=1,
end=500,
milestones=[100, 200, 250],
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs)
train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
21 changes: 8 additions & 13 deletions configs/classification/mobnetv2_0.35_rep_1bx16_300e_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@
data_root = 'datasets/digit'
height = 96
width = 96
batch_size = 16
workers = 1
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 300
epochs = 100

data_preprocessor = dict(
type='mmcls.ClsDataPreprocessor',
mean=[0, 0, 0],
std=[255.0, 255.0, 255.0],
to_rgb=True,
)

model = dict(
type='edgelab.ImageClassifier',
data_preprocessor=data_preprocessor,
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0]),
backbone=dict(type='MobileNetv2', widen_factor=0.35, out_indices=(2,), rep=True),
neck=dict(type='mmcls.GlobalAveragePooling', dim=2),
head=dict(
Expand All @@ -42,9 +36,10 @@

train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.ColorJitter', brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

Expand Down Expand Up @@ -100,12 +95,12 @@
type='MultiStepLR',
begin=1,
end=500,
milestones=[100, 200, 250],
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs)
train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
106 changes: 106 additions & 0 deletions configs/classification/mobnetv2_0.35_rep_1bx16_300e_mnist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
_base_ = '../_base_/default_runtime_cls.py'
default_scope = 'edgelab'
custom_imports = dict(imports=['edgelab'], allow_failed_imports=False)

# model settings
num_classes = 10
gray = True

# dataset settings
dataset_type = 'mmcls.MNIST'
data_root = 'datasets'
height = 32
width = 32
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 100


model = dict(
type='edgelab.ImageClassifier',
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0], std=[255.0]),
backbone=dict(type='MobileNetv2', gray_input=gray, widen_factor=0.35, out_indices=(2,), rep=True),
neck=dict(type='mmcls.GlobalAveragePooling'),
head=dict(
type='mmcls.LinearClsHead',
in_channels=32,
num_classes=num_classes,
loss=dict(type='mmcls.CrossEntropyLoss', loss_weight=1.0),
topk=(1, 5),
),
)

train_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmcls.PackClsInputs'),
]

test_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

train_dataloader = dict(
# Training dataset configurations
batch_size=batch_size,
num_workers=workers,
persistent_workers=persistent_workers,
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix='cifar10/',
test_mode=False,
pipeline=train_pipeline,
),
sampler=dict(type='DefaultSampler', shuffle=True),
)

val_dataloader = dict(
batch_size=batch_size,
num_workers=workers,
persistent_workers=persistent_workers,
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix='cifar10/',
test_mode=True,
pipeline=test_pipeline,
),
sampler=dict(type='DefaultSampler', shuffle=False),
)

test_dataloader = val_dataloader

# evaluator
val_evaluator = dict(type='mmcls.Accuracy', topk=(1, 5))
test_evaluator = val_evaluator


val_cfg = dict()
test_cfg = dict()

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

# learning policy
param_scheduler = [
dict(type='LinearLR', begin=0, end=30, start_factor=0.001, by_epoch=False), # warm-up
dict(
type='MultiStepLR',
begin=1,
end=500,
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
14 changes: 8 additions & 6 deletions configs/classification/mobnetv2_1.0_1bx16_300e_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
data_root = 'datasets'
height = 32
width = 32
batch_size = 16
workers = 1
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 300
epochs = 100

model = dict(
type='edgelab.ImageClassifier',
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0]),
backbone=dict(type='mmcls.MobileNetV2', widen_factor=1.0),
neck=dict(type='mmcls.GlobalAveragePooling'),
head=dict(
Expand All @@ -32,9 +33,10 @@
)

train_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.ColorJitter', brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

Expand Down Expand Up @@ -91,12 +93,12 @@
type='MultiStepLR',
begin=1,
end=500,
milestones=[100, 200, 250],
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs)
train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
14 changes: 8 additions & 6 deletions configs/classification/mobnetv2_1.0_1bx16_300e_cifar100.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
data_root = 'datasets'
height = 32
width = 32
batch_size = 16
workers = 1
batch_size = 32
workers = 8
persistent_workers = True

# optimizer
lr = 0.01
epochs = 300
epochs = 100

model = dict(
type='edgelab.ImageClassifier',
data_preprocessor=dict(type='mmdet.DetDataPreprocessor', mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0]),
backbone=dict(type='mmcls.MobileNetV2', widen_factor=1.0),
neck=dict(type='mmcls.GlobalAveragePooling'),
head=dict(
Expand All @@ -32,9 +33,10 @@
)

train_pipeline = [
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.ColorJitter', brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
dict(type='mmcls.Rotate', angle=30.0, prob=0.6),
dict(type='mmcls.RandomFlip', prob=0.5, direction='horizontal'),
dict(type='mmengine.Resize', scale=(height, width)),
dict(type='mmcls.PackClsInputs'),
]

Expand Down Expand Up @@ -91,12 +93,12 @@
type='MultiStepLR',
begin=1,
end=500,
milestones=[100, 200, 250],
milestones=[30, 60, 90],
gamma=0.1,
by_epoch=True,
),
]

auto_scale_lr = dict(base_batch_size=batch_size)

train_cfg = dict(by_epoch=True, max_epochs=epochs)
train_cfg = dict(by_epoch=True, max_epochs=epochs, val_interval=5)
Loading

0 comments on commit 1c3933c

Please sign in to comment.