Skip to content

Commit 645dcf8

Browse files
authored
[Doc] Add zh_cn evaluation doc and fix en typo (open-mmlab#2701)
as title --------- Signed-off-by: csatsurnh <[email protected]>
1 parent 7e41b5a commit 645dcf8

File tree

2 files changed

+170
-15
lines changed

2 files changed

+170
-15
lines changed

docs/en/advanced_guides/evaluation.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Evaluation
22

3-
The evaluation procedure would be executed at [ValLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L300) and [TestLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L373), users can evaluate model performance during training or using the test script with simple settings in the configuration file. The `ValLoop` and `TestLoop` are properties of [Runner](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L59), they will be built the first time they are called. To build the `ValLoop` successfully, the `val_dataloader` and `val_evaluator` must be set when building `Runner` since `dataloder` and `evaluator` are required parameters, and the same goes for `TestLoop`. For more information about the Runner's design, please refer to the [documentoation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md) of [MMEngine](https://github.com/open-mmlab/mmengine).
3+
The evaluation procedure would be executed at [ValLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L300) and [TestLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L373), users can evaluate model performance during training or using the test script with simple settings in the configuration file. The `ValLoop` and `TestLoop` are properties of [Runner](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L59), they will be built the first time they are called. To build the `ValLoop` successfully, the `val_dataloader` and `val_evaluator` must be set when building `Runner` since `dataloader` and `evaluator` are required parameters, and the same goes for `TestLoop`. For more information about the Runner's design, please refer to the [documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md) of [MMEngine](https://github.com/open-mmlab/mmengine).
44

55
<center>
66
<img src='../../../resources/test_step.png' />
@@ -61,7 +61,7 @@ In MMSegmentation, the settings of `test_dataloader` and `test_evaluator` are th
6161

6262
## IoUMetric
6363

64-
MMSegmentation implements [IoUMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/iou_metric.py) and [CitysMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/citys_metric.py) for evaluating the performance of models, based on the [BaseMetric](https://github.com/open-mmlab/mmengine/blob/main/mmengine/evaluator/metric.py) provided by [MMEngine](https://github.com/open-mmlab/mmengine). Please refer to [the documentation](https://mmengine.readthedocs.io/en/latest/tutorials/evaluation.html) for more details about the unified evaluation interface.
64+
MMSegmentation implements [IoUMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/iou_metric.py) and [CityscapesMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/citys_metric.py) for evaluating the performance of models, based on the [BaseMetric](https://github.com/open-mmlab/mmengine/blob/main/mmengine/evaluator/metric.py) provided by [MMEngine](https://github.com/open-mmlab/mmengine). Please refer to [the documentation](https://mmengine.readthedocs.io/en/latest/tutorials/evaluation.html) for more details about the unified evaluation interface.
6565

6666
Here we briefly describe the arguments and the two main methods of `IoUMetric`.
6767

@@ -102,9 +102,9 @@ Returns:
102102

103103
- Dict\[str, float\] - The computed metrics. The keys are the names of the metrics, and the values are corresponding results. The key mainly includes **aAcc**, **mIoU**, **mAcc**, **mDice**, **mFscore**, **mPrecision**, **mRecall**.
104104

105-
## CitysMetric
105+
## CityscapesMetric
106106

107-
`CitysMetric` uses the official [CityscapesScripts](https://github.com/mcordts/cityscapesScripts) provided by Cityscapes to evaluate model performance.
107+
`CityscapesMetric` uses the official [CityscapesScripts](https://github.com/mcordts/cityscapesScripts) provided by Cityscapes to evaluate model performance.
108108

109109
### Usage
110110

@@ -114,38 +114,38 @@ Before using it, please install the `cityscapesscripts` package first:
114114
pip install cityscapesscripts
115115
```
116116

117-
Since the `IoUMetric` is used as the default evaluator in MMSegmentation, if you would like to use `CitysMetric`, customizing the config file is required. In your customized config file, you should overwrite the default evaluator as follows.
117+
Since the `IoUMetric` is used as the default evaluator in MMSegmentation, if you would like to use `CityscapesMetric`, customizing the config file is required. In your customized config file, you should overwrite the default evaluator as follows.
118118

119119
```python
120-
val_evaluator = dict(type='CitysMetric', citys_metrics=['cityscapes'])
120+
val_evaluator = dict(type='CityscapesMetric', output_dir='tmp')
121121
test_evaluator = val_evaluator
122122
```
123123

124124
### Interface
125125

126126
The arguments of the constructor:
127127

128+
- output_dir (str) - The directory for output prediction
128129
- ignore_index (int) - Index that will be ignored in evaluation. Default: 255.
129-
- citys_metrics (list\[str\] | str) - Metrics to be evaluated, Default: \['cityscapes'\].
130-
- to_label_id (bool) - whether convert output to label_id for submission. Default: True.
131-
- suffix (str): The filename prefix of the png files. If the prefix is "somepath/xxx", the png files will be named "somepath/xxx.png". Default: '.format_cityscapes'.
132-
- collect_device (str): Device name used for collecting results from different ranks during distributed training. Must be 'cpu' or 'gpu'. Defaults to 'cpu'.
133-
- prefix (str, optional): The prefix that will be added in the metric names to disambiguate homonymous metrics of different evaluators. If the prefix is not provided in the argument, self.default_prefix will be used instead. Defaults to None.
130+
- format_only (bool) - Only format result for results commit without perform evaluation. It is useful when you want to format the result to a specific format and submit it to the test server. Defaults to False.
131+
- keep_results (bool) - Whether to keep the results. When `format_only` is True, `keep_results` must be True. Defaults to False.
132+
- collect_device (str) - Device name used for collecting results from different ranks during distributed training. Must be 'cpu' or 'gpu'. Defaults to 'cpu'.
133+
- prefix (str, optional) - The prefix that will be added in the metric names to disambiguate homonymous metrics of different evaluators. If prefix is not provided in the argument, self.default_prefix will be used instead. Defaults to None.
134134

135-
#### CitysMetric.process
135+
#### CityscapesMetric.process
136136

137137
This method would draw the masks on images and save the painted images to `work_dir`.
138138

139139
Parameters:
140140

141-
- data_batch (Any) - A batch of data from the dataloader.
141+
- data_batch (dict) - A batch of data from the dataloader.
142142
- data_samples (Sequence\[dict\]) - A batch of outputs from the model.
143143

144144
Returns:
145145

146146
This method doesn't have returns, the annotations' path would be stored in `self.results`, which will be used to compute the metrics when all batches have been processed.
147147

148-
#### CitysMetric.compute_metrics
148+
#### CityscapesMetric.compute_metrics
149149

150150
This method would call `cityscapesscripts.evaluation.evalPixelLevelSemanticLabeling` tool to calculate metrics.
151151

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,158 @@
11
# 模型评测
22

3-
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/evaluation.md)
3+
模型评测过程会分别在 [ValLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L300)[TestLoop](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L373) 中被执行,用户可以在训练期间或使用配置文件中简单设置的测试脚本进行模型性能评估。`ValLoop``TestLoop` 属于 [Runner](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L59),它们会在第一次被调用时构建。由于 `dataloader``evaluator` 是必需的参数,所以要成功构建 `ValLoop`,在构建 `Runner` 时必须设置 `val_dataloader``val_evaluator``TestLoop` 亦然。有关 Runner 设计的更多信息,请参阅 [MMEngine](https://github.com/open-mmlab/mmengine)[文档](https://github.com/open-mmlab/mmengine/blob/main/docs/zh_cn/design/runner.md)
4+
5+
<center>
6+
<img src='../../../resources/test_step.png' />
7+
<center>测试/验证 数据流</center>
8+
</center>
9+
10+
在 MMSegmentation 中,默认情况下,我们将 dataloader 和 metrics 的设置写在数据集配置文件中,并将 evaluation loop 的配置写在 `schedule_x` 配置文件中。
11+
12+
例如,在 ADE20K 配置文件 `configs/_base_/dataset/ADE20K.py` 中,在第37到48行,我们配置了 `val_dataloader`,在第51行,我们选择 `IoUMetric` 作为 evaluator,并设置 `mIoU` 作为指标:
13+
14+
```python
15+
val_dataloader = dict(
16+
batch_size=1,
17+
num_workers=4,
18+
persistent_workers=True,
19+
sampler=dict(type='DefaultSampler', shuffle=False),
20+
dataset=dict(
21+
type=dataset_type,
22+
data_root=data_root,
23+
data_prefix=dict(
24+
img_path='images/validation',
25+
seg_map_path='annotations/validation'),
26+
pipeline=test_pipeline))
27+
28+
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
29+
```
30+
31+
为了能够在训练期间进行评估模型,我们将评估配置添加到了 `configs/schedules/schedule_40k.py` 文件的第15至16行:
32+
33+
```python
34+
train_cfg = dict(type='IterBasedTrainLoop', max_iters=40000, val_interval=4000)
35+
val_cfg = dict(type='ValLoop')
36+
```
37+
38+
使用以上两种设置,MMSegmentation 在 40K 迭代训练期间,每 4000 次迭代进行一次模型 **mIoU** 指标的评估。
39+
40+
如果我们希望在训练后测试模型,则需要将 `test_dataloader``test_evaluator``test_cfg` 配置添加到配置文件中。
41+
42+
```python
43+
test_dataloader = dict(
44+
batch_size=1,
45+
num_workers=4,
46+
persistent_workers=True,
47+
sampler=dict(type='DefaultSampler', shuffle=False),
48+
dataset=dict(
49+
type=dataset_type,
50+
data_root=data_root,
51+
data_prefix=dict(
52+
img_path='images/validation',
53+
seg_map_path='annotations/validation'),
54+
pipeline=test_pipeline))
55+
56+
test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
57+
test_cfg = dict(type='TestLoop')
58+
```
59+
60+
在 MMSegmentation 中,默认情况下,`test_dataloader``test_evaluator` 的设置与 `ValLoop` 的 dataloader 和 evaluator 相同,我们可以修改这些设置以满足我们的需要。
61+
62+
## IoUMetric
63+
64+
MMSegmentation 基于 [MMEngine](https://github.com/open-mmlab/mmengine) 提供的 [BaseMetric](https://github.com/open-mmlab/mmengine/blob/main/mmengine/evaluator/metric.py) 实现 [IoUMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/iou_metric.py)[CityscapesMetric](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/evaluation/metrics/citys_metric.py),以评估模型的性能。有关统一评估接口的更多详细信息,请参阅[文档](https://mmengine.readthedocs.io/zh_CN/latest/tutorials/evaluation.html)
65+
66+
这里我们简要介绍 `IoUMetric` 的参数和两种主要方法。
67+
68+
除了 `collect_device``prefix` 之外,`IoUMetric` 的构建还包含一些其他参数。
69+
70+
构造函数的参数:
71+
72+
- ignore_index(int)- 将在评估中忽略的类别索引。默认值:255。
73+
- iou_metrics(list\[str\] | str)- 需要计算的指标,可选项包括 'mIoU'、'mDice' 和 'mFscore'。
74+
- nan_to_num(int,可选)- 如果指定,NaN 值将被用户定义的数字替换。默认值:None。
75+
- beta(int)- 决定综合评分中 recall 的权重。默认值:1。
76+
- collect_device(str)- 用于在分布式训练期间从不同进程收集结果的设备名称。必须是 'cpu' 或 'gpu'。默认为 'cpu'。
77+
- prefix(str,可选)- 将添加到指标名称中的前缀,以消除不同 evaluator 的同名指标的歧义。如果参数中未提供前缀,则将使用 self.default_prefix 进行替代。默认为 None。
78+
79+
`IoUMetric` 实现 IoU 指标的计算,`IoUMetric` 的两个核心方法是 `process``compute_metrics`
80+
81+
- `process` 方法处理一批 data 和 data_samples。
82+
- `compute_metrics` 方法根据处理的结果计算指标。
83+
84+
### IoUMetric.process
85+
86+
参数:
87+
88+
- data_batch(Any)- 来自 dataloader 的一批数据。
89+
- data_samples(Sequence\[dict\])- 模型的一批输出。
90+
91+
返回值:
92+
93+
此方法没有返回值,因为处理的结果将存储在 `self.results` 中,以在处理完所有批次后进行指标的计算。
94+
95+
### IoUMetric.compute_metrics
96+
97+
参数:
98+
99+
- results(list)- 每个批次的处理结果。
100+
101+
返回值:
102+
103+
- Dict\[str,float\] - 计算的指标。指标的名称为 key,值是相应的结果。key 主要包括 **aAcc****mIoU****mAcc****mDice****mFscore****mPrecision****mPrecall**
104+
105+
## CityscapesMetric
106+
107+
`CityscapesMetric` 使用由 Cityscapes 官方提供的 [CityscapesScripts](https://github.com/mcordts/cityscapesScripts) 进行模型性能的评估。
108+
109+
### 使用方法
110+
111+
在使用之前,请先安装 `cityscapesscripts` 包:
112+
113+
```shell
114+
pip install cityscapesscripts
115+
```
116+
117+
由于 `IoUMetric` 在 MMSegmentation 中作为默认的 evaluator 使用,如果您想使用 `CityscapesMetric`,则需要自定义配置文件。在自定义配置文件中,应按如下方式替换默认 evaluator。
118+
119+
```python
120+
val_evaluator = dict(type='CityscapesMetric', output_dir='tmp')
121+
test_evaluator = val_evaluator
122+
```
123+
124+
### 接口
125+
126+
构造函数的参数:
127+
128+
- output_dir (str) - 预测结果输出的路径
129+
- ignore_index (int) - 将在评估中忽略的类别索引。默认值:255。
130+
- format_only (bool) - 只为提交进行结果格式化而不进行评估。当您希望将结果格式化为特定格式并将其提交给测试服务器时有用。默认为 False。
131+
- keep_results (bool) - 是否保留结果。当 `format_only` 为 True 时,`keep_results` 必须为 True。默认为 False。
132+
- collect_device (str) - 用于在分布式训练期间从不同进程收集结果的设备名称。必须是 'cpu' 或 'gpu'。默认为 'cpu'。
133+
- prefix (str,可选) - 将添加到指标名称中的前缀,以消除不同 evaluator 的同名指标的歧义。如果参数中未提供前缀,则将使用 self.default_prefix 进行替代。默认为 None。
134+
135+
#### CityscapesMetric.process
136+
137+
该方法将在图像上绘制 mask,并将绘制的图像保存到 `work_dir` 中。
138+
139+
参数:
140+
141+
- data_batch(dict)- 来自 dataloader 的一批数据。
142+
- data_samples(Sequence\[dict\])- 模型的一批输出。
143+
144+
返回值:
145+
146+
此方法没有返回值,因为处理的结果将存储在 `self.results` 中,以在处理完所有批次后进行指标的计算。
147+
148+
#### CityscapesMetric.compute_metrics
149+
150+
此方法将调用 `cityscapessscripts.evaluation.evalPixelLevelSemanticLabeling` 工具来计算指标。
151+
152+
参数:
153+
154+
- results(list)- 数据集的测试结果。
155+
156+
返回值:
157+
158+
- dict\[str:float\] - Cityscapes 评测结果。

0 commit comments

Comments
 (0)