# Migration from MMClassification 0.x We introduce some modifications in MMClassification 1.x, and some of them are BC-breading. To migrate your projects from MMClassification 0.x smoothly, please read this tutorial. ## New dependencies MMClassification 1.x depends on some new packages, you can prepare a new clean environment and install again according to the [install tutorial](./get_started.md). Or install the below packages manually. 1. [MMEngine](https://github.com/open-mmlab/mmengine): MMEngine is the core the OpenMMLab 2.0 architecture, and we splited many compentents unrelated to computer vision from MMCV to MMEngine. 2. [MMCV](https://github.com/open-mmlab/mmcv): The computer vision package of OpenMMLab. This is not a new dependency, but you need to upgrade it to above `2.0.0rc1` version. 3. [rich](https://github.com/Textualize/rich): A terminal formatting package, and we use it to beautify some outputs in the terminal. ## Configuration files In MMClassification 1.x, we refactored the structure of configuration files, and the original files are not usable. In this section, we will introduce all changes of the configuration files. And we assume you already have ideas of the [config files](./user_guides/config.md). ### Model settings No changes in `model.backbone`, `model.neck` and `model.head` fields. Changes in **`model.train_cfg`**: - `BatchMixup` is renamed to [`Mixup`](mmpretrain.models.utils.batch_augments.Mixup). - `BatchCutMix` is renamed to [`CutMix`](mmpretrain.models.utils.batch_augments.CutMix). - `BatchResizeMix` is renamed to [`ResizeMix`](mmpretrain.models.utils.batch_augments.ResizeMix). - The `prob` argument is removed from all augments settings, and you can use the `probs` field in `train_cfg` to specify probabilities of every augemnts. If no `probs` field, randomly choose one by the same probability.
Original | ```python model = dict( ... train_cfg=dict(augments=[ dict(type='BatchMixup', alpha=0.8, num_classes=1000, prob=0.5), dict(type='BatchCutMix', alpha=1.0, num_classes=1000, prob=0.5) ] ) ``` |
New | ```python model = dict( ... train_cfg=dict(augments=[ dict(type='Mixup', alpha=0.8), dict(type='CutMix', alpha=1.0)] ) ``` |
Original | ```python data = dict( samples_per_gpu=32, workers_per_gpu=2, train=dict(...), val=dict(...), test=dict(...), ) ``` |
New | ```python train_dataloader = dict( batch_size=32, num_workers=2, dataset=dict(...), sampler=dict(type='DefaultSampler', shuffle=True) # necessary ) val_dataloader = dict( batch_size=32, num_workers=2, dataset=dict(...), sampler=dict(type='DefaultSampler', shuffle=False) # necessary ) test_dataloader = val_dataloader ``` |
Original | ```python 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']) ] ``` |
New | ```python data_preprocessor = 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', scale=224), dict(type='RandomFlip', prob=0.5, direction='horizontal'), dict(type='PackInputs'), ] ``` |
Original | ```python evaluation = dict( interval=1, metric='accuracy', metric_options=dict(topk=(1, 5)) ) ``` |
New | ```python val_evaluator = dict(type='Accuracy', topk=(1, 5)) test_evaluator = val_evaluator ``` |
Original | ```python evaluation = dict( interval=1, metric=['mAP', 'CP', 'OP', 'CR', 'OR', 'CF1', 'OF1'], metric_options=dict(thr=0.5), ) ``` |
New | ```python val_evaluator = [ dict(type='AveragePrecision'), dict(type='MultiLabelMetric', items=['precision', 'recall', 'f1-score'], average='both', thr=0.5), ] test_evaluator = val_evaluator ``` |
Original | ```python optimizer = dict( type='AdamW', lr=0.0015, weight_decay=0.3, paramwise_cfg = dict( norm_decay_mult=0.0, bias_decay_mult=0.0, )) optimizer_config = dict(grad_clip=dict(max_norm=1.0)) ``` |
New | ```python optim_wrapper = dict( optimizer=dict(type='AdamW', lr=0.0015, weight_decay=0.3), paramwise_cfg = dict( norm_decay_mult=0.0, bias_decay_mult=0.0, ), clip_grad=dict(max_norm=1.0), ) ``` |
Original | ```python lr_config = dict( policy='CosineAnnealing', min_lr=0, warmup='linear', warmup_iters=5, warmup_ratio=0.01, warmup_by_epoch=True) ``` |
New | ```python param_scheduler = [ # warmup dict( type='LinearLR', start_factor=0.01, by_epoch=True, end=5, # Update the learning rate after every iters. convert_to_iter_based=True), # main learning rate scheduler dict(type='CosineAnnealingLR', by_epoch=True, begin=5), ] ``` |
Original | ```python runner = dict(type='EpochBasedRunner', max_epochs=100) ``` |
New | ```python # The `val_interval` is the original `evaluation.interval`. train_cfg = dict(by_epoch=True, max_epochs=100, val_interval=1) val_cfg = dict() # Use the default validation loop. test_cfg = dict() # Use the default test loop. ``` |
Original | ```python log_config = dict( interval=100, hooks=[ dict(type='TextLoggerHook'), dict(type='TensorboardLoggerHook'), ]) ``` |
New | ```python default_hooks = dict( ... logger=dict(type='LoggerHook', interval=100), ) visualizer = dict( type='UniversalVisualizer', vis_backends=[dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend')], ) ``` |