From 684d79fedc2d144c8ac9e4ce16cd3b0dbd524ccb Mon Sep 17 00:00:00 2001 From: CSH <40987381+csatsurnh@users.noreply.github.com> Date: Mon, 13 Mar 2023 19:23:22 +0800 Subject: [PATCH] [Doc] add zh_cn migration doc (#2733) as title --------- Co-authored-by: MeowZheng --- README_zh-CN.md | 2 +- docs/en/migration/interface.md | 39 +-- docs/en/migration/package.md | 7 +- docs/zh_cn/migration.md | 3 - docs/zh_cn/migration/index.rst | 8 + docs/zh_cn/migration/interface.md | 496 ++++++++++++++++++++++++++++++ docs/zh_cn/migration/package.md | 113 +++++++ 7 files changed, 637 insertions(+), 31 deletions(-) delete mode 100644 docs/zh_cn/migration.md create mode 100644 docs/zh_cn/migration/index.rst create mode 100644 docs/zh_cn/migration/interface.md create mode 100644 docs/zh_cn/migration/package.md diff --git a/README_zh-CN.md b/README_zh-CN.md index 858485fd5..f7c3b0b18 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -76,7 +76,7 @@ MMSegmentation 是一个基于 PyTorch 的语义分割开源工具箱。它是 O 同时,我们提供了 Colab 教程。你可以在[这里](demo/MMSegmentation_Tutorial.ipynb)浏览教程,或者直接在 Colab 上[运行](https://colab.research.google.com/github/open-mmlab/mmsegmentation/blob/1.x/demo/MMSegmentation_Tutorial.ipynb)。 -若需要将0.x版本的代码迁移至新版,请参考[迁移文档](docs/zh_cn/migration.md)。 +若需要将0.x版本的代码迁移至新版,请参考[迁移文档](docs/zh_cn/migration)。 ## 基准测试和模型库 diff --git a/docs/en/migration/interface.md b/docs/en/migration/interface.md index d75f8ec3e..3dab125eb 100644 --- a/docs/en/migration/interface.md +++ b/docs/en/migration/interface.md @@ -6,14 +6,17 @@ This guide describes the fundamental differences between MMSegmentation 0.x and ## 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](get_started.md). +MMSegmentation 1.x depends on some new packages, you can prepare a new clean environment and install again according to the [installation 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. [MMClassification](https://github.com/open-mmlab/mmclassification)(Optional): The image classification toolbox and benchmark of OpenMMLab. This is not a new dependency, but you need to upgrade it to above **1.0.0rc0** version. +3. [MMClassification](https://github.com/open-mmlab/mmclassification)(Optional): The image classification toolbox and benchmark of OpenMMLab. This is not a new dependency, but you need to upgrade it to above **1.0.0rc0** version. + +4. [MMDetection](https://github.com/open-mmlab/mmdetection)(Optional): The object detection toolbox and benchmark of OpenMMLab. This is not a new dependency, but you need to upgrade it to above **3.0.0rc0** version. ## Train launch @@ -86,7 +89,7 @@ Add `model.data_preprocessor` field to configure the `DataPreProcessor`, includi - `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 RGB. Defaults to False. +- `rgb_to_bgr` (bool): whether to convert image from RGB to BGR. Defaults to False. **Note:** Please refer [models documentation](../advanced_guides/models.md) for more details. @@ -260,8 +263,7 @@ tta_pipeline = [ Changes in **`evaluation`**: - The **`evaluation`** field is split to `val_evaluator` and `test_evaluator`. And it won't support `interval` and `save_best` arguments. - The `interval` is moved to `train_cfg.val_interval`, and the `save_best` - is moved to `default_hooks.checkpoint.save_best`. `pre_eval` has been removed. + The `interval` is moved to `train_cfg.val_interval`, and the `save_best` is moved to `default_hooks.checkpoint.save_best`. `pre_eval` has been removed. - `'mIoU'` has been changed to `'IoUMetric'`. @@ -291,8 +293,7 @@ test_evaluator = val_evaluator Changes in **`optimizer`** and **`optimizer_config`**: -- Now we use `optim_wrapper` field to specify all configuration about the optimization process. And the - `optimizer` is a sub field of `optim_wrapper` now. +- Now we use `optim_wrapper` field to specify all configuration about the optimization process. And the `optimizer` is a sub field of `optim_wrapper` now. - `paramwise_cfg` is also a sub field of `optim_wrapper`, instead of `optimizer`. - `optimizer_config` is removed now, and all configurations of it are moved to `optim_wrapper`. - `grad_clip` is renamed to `clip_grad`. @@ -326,11 +327,9 @@ optim_wrapper = dict( Changes in **`lr_config`**: - The `lr_config` field is removed and we use new `param_scheduler` to replace it. -- The `warmup` related arguments are removed, since we use schedulers combination to implement this - functionality. +- The `warmup` related 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](TODO) for more details. +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](TODO) for more details.
@@ -374,8 +373,7 @@ param_scheduler = [ 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. +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.
@@ -402,8 +400,7 @@ test_cfg = dict(type='TestLoop') # Use the default test loop.
-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](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md) -in [MMEngine](https://github.com/open-mmlab/mmengine/). +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](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md) in [MMEngine](https://github.com/open-mmlab/mmengine/). ### Runtime settings @@ -433,8 +430,7 @@ default_hooks = dict( 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. +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. @@ -478,8 +474,7 @@ Changes in **`load_from`** and **`resume_from`**: - If `resume=False` and `load_from` is **not None**, only load the checkpoint, not resume training. - If `resume=False` and `load_from` is **None**, do not load nor resume. -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`. +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`. ```python env_cfg = dict( @@ -496,8 +491,6 @@ env_cfg = dict( 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](user_guides/visualization.md) for more details. +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](../user_guides/visualization.md) 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](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/registry.md) 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](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/registry.md) for more details. diff --git a/docs/en/migration/package.md b/docs/en/migration/package.md index c0aa1d6e3..728e9a9bb 100644 --- a/docs/en/migration/package.md +++ b/docs/en/migration/package.md @@ -74,9 +74,8 @@ We moved registry implementations for all kinds of modules in MMSegmentation in ### `mmseg.apis` -OpenMMLab 2.0 tries to support unified interface for multitasking of Computer Vision, -and releases much stronger [`Runner`](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md), -so MMSeg 1.x removed modules in `train.py` and `test.py` renamed `init_segmentor` to `init_model` and `inference_segmentor` to `inference_model` +OpenMMLab 2.0 tries to support unified interface for multitasking of Computer Vision, and releases much stronger [`Runner`](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md), so MMSeg 1.x removed modules in `train.py` and `test.py` renamed `init_segmentor` to `init_model` and `inference_segmentor` to `inference_model`. + Here is the changes of `mmseg.apis`: | Function | Changes | @@ -92,7 +91,7 @@ Here is the changes of `mmseg.apis`: ### `mmseg.datasets` -OpenMMLab 2.0 defines the `BaseDataset` to function and interface of dataset, and MMSegmentation 1.x also follow this protocol and defines the `BaseSegDataset` inherited from `BaseDataset`. MMCV 2.x collects general data transforms for multiple tasks e.g. classification, detection, segmentation, so MMSegmentation 1.x uses these data transforms and removes them from mmseg.datasets +OpenMMLab 2.0 defines the `BaseDataset` to function and interface of dataset, and MMSegmentation 1.x also follow this protocol and defines the `BaseSegDataset` inherited from `BaseDataset`. MMCV 2.x collects general data transforms for multiple tasks e.g. classification, detection, segmentation, so MMSegmentation 1.x uses these data transforms and removes them from mmseg.datasets. | Packages/Modules | Changes | | :-------------------: | :------------------------------------------------------------------------------------------ | diff --git a/docs/zh_cn/migration.md b/docs/zh_cn/migration.md deleted file mode 100644 index 3f19b2671..000000000 --- a/docs/zh_cn/migration.md +++ /dev/null @@ -1,3 +0,0 @@ -# 迁移文档 - -中文迁移文档在支持中,请先阅读[英文版迁移文档](../en/migration/) diff --git a/docs/zh_cn/migration/index.rst b/docs/zh_cn/migration/index.rst new file mode 100644 index 000000000..854b9e61d --- /dev/null +++ b/docs/zh_cn/migration/index.rst @@ -0,0 +1,8 @@ +迁移 +*************** + +.. toctree:: + :maxdepth: 1 + + interface.md + package.md diff --git a/docs/zh_cn/migration/interface.md b/docs/zh_cn/migration/interface.md new file mode 100644 index 000000000..a329ce38a --- /dev/null +++ b/docs/zh_cn/migration/interface.md @@ -0,0 +1,496 @@ +# 从 MMSegmentation 0.x 迁移 + +## 引言 + +本指南介绍了 MMSegmentation 0.x 和 MMSegmentation1.x 在行为和 API 方面的基本区别,以及这些如何都与您的迁移过程相关。 + +## 新的依赖 + +MMSegmentation 1.x 依赖于一些新的软件包,您可以准备一个新的干净环境,然后根据[安装教程](../get_started.md)重新安装。 + +或手动安装以下软件包。 + +1. [MMEngine](https://github.com/open-mmlab/mmengine):MMEngine 是 OpenMMLab 2.0 架构的核心,我们将许多与计算机视觉无关的内容从 MMCV 拆分到 MMEngine 中。 + +2. [MMCV](https://github.com/open-mmlab/mmcv):OpenMMLab 的计算机视觉包。这不是一个新的依赖,但您需要将其升级到 **2.0.0rc1** 以上的版本。 + +3. [MMClassification](https://github.com/open-mmlab/mmclassification)(可选):OpenMMLab 的图像分类工具箱和基准。这不是一个新的依赖,但您需要将其升级到 **1.0.0rc0** 以上的版本。 + +4. [MMDetection](https://github.com/open-mmlab/mmdetection)(可选): OpenMMLab 的目标检测工具箱和基准。这不是一个新的依赖,但您需要将其升级到 **3.0.0rc0** 以上的版本。 + +## 启动训练 + +OpenMMLab 2.0 的主要改进是发布了 MMEngine,它为启动训练任务的统一接口提供了通用且强大的执行器。 + +与 MMSeg 0.x 相比,MMSeg 1.x 在 `tools/train.py` 中提供的命令行参数更少 + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
功能原版新版
加载预训练模型--load_from=$CHECKPOINT--cfg-options load_from=$CHECKPOINT
从特定检查点恢复训练--resume-from=$CHECKPOINT--resume=$CHECKPOINT
从最新的检查点恢复训练--auto-resume--resume='auto'
培训练期间是否不评估检查点--no-validate--cfg-options val_cfg=None val_dataloader=None val_evaluator=None
指定训练设备--gpu-id=$DEVICE_ID-
是否为不同进程设置不同的种子--diff-seed--cfg-options randomness.diff_rank_seed=True
是否为 CUDNN 后端设置确定性选项--deterministic--cfg-options randomness.deterministic=True
+ +## 配置文件 + +### 模型设置 + +`model.backend`、`model.neck`、`model.decode_head` 和 `model.loss` 字段没有更改。 + +添加 `model.data_preprocessor` 字段以配置 `DataPreProcessor`,包括: + +- `mean`(Sequence,可选):R、G、B 通道的像素平均值。默认为 None。 + +- `std`(Sequence,可选):R、G、B通道的像素标准差。默认为 None。 + +- `size`(Sequence,可选):固定的填充大小。 + +- `size_divisor`(int,可选):填充大小的除法因子。 + +- `seg_pad_val`(float,可选):分割图的填充值。默认值:255。 + +- `padding_mode`(str):填充类型。默认值:'constant'。 + + - constant:常量值填充,值由 pad_val 指定。 + +- `bgr_to_rgb`(bool):是否将图像从 BGR 转换为 RGB。默认为 False。 + +- `rgb_to_bgr`(bool):是否将图像从 RGB 转换为 BGR。默认为 False。 + +**注:** +有关详细信息,请参阅[模型文档](../advanced_guides/models.md)。 + +### 数据集设置 + +**data** 的更改: + +原版 `data` 字段被拆分为 `train_dataloader`、`val_dataloader` 和 `test_dataloader`。这允许我们以细粒度配置它们。例如,您可以在训练和测试期间指定不同的采样器和批次大小。 +`samples_per_gpu` 重命名为 `batch_size`。 +`workers_per_gpu` 重命名为 `num_workers`。 + + + + + + + + + +
原版 + +```python +data = dict( + samples_per_gpu=4, + workers_per_gpu=4, + train=dict(...), + val=dict(...), + test=dict(...), +) +``` + +
新版 + +```python +train_dataloader = dict( + batch_size=4, + num_workers=4, + dataset=dict(...), + sampler=dict(type='DefaultSampler', shuffle=True) # necessary +) + +val_dataloader = dict( + batch_size=4, + num_workers=4, + dataset=dict(...), + sampler=dict(type='DefaultSampler', shuffle=False) # necessary +) + +test_dataloader = val_dataloader +``` + +
+ +**流程**变更 + +- 原始格式转换 **`ToTensor`**、**`ImageToTensor`**、**`Collect`** 组合为 [`PackSegInputs`](mmseg.datasets.transforms.PackSegInputs) +- 我们不建议在数据集流程中执行 **`Normalize`** 和 **Pad**。请将其从流程中删除,并将其设置在 `data_preprocessor` 字段中。 +- MMSeg 1.x 中原始的 **`Resize`** 已更改为 **`RandomResize `**,输入参数 `img_scale` 重命名为 `scale`,`keep_ratio` 的默认值修改为 False。 +- 原始的 `test_pipeline` 将单尺度和多尺度测试结合在一起,在 MMSeg 1.x 中,我们将其分为 `test_pipeline` 和 `tta_pipeline`。 + +**注:** +我们将一些数据转换工作转移到数据预处理器中,如归一化,请参阅[文档](package.md)了解更多详细信息。 + +训练流程 + + + + + + + + + +
原版 + +```python +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='LoadAnnotations', reduce_zero_label=True), + dict(type='Resize', img_scale=(2560, 640), ratio_range=(0.5, 2.0)), + dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), + dict(type='RandomFlip', prob=0.5), + dict(type='PhotoMetricDistortion'), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255), + dict(type='DefaultFormatBundle'), + dict(type='Collect', keys=['img', 'gt_semantic_seg']), +] +``` + +
新版 + +```python +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='LoadAnnotations', reduce_zero_label=True), + dict( + type='RandomResize', + scale=(2560, 640), + ratio_range=(0.5, 2.0), + keep_ratio=True), + dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), + dict(type='RandomFlip', prob=0.5), + dict(type='PhotoMetricDistortion'), + dict(type='PackSegInputs') +] +``` + +
+ +测试流程 + + + + + + + + + +
原版 + +```python +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiScaleFlipAug', + img_scale=(2560, 640), + # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75], + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='RandomFlip'), + dict(type='Normalize', **img_norm_cfg), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] +``` + +
新版 + +```python +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='Resize', scale=(2560, 640), keep_ratio=True), + dict(type='LoadAnnotations', reduce_zero_label=True), + dict(type='PackSegInputs') +] +img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] +tta_pipeline = [ + dict(type='LoadImageFromFile', backend_args=None), + dict( + type='TestTimeAug', + transforms=[ + [ + dict(type='Resize', scale_factor=r, keep_ratio=True) + for r in img_ratios + ], + [ + dict(type='RandomFlip', prob=0., direction='horizontal'), + dict(type='RandomFlip', prob=1., direction='horizontal') + ], [dict(type='LoadAnnotations')], [dict(type='PackSegInputs')] + ]) +] +``` + +
+ +**`evaluation`** 中的更改: + +- **`evaluation`** 字段被拆分为 `val_evaluator` 和 `test_evaluator `。而且不再支持 `interval` 和 `save_best` 参数。 + `interval` 已移动到 `train_cfg.val_interval`,`save_best` 已移动到 `default_hooks.checkpoint.save_best`。`pre_eval` 已删除。 +- `IoU` 已更改为 `IoUMetric`。 + + + + + + + + + +
原版 + +```python +evaluation = dict(interval=2000, metric='mIoU', pre_eval=True) +``` + +
新版 + +```python +val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) +test_evaluator = val_evaluator +``` + +
+ +### Optimizer 和 Schedule 设置 + +**`optimizer`** 和 **`optimizer_config`** 中的更改: + +- 现在我们使用 `optim_wrapper` 字段来指定优化过程的所有配置。以及 `optimizer` 是 `optim_wrapper` 的一个子字段。 +- `paramwise_cfg` 也是 `optim_wrapper` 的一个子字段,以替代 `optimizer`。 +- `optimizer_config` 现在被删除,它的所有配置都被移动到 `optim_wrapper` 中。 +- `grad_clip` 重命名为 `clip_grad`。 + + + + + + + + + +
原版 + +```python +optimizer = dict(type='AdamW', lr=0.0001, weight_decay=0.0005) +optimizer_config = dict(grad_clip=dict(max_norm=1, norm_type=2)) +``` + +
新版 + +```python +optim_wrapper = dict( + type='OptimWrapper', + optimizer=dict(type='AdamW', lr=0.0001, weight_decay=0.0005), + clip_grad=dict(max_norm=1, norm_type=2)) +``` + +
+ +**`lr_config`** 中的更改: + +- 我们将 `lr_config` 字段删除,并使用新的 `param_scheduler` 替代。 +- 我们删除了与 `warmup` 相关的参数,因为我们使用 scheduler 组合来实现该功能。 + +新的 scheduler 组合机制非常灵活,您可以使用它来设计多种学习率/动量曲线。有关详细信息,请参见[教程](TODO)。 + + + + + + + + + +
原版 + +```python +lr_config = dict( + policy='poly', + warmup='linear', + warmup_iters=1500, + warmup_ratio=1e-6, + power=1.0, + min_lr=0.0, + by_epoch=False) +``` + +
新版 + +```python +param_scheduler = [ + dict( + type='LinearLR', start_factor=1e-6, by_epoch=False, begin=0, end=1500), + dict( + type='PolyLR', + power=1.0, + begin=1500, + end=160000, + eta_min=0.0, + by_epoch=False, + ) +] +``` + +
+ +**`runner`** 中的更改: + +原版 `runner` 字段中的大多数配置被移动到 `train_cfg`、`val_cfg` 和 `test_cfg` 中,以在训练、验证和测试中配置 loop。 + + + + + + + + + +
原版 + +```python +runner = dict(type='IterBasedRunner', max_iters=20000) +``` + +
新版 + +```python +# The `val_interval` is the original `evaluation.interval`. +train_cfg = dict(type='IterBasedTrainLoop', max_iters=20000, val_interval=2000) +val_cfg = dict(type='ValLoop') # Use the default validation loop. +test_cfg = dict(type='TestLoop') # Use the default test loop. +``` + +
+ +事实上,在 OpenMMLab 2.0 中,我们引入了 `Loop` 来控制训练、验证和测试中的行为。`Runner` 的功能也发生了变化。您可以在 [MMMEngine](https://github.com/open-mmlab/mmengine/) 的[执行器教程](https://github.com/open-mmlab/mmengine/blob/main/docs/zh_cn/design/runner.md) 中找到更多的详细信息。 + +### 运行时设置 + +**`checkpoint_config`** 和 **`log_config`** 中的更改: + +`checkpoint_config` 被移动到 `default_hooks.checkpoint` 中,`log_config` 被移动到 `default_hooks.logger` 中。 +并且我们将许多钩子设置从脚本代码移动到运行时配置的 `default_hooks` 字段中。 + +```python +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')) +``` + +此外,我们将原版 logger 拆分为 logger 和 visualizer。logger 用于记录信息,visualizer 用于在不同的后端显示 logger,如 terminal 和 TensorBoard。 + + + + + + + + + +
原版 + +```python +log_config = dict( + interval=100, + hooks=[ + dict(type='TextLoggerHook'), + dict(type='TensorboardLoggerHook'), + ]) +``` + +
新版 + +```python +default_hooks = dict( + ... + logger=dict(type='LoggerHook', interval=100), +) +vis_backends = [dict(type='LocalVisBackend'), + dict(type='TensorboardVisBackend')] +visualizer = dict( + type='SegLocalVisualizer', vis_backends=vis_backends, name='visualizer') +``` + +
+ +**`load_from`** 和 **`resume_from`** 中的更改: + +- 删除 `resume_from`。我们使用 `resume` 和 `load_from` 来替换它。 + - 如果 `resume=True` 且 `load_from` 为 **not None**,则从 `load_from` 中的检查点恢复训练。 + - 如果 `resume=True` 且 `load_from` 为 **None**,则尝试从工作目录中的最新检查点恢复。 + - 如果 `resume=False` 且 `load_from` 为 **not None**,则只加载检查点,而不继续训练。 + - 如果 `resume=False` 且 `load_from` 为 **None**,则不加载或恢复。 + +**`dist_params`** 中的更改:`dist_params` 字段现在是 `env_cfg` 的子字段。并且 `env_cfg` 中还有一些新的配置。 + +```python +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'), +) +``` + +**`workflow`** 的改动:`workflow` 相关功能被删除。 + +新字段 **`visualizer`**:visualizer 是 OpenMMLab 2.0 体系结构中的新设计。我们在 runner 中使用 visualizer 实例来处理结果和日志可视化,并保存到不同的后端。更多详细信息,请参阅[可视化教程](../user_guides/visualization.md)。 + +新字段 **`default_scope`**:搜索所有注册模块的起点。MMSegmentation 中的 `default_scope` 为 `mmseg`。请参见[注册器教程](https://github.com/open-mmlab/mmengine/blob/main/docs/zh_cn/advanced_tutorials/registry.md)了解更多详情。 diff --git a/docs/zh_cn/migration/package.md b/docs/zh_cn/migration/package.md new file mode 100644 index 000000000..d8d2245be --- /dev/null +++ b/docs/zh_cn/migration/package.md @@ -0,0 +1,113 @@ +#包结构更改 + +本节包含您对 MMSeg 0.x 和 1.x 之间的变化感到好奇的内容。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MMSegmentation 0.xMMSegmentation 1.x
mmseg.apimmseg.api
- mmseg.core+ mmseg.engine
mmseg.datasetsmmseg.datasets
mmseg.modelsmmseg.models
- mmseg.ops+ mmseg.structure
mmseg.utilsmmseg.utils
+ mmseg.evaluation
+ mmseg.registry
+ +## 已删除的包 + +### `mmseg.core` + +在 OpenMMLab 2.0 中,`core` 包已被删除。`core` 的 `hooks` 和 `optimizers` 被移动到了 `mmseg.engine` 中,而 `core` 中的 `evaluation` 目前是 mmseg.evaluation。 + +## `mmseg.ops` + +`ops` 包包含 `encoding` 和 `wrappers`,它们被移到了 `mmseg.models.utils` 中。 + +## 增加的包 + +### `mmseg.engine` + +OpenMMLab 2.0 增加了一个新的深度学习训练基础库 MMEngine。它是所有 OpenMMLab 代码库的训练引擎。 +mmseg 的 `engine` 包是一些用于语义分割任务的定制模块,如 `SegVisualizationHook` 用于可视化分割掩膜。 + +### `mmseg.structure` + +在 OpenMMLab 2.0 中,我们为计算机视觉任务设计了数据结构,在 mmseg 中,我们在 `structure` 包中实现了 `SegDataSample`。 + +### `mmseg.evaluation` + +我们将所有评估指标都移动到了 `mmseg.evaluation` 中。 + +### `mmseg.registry` + +我们将 MMSegmentation 中所有类型模块的注册实现移动到 `mmseg.registry` 中。 + +## 修改的包 + +### `mmseg.apis` + +OpenMMLab 2.0 尝试支持计算机视觉的多任务统一接口,并发布了更强的 [`Runner`](https://github.com/open-mmlab/mmengine/blob/main/docs/zh_cn/design/runner.md),因此 MMSeg 1.x 删除了 `train.py` 和 `test.py` 中的模块,并将 `init_segmentor` 重命名为 `init_model`,将 `inference_segmentor` 重命名为 `inference_model`。 + +以下是 `mmseg.apis` 的更改: + +| 函数 | 变化 | +| :-------------------: | :--------------------------------------------- | +| `init_segmentor` | 重命名为 `init_model` | +| `inference_segmentor` | 重命名为 `inference_model` | +| `show_result_pyplot` | 基于 `SegLocalVisualizer` 实现 | +| `train_model` | 删除,使用 `runner.train` 训练。 | +| `multi_gpu_test` | 删除,使用 `runner.test` 测试。 | +| `single_gpu_test` | 删除,使用 `runner.test` 测试。 | +| `set_random_seed` | 删除,使用 `mmengine.runner.set_random_seed`。 | +| `init_random_seed` | 删除,使用 `mmengine.dist.sync_random_seed`。 | + +### `mmseg.datasets` + +OpenMMLab 2.0 将 `BaseDataset` 定义为数据集的函数和接口,MMSegmentation 1.x 也遵循此协议,并定义了从 `BaseDataset` 继承的 `BaseSegDataset`。MMCV 2.x 收集多种任务的通用数据转换,例如分类、检测、分割,因此 MMSegmentation 1.x 使用这些数据转换并将其从 mmseg.dataset 中删除。 + +| 包/模块 | 更改 | +| :-------------------: | :----------------------------------------------------------------------------------- | +| `mmseg.pipelines` | 移动到 `mmcv.transforms` 中 | +| `mmseg.sampler` | 移动到 `mmengine.dataset.sampler` 中 | +| `CustomDataset` | 重命名为 `BaseSegDataset` 并从 MMEngine 中的 `BaseDataset` 继承 | +| `DefaultFormatBundle` | 替换为 `PackSegInputs` | +| `LoadImageFromFile` | 移动到 `mmcv.transforms.LoadImageFromFile` 中 | +| `LoadAnnotations` | 移动到 `mmcv.transforms.LoadAnnotations` 中 | +| `Resize` | 移动到 `mmcv.transforms` 中并拆分为 `Resize`,`RandomResize` 和 `RandomChoiceResize` | +| `RandomFlip` | 移动到 `mmcv.transforms.RandomFlip` 中 | +| `Pad` | 移动到 `mmcv.transforms.Pad` 中 | +| `Normalize` | 移动到 `mmcv.transforms.Normalize` 中 | +| `Compose` | 移动到 `mmcv.transforms.Compose` 中 | +| `ImageToTensor` | 移动到 `mmcv.transforms.ImageToTensor` 中 | + +### `mmseg.models` + +`models` 没有太大变化,只是从以前的 `mmseg.ops` 中添加了 `encoding` 和 `wrappers`