OpenMMLab(1)配置文件

文件列表

configs 配置文件

resnet18_8xb16_cifar10

18层   8卡   b16:batch(8×16)  cifar10:数据集    mixup:数据增强   coslr:学习率衰减

_base__  网络结构models、数据集定义datasets、学习策略schedules、常规训练方式

config--_base_--models--resnet18.py    网络模型

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    提特征

  • depth:层数
  • num_stages:经过多少个stage
  • out_indices:输出哪个层,可以多个层  (3--第三层  [0, 1, 2, 3])
  • style:pytorch--3×3卷积 步长s=2  caffe--1×1卷积 s=2

neck:融合策略  GlobalAveragePooling大小相等

  • head:输出
  • type:分类任务,使用FC全连接
  • num_classes:分类数量,自行修改
  • in_channels:根据neck
  • loss:损失    mmcls--models--losses中自行选择
  • topk:评估标准,top1的准确率,top5的准确率

configs--_base_--datasets--imagenet_bs32.py    数据集加载及dataload处理

# 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:标准化,均值、标准差  x-μ/σ

train_pipeline、test_pipeline:数据预处理

type:是调用mmcls中的--datasets--pipelines中的方法

  • dict(type='LoadImageFromFile'),    读图像数据,方法在dataset_type中有
  • 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']),  转化为Tensor
  • dict(type='ToTensor', keys=['gt_label']),  标签转为Tensor
  • dict(type='Collect', keys=['img', 'gt_label'])  返回图像和标签

data = dict(
    samples_per_gpu=32,  单卡的batchsize,或多卡每个卡的batchsize
    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')  评估,interval经过1epoch后走验证集,metric要打印哪些指标

configs--_base_--schedules--imagenet_bs256.py    优化器和迭代次数

# 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:优化器  学习率 动量 学习率衰减

lr_config:迭代30、60、90次衰减

runner:最终迭代多少次

configs--_base_--default_runtime    日志

# 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:多少个后进行保存

log_config:保存日志,迭代多少次保存信息

你可能感兴趣的:(深度学习,Pytorch,python,深度学习,python)