[Doc] add zh_cn migration doc (#2733)

as title

---------

Co-authored-by: MeowZheng <meowzheng@outlook.com>
pull/2747/head
CSH 2023-03-13 19:23:22 +08:00 committed by GitHub
parent 45fae72de5
commit 684d79fedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 637 additions and 31 deletions

View File

@ -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)。
## 基准测试和模型库

View File

@ -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'`.
<table class="docutils">
@ -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.
<table class="docutils">
<tr>
@ -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.
<table class="docutils">
<tr>
@ -402,8 +400,7 @@ test_cfg = dict(type='TestLoop') # Use the default test loop.
</tr>
</table>
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.
<table class="docutils">
<tr>
@ -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.

View File

@ -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 |
| :-------------------: | :------------------------------------------------------------------------------------------ |

View File

@ -1,3 +0,0 @@
# 迁移文档
中文迁移文档在支持中,请先阅读[英文版迁移文档](../en/migration/)

View File

@ -0,0 +1,8 @@
迁移
***************
.. toctree::
:maxdepth: 1
interface.md
package.md

View File

@ -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` 中提供的命令行参数更少
<table class="docutils">
<tr>
<td>功能</td>
<td>原版</td>
<td>新版</td>
</tr>
<tr>
<td>加载预训练模型</td>
<td>--load_from=$CHECKPOINT</td>
<td>--cfg-options load_from=$CHECKPOINT</td>
</tr>
<tr>
<td>从特定检查点恢复训练</td>
<td>--resume-from=$CHECKPOINT</td>
<td>--resume=$CHECKPOINT</td>
</tr>
<tr>
<td>从最新的检查点恢复训练</td>
<td>--auto-resume</td>
<td>--resume='auto'</td>
</tr>
<tr>
<td>培训练期间是否不评估检查点</td>
<td>--no-validate</td>
<td>--cfg-options val_cfg=None val_dataloader=None val_evaluator=None</td>
</tr>
<tr>
<td>指定训练设备</td>
<td>--gpu-id=$DEVICE_ID</td>
<td>-</td>
</tr>
<tr>
<td>是否为不同进程设置不同的种子</td>
<td>--diff-seed</td>
<td>--cfg-options randomness.diff_rank_seed=True</td>
</tr>
<td>是否为 CUDNN 后端设置确定性选项</td>
<td>--deterministic</td>
<td>--cfg-options randomness.deterministic=True</td>
</table>
## 配置文件
### 模型设置
`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`
<table class="docutils">
<tr>
<td>原版</td>
<td>
```python
data = dict(
samples_per_gpu=4,
workers_per_gpu=4,
train=dict(...),
val=dict(...),
test=dict(...),
)
```
</td>
<tr>
<td>新版</td>
<td>
```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
```
</td>
</tr>
</table>
**流程**变更
- 原始格式转换 **`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)了解更多详细信息。
训练流程
<table class="docutils">
<tr>
<td>原版</td>
<td>
```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']),
]
```
</td>
<tr>
<td>新版</td>
<td>
```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')
]
```
</td>
</tr>
</table>
测试流程
<table class="docutils">
<tr>
<td>原版</td>
<td>
```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']),
])
]
```
</td>
<tr>
<td>新版</td>
<td>
```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')]
])
]
```
</td>
</tr>
</table>
**`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`
<table class="docutils">
<tr>
<td>原版</td>
<td>
```python
evaluation = dict(interval=2000, metric='mIoU', pre_eval=True)
```
</td>
<tr>
<td>新版</td>
<td>
```python
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
test_evaluator = val_evaluator
```
</td>
</tr>
</table>
### Optimizer 和 Schedule 设置
**`optimizer`** 和 **`optimizer_config`** 中的更改:
- 现在我们使用 `optim_wrapper` 字段来指定优化过程的所有配置。以及 `optimizer``optim_wrapper` 的一个子字段。
- `paramwise_cfg` 也是 `optim_wrapper` 的一个子字段,以替代 `optimizer`
- `optimizer_config` 现在被删除,它的所有配置都被移动到 `optim_wrapper` 中。
- `grad_clip` 重命名为 `clip_grad`
<table class="docutils">
<tr>
<td>原版</td>
<td>
```python
optimizer = dict(type='AdamW', lr=0.0001, weight_decay=0.0005)
optimizer_config = dict(grad_clip=dict(max_norm=1, norm_type=2))
```
</td>
<tr>
<td>新版</td>
<td>
```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))
```
</td>
</tr>
</table>
**`lr_config`** 中的更改:
- 我们将 `lr_config` 字段删除,并使用新的 `param_scheduler` 替代。
- 我们删除了与 `warmup` 相关的参数,因为我们使用 scheduler 组合来实现该功能。
新的 scheduler 组合机制非常灵活,您可以使用它来设计多种学习率/动量曲线。有关详细信息,请参见[教程](TODO)。
<table class="docutils">
<tr>
<td>原版</td>
<td>
```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)
```
</td>
<tr>
<td>新版</td>
<td>
```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,
)
]
```
</td>
</tr>
</table>
**`runner`** 中的更改:
原版 `runner` 字段中的大多数配置被移动到 `train_cfg`、`val_cfg` 和 `test_cfg` 中,以在训练、验证和测试中配置 loop。
<table class="docutils">
<tr>
<td>原版</td>
<td>
```python
runner = dict(type='IterBasedRunner', max_iters=20000)
```
</td>
<tr>
<td>新版</td>
<td>
```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.
```
</td>
</tr>
</table>
事实上,在 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。
<table class="docutils">
<tr>
<td>原版</td>
<td>
```python
log_config = dict(
interval=100,
hooks=[
dict(type='TextLoggerHook'),
dict(type='TensorboardLoggerHook'),
])
```
</td>
<tr>
<td>新版</td>
<td>
```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')
```
</td>
</tr>
</table>
**`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)了解更多详情。

View File

@ -0,0 +1,113 @@
#包结构更改
本节包含您对 MMSeg 0.x 和 1.x 之间的变化感到好奇的内容。
<table>
<tr>
<td>MMSegmentation 0.x</td>
<td>MMSegmentation 1.x</td>
</tr>
<tr>
<td>mmseg.api</td>
<td>mmseg.api</td>
</tr>
<tr>
<td bgcolor=#fcf7f7>- mmseg.core</td>
<td bgcolor=#ecf4eb>+ mmseg.engine</td>
</tr>
<tr>
<td>mmseg.datasets</td>
<td>mmseg.datasets</td>
</tr>
<tr>
<td>mmseg.models</td>
<td>mmseg.models</td>
</tr>
<tr>
<td bgcolor=#fcf7f7>- mmseg.ops</td>
<td bgcolor=#ecf4eb>+ mmseg.structure</td>
</tr>
<tr>
<td>mmseg.utils</td>
<td>mmseg.utils</td>
</tr>
<tr>
<td></td>
<td bgcolor=#ecf4eb>+ mmseg.evaluation</td>
</tr>
<tr>
<td></td>
<td bgcolor=#ecf4eb>+ mmseg.registry</td>
<tr>
</table>
## 已删除的包
### `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`