Migration from MMSegmentation 0.x
Introduction
This guide describes the fundamental differences between MMSegmentation 0.x and MMSegmentation 1.x in terms of behaviors and the APIs, and how these all relate to your migration journey.
New dependencies
MMSegmentation 1.x depends on some new packages, you can prepare a new clean environment and install again according to the installation tutorial.
Or install the below packages manually.
MMEngine: MMEngine is the core the OpenMMLab 2.0 architecture, and we splited many compentents unrelated to computer vision from MMCV to MMEngine.
MMCV: The computer vision package of OpenMMLab. This is not a new dependency, but you need to upgrade it to 2.0.0 version or above.
MMClassification(Optional): The image classification toolbox and benchmark of OpenMMLab. This is not a new dependency, but you need to upgrade it to 1.0.0rc6 version.
MMDetection(Optional): The object detection toolbox and benchmark of OpenMMLab. This is not a new dependency, but you need to upgrade it to 3.0.0 version or above.
Train launch
The main improvement of OpenMMLab 2.0 is releasing MMEngine which provides universal and powerful runner for unified interfaces to launch training jobs.
Compared with MMSeg0.x, MMSeg1.x provides fewer command line arguments in tools/train.py
| Function | Original | New |
| Loading pre-trained checkpoint | --load_from=$CHECKPOINT | --cfg-options load_from=$CHECKPOINT |
| Resuming Train from specific checkpoint | --resume-from=$CHECKPOINT | --resume=$CHECKPOINT |
| Resuming Train from the latest checkpoint | --auto-resume | --resume='auto' |
| Whether not to evaluate the checkpoint during training | --no-validate | --cfg-options val_cfg=None val_dataloader=None val_evaluator=None |
| Training device assignment | --gpu-id=$DEVICE_ID | - |
| Whether or not set different seeds for different ranks | --diff-seed | --cfg-options randomness.diff_rank_seed=True |
| Whether to set deterministic options for CUDNN backend | --deterministic | --cfg-options randomness.deterministic=True |
Test launch
Similar to training launch, there are only common arguments in tools/test.py of MMSegmentation 1.x. Below is the difference in test scripts, please refer to this documentation for more details about test launch.
| Function | 0.x | 1.x |
| Evaluation metrics | --eval mIoU | --cfg-options test_evaluator.type=IoUMetric |
| Whether to use test time augmentation | --aug-test | --tta |
| Whether save the output results without perform evaluation | --format-only | --cfg-options test_evaluator.format_only=True |
Configuration file
Model settings
No changes in model.backbone, model.neck, model.decode_head and model.losses fields.
Add model.data_preprocessor field to configure the DataPreProcessor, including:
mean(Sequence, optional): The pixel mean of R, G, B channels. Defaults to None.std(Sequence, optional): The pixel standard deviation of R, G, B channels. Defaults to None.size(Sequence, optional): Fixed padding size.size_divisor(int, optional): The divisor of padded size.seg_pad_val(float, optional): Padding value of segmentation map. Default: 255.padding_mode(str): Type of padding. Default: 'constant'.- constant: pads with a constant value, this value is specified with pad_val.
bgr_to_rgb(bool): whether to convert image from BGR to RGB.Defaults to False.rgb_to_bgr(bool): whether to convert image from RGB to BGR. Defaults to False.
Note: Please refer models documentation for more details.
Dataset settings
Changes in data:
The original data field is split to train_dataloader, val_dataloader and test_dataloader. This allows us to configure them in fine-grained. For example, you can specify different sampler and batch size during training and test.
The samples_per_gpu is renamed to batch_size.
The workers_per_gpu is renamed to num_workers.
| Original |
|
| New |
|
Changes in pipeline
- The original formatting transforms
ToTensor、ImageToTensor、Collectare combined asPackSegInputs - We don't recommend to do
Normalizeand Pad in the dataset pipeline. Please remove it from pipelines and set it in thedata_preprocessorfield. - The original
Resizein MMSeg 1.x has been changed toRandomResizeand the input argumentsimg_scaleis renamed toscale, and the default value ofkeep_ratiois modified to False. - The original
test_pipelinecombines single-scale test and multi-scale test together, in MMSeg 1.x we separate it intotest_pipelineandtta_pipeline.
Note: We move some work of data transforms to the data preprocessor, like normalization, see the documentation for more details.
train_pipeline
| Original |
|
| New |
|
test_pipeline
| Original |
|
| New |
|
Changes in evaluation:
- The
evaluationfield is split toval_evaluatorandtest_evaluator. And it won't supportintervalandsave_bestarguments. Theintervalis moved totrain_cfg.val_interval, and thesave_bestis moved todefault_hooks.checkpoint.save_best.pre_evalhas been removed. 'mIoU'has been changed to'IoUMetric'.
| Original |
|
| New |
|
Optimizer and Schedule settings
Changes in optimizer and optimizer_config:
- Now we use
optim_wrapperfield to specify all configuration about the optimization process. And theoptimizeris a sub field ofoptim_wrappernow. paramwise_cfgis also a sub field ofoptim_wrapper, instead ofoptimizer.optimizer_configis removed now, and all configurations of it are moved tooptim_wrapper.grad_clipis renamed toclip_grad.
| Original |
|
| New |
|
Changes in lr_config:
- The
lr_configfield is removed and we use newparam_schedulerto replace it. - The
warmuprelated arguments are removed, since we use schedulers combination to implement this functionality.
The new schedulers combination mechanism is very flexible, and you can use it to design many kinds of learning rate / momentum curves. See the tutorial for more details.
| Original |
|
| New |
|
Changes in runner:
Most configuration in the original runner field is moved to train_cfg, val_cfg and test_cfg, which configure the loop in training, validation and test.
| Original |
|
| New |
|
In fact, in OpenMMLab 2.0, we introduced Loop to control the behaviors in training, validation and test. The functionalities of Runner are also changed. You can find more details of runner tutorial in MMEngine.
Runtime settings
Changes in checkpoint_config and log_config:
The checkpoint_config are moved to default_hooks.checkpoint and the log_config are moved to default_hooks.logger.
And we move many hooks settings from the script code to the default_hooks field in the runtime configuration.
default_hooks = dict(
# record the time of every iterations.
timer=dict(type='IterTimerHook'),
# print log every 50 iterations.
logger=dict(type='LoggerHook', interval=50, log_metric_by_epoch=False),
# enable the parameter scheduler.
param_scheduler=dict(type='ParamSchedulerHook'),
# save checkpoint every 2000 iterations.
checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=2000),
# set sampler seed in distributed environment.
sampler_seed=dict(type='DistSamplerSeedHook'),
# validation results visualization.
visualization=dict(type='SegVisualizationHook'))
In addition, we split the original logger to logger and visualizer. The logger is used to record information and the visualizer is used to show the logger in different backends, like terminal and TensorBoard.
| Original |
|
| New |
|
Changes in load_from and resume_from:
- The
resume_fromis removed. And we useresumeandload_fromto replace it.- If
resume=Trueandload_fromis not None, resume training from the checkpoint inload_from. - If
resume=Trueandload_fromis None, try to resume from the latest checkpoint in the work directory. - If
resume=Falseandload_fromis not None, only load the checkpoint, not resume training. - If
resume=Falseandload_fromis None, do not load nor resume.
- If
Changes in dist_params: The dist_params field is a sub field of env_cfg now. And there are some new configurations in the env_cfg.
env_cfg = dict(
# whether to enable cudnn benchmark
cudnn_benchmark=False,
# set multi process parameters
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
# set distributed parameters
dist_cfg=dict(backend='nccl'),
)
Changes in workflow: workflow related functionalities are removed.
New field visualizer: The visualizer is a new design in OpenMMLab 2.0 architecture. We use a visualizer instance in the runner to handle results & log visualization and save to different backends. See the visualization tutorial for more details.
New field default_scope: The start point to search module for all registries. The default_scope in MMSegmentation is mmseg. See the registry tutorial for more details.