总的来说,是跟pytorch相似的,只不过一些成熟且不会老是更改的东西,封装了起来,直接使用字典即可配置
model = dict( type='ImageClassifier', backbone=dict( type='ResNet', depth=18, num_stages=4, out_indices=(3, ), style='pytorch'), neck=dict(type='GeneralizedMeanPooling'), head=dict( type='LinearClsHead', num_classes=102, in_channels=512, loss=dict(type='FocalLoss', loss_weight=1.0),#L1Loss CrossEntropyLoss topk=(1, 5)), train_cfg=dict( augments=dict(type='BatchMixup', alpha=0.2, num_classes=102, prob=1.)) ) 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='ColorJitter', brightness=0.5, contrast=0.5, saturation=0.5), dict( type='Normalize', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), 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', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ] data = dict( samples_per_gpu=32, workers_per_gpu=2, train=dict( type='MyFilelist', data_prefix='C:/Users/sci/Desktop/mmclassification-master/mmcls/data/flower_data/train_filelist', ann_file='C:/Users/sci/Desktop/mmclassification-master/mmcls/data/flower_data/train.txt', pipeline=[ dict(type='LoadImageFromFile'), dict(type='RandomResizedCrop', size=224), dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'), dict( type='Normalize', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), dict(type='ImageToTensor', keys=['img']), dict(type='ToTensor', keys=['gt_label']), dict(type='Collect', keys=['img', 'gt_label']) ]), val=dict( type='ImageNet', data_prefix='../mmcls/data/flower_data/val_filelist', ann_file='../mmcls/data/flower_data/val.txt', pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', size=(256, -1)), dict(type='CenterCrop', crop_size=224), dict( type='Normalize', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ]), test=dict( type='ImageNet', data_prefix='../mmcls/data/flower_data/val_filelist', ann_file='../mmcls/data/flower_data/val.txt', pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', size=(256, -1)), dict(type='CenterCrop', crop_size=224), dict( type='Normalize', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ])) evaluation = dict(interval=10, metric='accuracy') optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001) optimizer_config = dict(grad_clip=None) lr_config = dict(policy='step', step=[30, 60, 90]) runner = dict(type='EpochBasedRunner', max_epochs=100) checkpoint_config = dict(interval=50) log_config = dict(interval=100, hooks=[dict(type='TextLoggerHook')]) dist_params = dict(backend='nccl') log_level = 'INFO' load_from = '../mmcls/data/resnet18_8xb32_in1k_20210831-fbbb1da6.pth' resume_from = None workflow = [('train', 1)] work_dir = './work_dirs/resnet18_8xb32_in1k' gpu_ids = [0]
上面是此次实验的代码,属于model部分,然后使用train.py进行训练就行
总结,很适合新手,后期会进行模型修改,在后面的分享