# Migration We introduce some modifications in MMPretrain 1.x, and some of them are BC-breacking. To migrate your projects from **MMClassification 0.x** or **MMSelfSup 0.x** smoothly, please read this tutorial. - [Migration](#migration) - [New dependencies](#new-dependencies) - [General change of config](#general-change-of-config) - [Schedule settings](#schedule-settings) - [Runtime settings](#runtime-settings) - [Other changes](#other-changes) - [Migration from MMClassification 0.x](#migration-from-mmclassification-0x) - [Config files](#config-files) - [Model settings](#model-settings) - [Data settings](#data-settings) - [Packages](#packages) - [`mmpretrain.apis`](#mmpretrainapis) - [`mmpretrain.core`](#mmpretraincore) - [`mmpretrain.datasets`](#mmpretraindatasets) - [`mmpretrain.models`](#mmpretrainmodels) - [`mmpretrain.utils`](#mmpretrainutils) - [Migration from MMSelfSup 0.x](#migration-from-mmselfsup-0x) - [Config](#config) - [Dataset settings](#dataset-settings) - [Model settings](#model-settings-1) - [Package](#package) ## New dependencies ```{warning} MMPretrain 1.x has new package dependencies, and a new environment should be created for MMPretrain 1.x even if you already have a well-rounded MMClassification 0.x or MMSelfSup 0.x environment. Please refer to the [installation tutorial](./get_started.md) for the required package installation or install the packages manually. ``` 1. [MMEngine](https://github.com/open-mmlab/mmengine): MMEngine is the core the OpenMMLab 2.0 architecture, and we have split 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 it should be upgraded to version `2.0.0rc1` or above. 3. [rich](https://github.com/Textualize/rich): A terminal formatting package, and we use it to enhance some outputs in the terminal. 4. [einops](https://github.com/arogozhnikov/einops): Operators for Einstein notations. # General change of config In this section, we introduce the general difference between old version(**MMClassification 0.x** or **MMSelfSup 0.x**) and **MMPretrain 1.x**. ## Schedule settings | MMCls or MMSelfSup 0.x | MMPretrain 1.x | Remark | | ---------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------- | | optimizer_config | / | It has been **removed**. | | / | optim_wrapper | The `optim_wrapper` provides a common interface for updating parameters. | | lr_config | param_scheduler | The `param_scheduler` is a list to set learning rate or other parameters, which is more flexible. | | runner | train_cfg | The loop setting (`EpochBasedTrainLoop`, `IterBasedTrainLoop`) in `train_cfg` controls the work flow of the algorithm training. | Changes in **`optimizer`** and **`optimizer_config`**: - Now we use `optim_wrapper` field to specify all configurations related to optimization process. The `optimizer` has become a subfield of `optim_wrapper`. - The `paramwise_cfg` field is also a subfield of `optim_wrapper`, instead of `optimizer`. - The `optimizer_config` field has been removed, and all configurations has been moved to `optim_wrapper`. - The `grad_clip` field has been renamed to `clip_grad`.
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')], ) ``` |
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 data = dict( samples_per_gpu=32, # total 32*8(gpu)=256 workers_per_gpu=4, train=dict( type=dataset_type, data_source=dict( type=data_source, data_prefix='data/imagenet/train', ann_file='data/imagenet/meta/train.txt', ), num_views=[1, 1], pipelines=[train_pipeline1, train_pipeline2], prefetch=prefetch, ), val=...) ``` |
New | ```python train_dataloader = dict( batch_size=32, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), collate_fn=dict(type='default_collate'), dataset=dict( type=dataset_type, data_root=data_root, ann_file='meta/train.txt', data_prefix=dict(img_path='train/'), pipeline=train_pipeline)) val_dataloader = ... ``` |