File List
configs configuration file
resnet18_8xb16_cifar10
18 layers, 8 cards b16: batch (8×16) cifar10: dataset mixup: data enhancement coslr: learning rate decay
_base__ Network structure models, dataset definition datasets, learning strategy schedules, conventional training methods
config--_base_--models--resnet18.py network model
model = dict(
type='ImageClassifier',
backbone=dict(
type='ResNet',
depth=18,
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),
))
type:mmcls--models--classifiers--image.py--ImageClassifier(forward train)
backbone: mmcls--models--backbones--resnet.py feature extraction
- depth: the number of layers
- num_stages: how many stages have passed
- out_indices: Which layer to output, can be multiple layers (3--the third layer [0, 1, 2, 3])
- style: pytorch--3×3 convolution step size s=2 caffe--1×1 convolution s=2
neck: fusion strategy GlobalAveragePooling equal in size
- head: output
- type: classification task, using FC full connection
- num_classes: number of categories, modify by yourself
- in_channels: according to the neck
- loss: loss mmcls--models--losses to choose by yourself
- topk: evaluation criteria, top1 accuracy, top5 accuracy
configs--_base_--datasets--imagenet_bs32.py data set loading and dataload processing
# 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),
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=32,
workers_per_gpu=2,
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=1, metric='accuracy')
dataset_type:mmcls--datasets--imagenet.py
img_norm_cfg: normalization, mean, standard deviation x-μ/σ
train_pipeline, test_pipeline: data preprocessing
type: is to call the method in --datasets--pipelines in mmcls
- dict(type='LoadImageFromFile'), read image data, the method is in dataset_type
- dict(type='RandomResizedCrop', size=224), random size cropping
- dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'), 翻转
- dict(type='Normalize', **img_norm_cfg), normalized
- dict(type='ImageToTensor', keys=['img']), convert to Tensor
- dict(type='ToTensor', keys=['gt_label']), the label is converted to Tensor
- dict(type='Collect', keys=['img', 'gt_label']) returns images and labels
data = dict(
samples_per_gpu=32, the batchsize of a single card, or the batchsize of each card for multiple cards
workers_per_gpu=2,
train=dict( training set
type=dataset_type,
data_prefix='data/imagenet/train', read path, no Specify the label, use the label folder as the label
pipeline=train_pipeline),
val=dict( validation set
type=dataset_type,
data_prefix='data/imagenet/val',
ann_file='data/imagenet/meta/val.txt', specify the label File path name, then use the label in the file
pipeline=test_pipeline),
test=dict( test set
# 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=1, metric='accuracy') evaluation, the interval goes through the validation set after 1epoch, which metrics should be printed by the metric
configs--_base_--schedules--imagenet_bs256.py optimizer and number of iterations
# optimizer
optimizer = dict(type='SGD', lr=0.1, momentum=0.9, weight_decay=0.0001)
optimizer_config = dict(grad_clip=None)
# learning policy
lr_config = dict(policy='step', step=[30, 60, 90])
runner = dict(type='EpochBasedRunner', max_epochs=100)
optimizer: optimizer learning rate momentum learning rate decay
lr_config: iterate 30, 60, 90 decays
runner: how many final iterations
configs--_base_--default_runtime log
# checkpoint saving
checkpoint_config = dict(interval=1)
# yapf:disable
log_config = dict(
interval=100,
hooks=[
dict(type='TextLoggerHook'),
# dict(type='TensorboardLoggerHook')
])
# yapf:enable
dist_params = dict(backend='nccl')
log_level = 'INFO'
load_from = None
resume_from = None
workflow = [('train', 1)]
checkpoint_config: save after how many
log_config: save the log, how many iterations to save the information