[Doc] Refine MMSegmentation documentation (#2668)
parent
310ec4afc7
commit
aaa08dc4b2
|
@ -1,4 +1,4 @@
|
|||
# Add New Datasets
|
||||
# \[WIP\] Add New Datasets
|
||||
|
||||
## Customize datasets by reorganizing data
|
||||
|
|
@ -0,0 +1 @@
|
|||
# Add New Metrics
|
|
@ -1,37 +0,0 @@
|
|||
# Adding New Data Transforms
|
||||
|
||||
1. Write a new pipeline in any file, e.g., `my_pipeline.py`. It takes a dict as input and return a dict.
|
||||
|
||||
```python
|
||||
from mmseg.datasets import TRANSFORMS
|
||||
@TRANSFORMS.register_module()
|
||||
class MyTransform:
|
||||
def transform(self, results):
|
||||
results['dummy'] = True
|
||||
return results
|
||||
```
|
||||
|
||||
2. Import the new class.
|
||||
|
||||
```python
|
||||
from .my_pipeline import MyTransform
|
||||
```
|
||||
|
||||
3. Use it in config files.
|
||||
|
||||
```python
|
||||
crop_size = (512, 1024)
|
||||
train_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='RandomResize',
|
||||
scale=(2048, 1024),
|
||||
ratio_range=(0.5, 2.0),
|
||||
keep_ratio=True),
|
||||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
|
||||
dict(type='RandomFlip', flip_ratio=0.5),
|
||||
dict(type='PhotoMetricDistortion'),
|
||||
dict(type='MyTransform'),
|
||||
dict(type='PackSegInputs'),
|
||||
]
|
||||
```
|
|
@ -0,0 +1,52 @@
|
|||
# Adding New Data Transforms
|
||||
|
||||
## Customization data transformation
|
||||
|
||||
The customized data transformation must inherited from `BaseTransform` and implement `transform` function.
|
||||
Here we use a simple flipping transformation as example:
|
||||
|
||||
```python
|
||||
import random
|
||||
import mmcv
|
||||
from mmcv.transforms import BaseTransform, TRANSFORMS
|
||||
|
||||
@TRANSFORMS.register_module()
|
||||
class MyFlip(BaseTransform):
|
||||
def __init__(self, direction: str):
|
||||
super().__init__()
|
||||
self.direction = direction
|
||||
|
||||
def transform(self, results: dict) -> dict:
|
||||
img = results['img']
|
||||
results['img'] = mmcv.imflip(img, direction=self.direction)
|
||||
return results
|
||||
```
|
||||
|
||||
Moreover, import the new class.
|
||||
|
||||
```python
|
||||
from .my_pipeline import MyFlip
|
||||
```
|
||||
|
||||
Thus, we can instantiate a `MyFlip` object and use it to process the data dict.
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
transform = MyFlip(direction='horizontal')
|
||||
data_dict = {'img': np.random.rand(224, 224, 3)}
|
||||
data_dict = transform(data_dict)
|
||||
processed_img = data_dict['img']
|
||||
```
|
||||
|
||||
Or, we can use `MyFlip` transformation in data pipeline in our config file.
|
||||
|
||||
```python
|
||||
pipeline = [
|
||||
...
|
||||
dict(type='MyFlip', direction='horizontal'),
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
Note that if you want to use `MyFlip` in config, you must ensure the file containing `MyFlip` is imported during runtime.
|
|
@ -81,7 +81,7 @@ The arguments of the constructor:
|
|||
- `process` method processes one batch of data and data_samples.
|
||||
- `compute_metrics` method computes the metrics from processed results.
|
||||
|
||||
#### IoUMetric.process
|
||||
### IoUMetric.process
|
||||
|
||||
Parameters:
|
||||
|
||||
|
@ -92,7 +92,7 @@ Returns:
|
|||
|
||||
This method doesn't have returns since the processed results would be stored in `self.results`, which will be used to compute the metrics when all batches have been processed.
|
||||
|
||||
#### IoUMetric.compute_metrics
|
||||
### IoUMetric.compute_metrics
|
||||
|
||||
Parameters:
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ Component Customization
|
|||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
add_modules.md
|
||||
add_models.md
|
||||
add_datasets.md
|
||||
add_transforms.md
|
||||
add_metrics.md
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Training Tricks
|
||||
# \[WIP\] Training Tricks
|
||||
|
||||
MMSegmentation support following training tricks out of box.
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@ The structure of this guide is as follows:
|
|||
|
||||
- [Data Transforms](#data-transforms)
|
||||
- [Design of Data pipelines](#design-of-data-pipelines)
|
||||
- [Customization data transformation](#customization-data-transformation)
|
||||
- [Data loading](#data-loading)
|
||||
- [Pre-processing](#pre-processing)
|
||||
- [Formatting](#formatting)
|
||||
|
||||
## Design of Data pipelines
|
||||
|
||||
|
@ -125,48 +127,3 @@ The position of random contrast is in second or second to last(mode 0 or 1 below
|
|||
|
||||
- add: `inputs`, `data_sample`
|
||||
- remove: keys specified by `meta_keys` (merged into the metainfo of data_sample), all other keys
|
||||
|
||||
## Customization data transformation
|
||||
|
||||
The customized data transformation must inherited from `BaseTransform` and implement `transform` function.
|
||||
Here we use a simple flipping transformation as example:
|
||||
|
||||
```python
|
||||
import random
|
||||
import mmcv
|
||||
from mmcv.transforms import BaseTransform, TRANSFORMS
|
||||
|
||||
@TRANSFORMS.register_module()
|
||||
class MyFlip(BaseTransform):
|
||||
def __init__(self, direction: str):
|
||||
super().__init__()
|
||||
self.direction = direction
|
||||
|
||||
def transform(self, results: dict) -> dict:
|
||||
img = results['img']
|
||||
results['img'] = mmcv.imflip(img, direction=self.direction)
|
||||
return results
|
||||
```
|
||||
|
||||
Thus, we can instantiate a `MyFlip` object and use it to process the data dict.
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
transform = MyFlip(direction='horizontal')
|
||||
data_dict = {'img': np.random.rand(224, 224, 3)}
|
||||
data_dict = transform(data_dict)
|
||||
processed_img = data_dict['img']
|
||||
```
|
||||
|
||||
Or, we can use `MyFlip` transformation in data pipeline in our config file.
|
||||
|
||||
```python
|
||||
pipeline = [
|
||||
...
|
||||
dict(type='MyFlip', direction='horizontal'),
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
Note that if you want to use `MyFlip` in config, you must ensure the file containing `MyFlip` is imported during runtime.
|
||||
|
|
|
@ -11,11 +11,6 @@ datasets
|
|||
.. automodule:: mmseg.datasets
|
||||
:members:
|
||||
|
||||
samplers
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets.samplers
|
||||
:members:
|
||||
|
||||
transforms
|
||||
^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets.transforms
|
||||
|
@ -35,7 +30,7 @@ optimizers
|
|||
:members:
|
||||
|
||||
mmseg.evaluation
|
||||
--------------
|
||||
-----------------
|
||||
|
||||
metrics
|
||||
^^^^^^^^^^
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
# Model Zoo Statistics
|
||||
|
||||
- Number of papers: 47
|
||||
|
||||
- ALGORITHM: 36
|
||||
- BACKBONE: 11
|
||||
|
||||
- Number of checkpoints: 612
|
||||
|
||||
- \[ALGORITHM\] [ANN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ann) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [APCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/apcnet) (12 ckpts)
|
||||
|
||||
- \[BACKBONE\] [BEiT](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/beit) (2 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV1](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/bisenetv1) (11 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV2](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/bisenetv2) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ccnet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CGNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/cgnet) (2 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ConvNeXt](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/convnext) (6 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/danet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/deeplabv3) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3+](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/deeplabv3plus) (42 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DMNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dmnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DNLNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dnlnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DPT](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dpt) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EMANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/emanet) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EncNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/encnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ERFNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/erfnet) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FastFCN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastfcn) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastscnn) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FCN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fcn) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [GCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/gcnet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [HRNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/hrnet) (37 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ICNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/icnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ISANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/isanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [K-Net](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/knet) (7 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MAE](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mae) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Mask2Former](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mask2former) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [MaskFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/maskformer) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV2](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mobilenet_v2) (8 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV3](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mobilenet_v3) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [NonLocal Net](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/nonlocal_net) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [OCRNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ocrnet) (24 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PointRend](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/point_rend) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [PoolFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/psanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSPNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/pspnet) (54 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ResNeSt](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/resnest) (8 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SegFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/segformer) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Segmenter](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/segmenter) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Semantic FPN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/sem_fpn) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SETR](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/setr) (7 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [STDC](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/stdc) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Swin Transformer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/swin) (6 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Twins](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/twins) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/unet) (25 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UPerNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/upernet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Vision Transformer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/vit) (11 ckpts)
|
|
@ -1,4 +1,4 @@
|
|||
# Frequently Asked Questions (FAQ)
|
||||
# \[WIP\] Frequently Asked Questions (FAQ)
|
||||
|
||||
We list some common troubles faced by many users and their corresponding solutions here. Feel free to enrich the list if you find any frequent issues and have ways to help others to solve them. If the contents here do not cover your issue, please create an issue using the [provided templates](https://github.com/open-mmlab/mmsegmentation/blob/master/.github/ISSUE_TEMPLATE/error-report.md/) and make sure you fill in all required information in the template.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Deployment
|
||||
# \[WIP\] Deployment
|
||||
|
||||
> ## [Try the new MMDeploy to deploy your model](https://mmdeploy.readthedocs.io/)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Useful Tools
|
||||
# \[WIP\] Useful Tools
|
||||
|
||||
Apart from training/testing scripts, We provide lots of useful tools under the
|
||||
`tools/` directory.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 自定义数据集(待更新)
|
||||
# 新增自定义数据集(待更新)
|
||||
|
||||
## 通过重新组织数据来定制数据集
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
# 添加评测指标
|
|
@ -0,0 +1 @@
|
|||
# 新增评测指标 (待更新)
|
|
@ -0,0 +1,3 @@
|
|||
# 新增模块(待更新)
|
||||
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/add_models.md)
|
|
@ -1,230 +0,0 @@
|
|||
# 自定义模型(待更新)
|
||||
|
||||
## 自定义优化器 (optimizer)
|
||||
|
||||
假设您想增加一个新的叫 `MyOptimizer` 的优化器,它的参数分别为 `a`, `b`, 和 `c`。
|
||||
您首先需要在一个文件里实现这个新的优化器,例如在 `mmseg/core/optimizer/my_optimizer.py` 里面:
|
||||
|
||||
```python
|
||||
from mmcv.runner import OPTIMIZERS
|
||||
from torch.optim import Optimizer
|
||||
|
||||
|
||||
@OPTIMIZERS.register_module
|
||||
class MyOptimizer(Optimizer):
|
||||
|
||||
def __init__(self, a, b, c)
|
||||
|
||||
```
|
||||
|
||||
然后增加这个模块到 `mmseg/core/optimizer/__init__.py` 里面,这样注册器 (registry) 将会发现这个新的模块并添加它:
|
||||
|
||||
```python
|
||||
from .my_optimizer import MyOptimizer
|
||||
```
|
||||
|
||||
之后您可以在配置文件的 `optimizer` 域里使用 `MyOptimizer`,
|
||||
如下所示,在配置文件里,优化器被 `optimizer` 域所定义:
|
||||
|
||||
```python
|
||||
optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001)
|
||||
```
|
||||
|
||||
为了使用您自己的优化器,域可以被修改为:
|
||||
|
||||
```python
|
||||
optimizer = dict(type='MyOptimizer', a=a_value, b=b_value, c=c_value)
|
||||
```
|
||||
|
||||
我们已经支持了 PyTorch 自带的全部优化器,唯一修改的地方是在配置文件里的 `optimizer` 域。例如,如果您想使用 `ADAM`,尽管数值表现会掉点,还是可以如下修改:
|
||||
|
||||
```python
|
||||
optimizer = dict(type='Adam', lr=0.0003, weight_decay=0.0001)
|
||||
```
|
||||
|
||||
使用者可以直接按照 PyTorch [文档教程](https://pytorch.org/docs/stable/optim.html?highlight=optim#module-torch.optim) 去设置参数。
|
||||
|
||||
## 定制优化器的构造器 (optimizer constructor)
|
||||
|
||||
对于优化,一些模型可能会有一些特别定义的参数,例如批归一化 (BatchNorm) 层里面的权重衰减 (weight decay)。
|
||||
使用者可以通过定制优化器的构造器来微调这些细粒度的优化器参数。
|
||||
|
||||
```python
|
||||
from mmcv.utils import build_from_cfg
|
||||
|
||||
from mmcv.runner import OPTIMIZER_BUILDERS
|
||||
from .cocktail_optimizer import CocktailOptimizer
|
||||
|
||||
|
||||
@OPTIMIZER_BUILDERS.register_module
|
||||
class CocktailOptimizerConstructor(object):
|
||||
|
||||
def __init__(self, optim_wrapper_cfg, paramwise_cfg=None):
|
||||
|
||||
def __call__(self, model):
|
||||
|
||||
return my_optimizer
|
||||
|
||||
```
|
||||
|
||||
## 开发和增加新的组件(Module)
|
||||
|
||||
MMSegmentation 里主要有2种组件:
|
||||
|
||||
- 主干网络 (backbone): 通常是卷积网络的堆叠,来做特征提取,例如 ResNet, HRNet
|
||||
- 解码头 (decoder head): 用于语义分割图的解码的组件(得到分割结果)
|
||||
|
||||
### 添加新的主干网络
|
||||
|
||||
这里我们以 MobileNet 为例,展示如何增加新的主干组件:
|
||||
|
||||
1. 创建一个新的文件 `mmseg/models/backbones/mobilenet.py`
|
||||
|
||||
```python
|
||||
import torch.nn as nn
|
||||
|
||||
from ..registry import BACKBONES
|
||||
|
||||
|
||||
@BACKBONES.register_module
|
||||
class MobileNet(nn.Module):
|
||||
|
||||
def __init__(self, arg1, arg2):
|
||||
pass
|
||||
|
||||
def forward(self, x): # should return a tuple
|
||||
pass
|
||||
|
||||
def init_weights(self, pretrained=None):
|
||||
pass
|
||||
```
|
||||
|
||||
2. 在 `mmseg/models/backbones/__init__.py` 里面导入模块
|
||||
|
||||
```python
|
||||
from .mobilenet import MobileNet
|
||||
```
|
||||
|
||||
3. 在您的配置文件里使用它
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
...
|
||||
backbone=dict(
|
||||
type='MobileNet',
|
||||
arg1=xxx,
|
||||
arg2=xxx),
|
||||
...
|
||||
```
|
||||
|
||||
### 增加新的解码头 (decoder head)组件
|
||||
|
||||
在 MMSegmentation 里面,对于所有的分割头,我们提供一个基类解码头 [BaseDecodeHead](https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/models/decode_heads/decode_head.py) 。
|
||||
所有新建的解码头都应该继承它。这里我们以 [PSPNet](https://arxiv.org/abs/1612.01105) 为例,
|
||||
展示如何开发和增加一个新的解码头组件:
|
||||
|
||||
首先,在 `mmseg/models/decode_heads/psp_head.py` 里添加一个新的解码头。
|
||||
PSPNet 中实现了一个语义分割的解码头。为了实现一个解码头,我们只需要在新构造的解码头中实现如下的3个函数:
|
||||
|
||||
```python
|
||||
@HEADS.register_module()
|
||||
class PSPHead(BaseDecodeHead):
|
||||
|
||||
def __init__(self, pool_scales=(1, 2, 3, 6), **kwargs):
|
||||
super(PSPHead, self).__init__(**kwargs)
|
||||
|
||||
def init_weights(self):
|
||||
|
||||
def forward(self, inputs):
|
||||
|
||||
```
|
||||
|
||||
接着,使用者需要在 `mmseg/models/decode_heads/__init__.py` 里面添加这个模块,这样对应的注册器 (registry) 可以查找并加载它们。
|
||||
|
||||
PSPNet的配置文件如下所示:
|
||||
|
||||
```python
|
||||
norm_cfg = dict(type='SyncBN', requires_grad=True)
|
||||
model = dict(
|
||||
type='EncoderDecoder',
|
||||
pretrained='pretrain_model/resnet50_v1c_trick-2cccc1ad.pth',
|
||||
backbone=dict(
|
||||
type='ResNetV1c',
|
||||
depth=50,
|
||||
num_stages=4,
|
||||
out_indices=(0, 1, 2, 3),
|
||||
dilations=(1, 1, 2, 4),
|
||||
strides=(1, 2, 1, 1),
|
||||
norm_cfg=norm_cfg,
|
||||
norm_eval=False,
|
||||
style='pytorch',
|
||||
contract_dilation=True),
|
||||
decode_head=dict(
|
||||
type='PSPHead',
|
||||
in_channels=2048,
|
||||
in_index=3,
|
||||
channels=512,
|
||||
pool_scales=(1, 2, 3, 6),
|
||||
dropout_ratio=0.1,
|
||||
num_classes=19,
|
||||
norm_cfg=norm_cfg,
|
||||
align_corners=False,
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)))
|
||||
|
||||
```
|
||||
|
||||
### 增加新的损失函数
|
||||
|
||||
假设您想添加一个新的损失函数 `MyLoss` 到语义分割解码器里。
|
||||
为了添加一个新的损失函数,使用者需要在 `mmseg/models/losses/my_loss.py` 里面去实现它。
|
||||
`weighted_loss` 可以对计算损失时的每个样本做加权。
|
||||
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from ..builder import LOSSES
|
||||
from .utils import weighted_loss
|
||||
|
||||
@weighted_loss
|
||||
def my_loss(pred, target):
|
||||
assert pred.size() == target.size() and target.numel() > 0
|
||||
loss = torch.abs(pred - target)
|
||||
return loss
|
||||
|
||||
@LOSSES.register_module
|
||||
class MyLoss(nn.Module):
|
||||
|
||||
def __init__(self, reduction='mean', loss_weight=1.0):
|
||||
super(MyLoss, self).__init__()
|
||||
self.reduction = reduction
|
||||
self.loss_weight = loss_weight
|
||||
|
||||
def forward(self,
|
||||
pred,
|
||||
target,
|
||||
weight=None,
|
||||
avg_factor=None,
|
||||
reduction_override=None):
|
||||
assert reduction_override in (None, 'none', 'mean', 'sum')
|
||||
reduction = (
|
||||
reduction_override if reduction_override else self.reduction)
|
||||
loss = self.loss_weight * my_loss(
|
||||
pred, target, weight, reduction=reduction, avg_factor=avg_factor)
|
||||
return loss
|
||||
```
|
||||
|
||||
然后使用者需要在 `mmseg/models/losses/__init__.py` 里面添加它:
|
||||
|
||||
```python
|
||||
from .my_loss import MyLoss, my_loss
|
||||
|
||||
```
|
||||
|
||||
为了使用它,修改 `loss_xxx` 域。之后您需要在解码头组件里修改 `loss_decode` 域。
|
||||
`loss_weight` 可以被用来对不同的损失函数做加权。
|
||||
|
||||
```python
|
||||
loss_decode=dict(type='MyLoss', loss_weight=1.0))
|
||||
```
|
|
@ -1,166 +1,3 @@
|
|||
# 自定义数据流程(待更新)
|
||||
# 新增数据增强(待更新)
|
||||
|
||||
## 数据流程的设计
|
||||
|
||||
按照通常的惯例,我们使用 `Dataset` 和 `DataLoader` 做多线程的数据加载。`Dataset` 返回一个数据内容的字典,里面对应于模型前传方法的各个参数。
|
||||
因为在语义分割中,输入的图像数据具有不同的大小,我们在 MMCV 里引入一个新的 `DataContainer` 类别去帮助收集和分发不同大小的输入数据。
|
||||
|
||||
更多细节,请查看[这里](https://github.com/open-mmlab/mmcv/blob/master/mmcv/parallel/data_container.py) 。
|
||||
|
||||
数据的准备流程和数据集是解耦的。通常一个数据集定义了如何处理标注数据(annotations)信息,而一个数据流程定义了准备一个数据字典的所有步骤。一个流程包括了一系列操作,每个操作里都把一个字典作为输入,然后再输出一个新的字典给下一个变换操作。
|
||||
|
||||
这些操作可分为数据加载 (data loading),预处理 (pre-processing),格式变化 (formatting) 和测试时数据增强 (test-time augmentation)。
|
||||
|
||||
下面的例子就是 PSPNet 的一个流程:
|
||||
|
||||
```python
|
||||
img_norm_cfg = dict(
|
||||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
|
||||
crop_size = (512, 1024)
|
||||
train_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='Resize', img_scale=(2048, 1024), ratio_range=(0.5, 2.0)),
|
||||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
|
||||
dict(type='RandomFlip', flip_ratio=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']),
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(
|
||||
type='MultiScaleFlipAug',
|
||||
img_scale=(2048, 1024),
|
||||
# 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']),
|
||||
])
|
||||
]
|
||||
```
|
||||
|
||||
对于每个操作,我们列出它添加、更新、移除的相关字典域 (dict fields):
|
||||
|
||||
### 数据加载 Data loading
|
||||
|
||||
`LoadImageFromFile`
|
||||
|
||||
- 增加: img, img_shape, ori_shape
|
||||
|
||||
`LoadAnnotations`
|
||||
|
||||
- 增加: gt_semantic_seg, seg_fields
|
||||
|
||||
### 预处理 Pre-processing
|
||||
|
||||
`Resize`
|
||||
|
||||
- 增加: scale, scale_idx, pad_shape, scale_factor, keep_ratio
|
||||
- 更新: img, img_shape, \*seg_fields
|
||||
|
||||
`RandomFlip`
|
||||
|
||||
- 增加: flip
|
||||
- 更新: img, \*seg_fields
|
||||
|
||||
`Pad`
|
||||
|
||||
- 增加: pad_fixed_size, pad_size_divisor
|
||||
- 更新: img, pad_shape, \*seg_fields
|
||||
|
||||
`RandomCrop`
|
||||
|
||||
- 更新: img, pad_shape, \*seg_fields
|
||||
|
||||
`Normalize`
|
||||
|
||||
- 增加: img_norm_cfg
|
||||
- 更新: img
|
||||
|
||||
`SegRescale`
|
||||
|
||||
- 更新: gt_semantic_seg
|
||||
|
||||
`PhotoMetricDistortion`
|
||||
|
||||
- 更新: img
|
||||
|
||||
### 格式 Formatting
|
||||
|
||||
`ToTensor`
|
||||
|
||||
- 更新: 由 `keys` 指定
|
||||
|
||||
`ImageToTensor`
|
||||
|
||||
- 更新: 由 `keys` 指定
|
||||
|
||||
`Transpose`
|
||||
|
||||
- 更新: 由 `keys` 指定
|
||||
|
||||
`ToDataContainer`
|
||||
|
||||
- 更新: 由 `keys` 指定
|
||||
|
||||
`DefaultFormatBundle`
|
||||
|
||||
- 更新: img, gt_semantic_seg
|
||||
|
||||
`Collect`
|
||||
|
||||
- 增加: img_meta (the keys of img_meta is specified by `meta_keys`)
|
||||
- 移除: all other keys except for those specified by `keys`
|
||||
|
||||
### 测试时数据增强 Test time augmentation
|
||||
|
||||
`MultiScaleFlipAug`
|
||||
|
||||
## 拓展和使用自定义的流程
|
||||
|
||||
1. 在任何一个文件里写一个新的流程,例如 `my_pipeline.py`,它以一个字典作为输入并且输出一个字典
|
||||
|
||||
```python
|
||||
from mmseg.datasets import PIPELINES
|
||||
|
||||
@PIPELINES.register_module()
|
||||
class MyTransform:
|
||||
|
||||
def __call__(self, results):
|
||||
results['dummy'] = True
|
||||
return results
|
||||
```
|
||||
|
||||
2. 导入一个新类
|
||||
|
||||
```python
|
||||
from .my_pipeline import MyTransform
|
||||
```
|
||||
|
||||
3. 在配置文件里使用它
|
||||
|
||||
```python
|
||||
img_norm_cfg = dict(
|
||||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
|
||||
crop_size = (512, 1024)
|
||||
train_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='Resize', img_scale=(2048, 1024), ratio_range=(0.5, 2.0)),
|
||||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
|
||||
dict(type='RandomFlip', flip_ratio=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='MyTransform'),
|
||||
dict(type='DefaultFormatBundle'),
|
||||
dict(type='Collect', keys=['img', 'gt_semantic_seg']),
|
||||
]
|
||||
```
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/add_transform.md)
|
||||
|
|
|
@ -43,7 +43,7 @@ dict(
|
|||
|
||||
### 数据预处理器到模型
|
||||
|
||||
虽然在[上面的图](#数据流概述)中分开绘制了数据预处理器和模型,但数据预处理器是模型的一部分,因此可以在[模型教程](https://mmsegmentation.readthedocs.io/en/dev-1.x/advanced_guides/models.html)中找到数据预处理器章节。 ***([中文链接待更新](https://mmsegmentation.readthedocs.io/zh_CN/dev-1.x/advanced_guides/models.html))***
|
||||
虽然在[上面的图](##数据流概述)中分开绘制了数据预处理器和模型,但数据预处理器是模型的一部分,因此可以在[模型教程](https://mmsegmentation.readthedocs.io/en/dev-1.x/advanced_guides/models.html)中找到数据预处理器章节。 ***([中文链接待更新](https://mmsegmentation.readthedocs.io/zh_CN/dev-1.x/advanced_guides/models.html))***
|
||||
|
||||
数据预处理器的返回值是一个包含 `inputs` 和 `data_samples` 的字典,其中 `inputs` 是批处理图像的 4D 张量,`data_samples` 中添加了一些用于数据预处理的额外元信息。当传递给网络时,字典将被解包为两个值。 以下伪代码展示了数据预处理器的返回值和模型的输入值。
|
||||
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
# 模型评测
|
||||
# 模型评测
|
||||
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/evaluation.md)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
add_modules.md
|
||||
add_models.md
|
||||
add_datasets.md
|
||||
add_transforms.md
|
||||
add_metrics.md
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
# 模型
|
||||
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/models.md)
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
# 数据增广
|
||||
# 数据增强变化
|
||||
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/advanced_guides/transforms.md)
|
||||
|
|
|
@ -11,11 +11,6 @@ datasets
|
|||
.. automodule:: mmseg.datasets
|
||||
:members:
|
||||
|
||||
samplers
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets.samplers
|
||||
:members:
|
||||
|
||||
transforms
|
||||
^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets.transforms
|
||||
|
|
|
@ -34,7 +34,7 @@ conda install pytorch torchvision cpuonly -c pytorch
|
|||
|
||||
## 安装
|
||||
|
||||
我们建议用户遵循我们的最佳实践来安装 MMSegmentation 。但是整个过程是高度自定义的。更多信息请参见[自定义安装](#自定义安装)部分。
|
||||
我们建议用户遵循我们的最佳实践来安装 MMSegmentation 。但是整个过程是高度自定义的。更多信息请参见[自定义安装](##自定义安装)部分。
|
||||
|
||||
### 最佳实践
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
# 模型库统计数据
|
||||
|
||||
- 论文数量: 47
|
||||
|
||||
- ALGORITHM: 36
|
||||
- BACKBONE: 11
|
||||
|
||||
- 模型数量: 612
|
||||
|
||||
- \[ALGORITHM\] [ANN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ann) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [APCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/apcnet) (12 ckpts)
|
||||
|
||||
- \[BACKBONE\] [BEiT](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/beit) (2 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV1](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/bisenetv1) (11 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV2](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/bisenetv2) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ccnet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CGNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/cgnet) (2 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ConvNeXt](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/convnext) (6 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/danet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/deeplabv3) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3+](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/deeplabv3plus) (42 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DMNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dmnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DNLNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dnlnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DPT](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/dpt) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EMANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/emanet) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EncNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/encnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ERFNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/erfnet) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FastFCN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastfcn) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastscnn) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FCN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fcn) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [GCNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/gcnet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [HRNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/hrnet) (37 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ICNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/icnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ISANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/isanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [K-Net](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/knet) (7 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MAE](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mae) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Mask2Former](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mask2former) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [MaskFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/maskformer) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV2](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mobilenet_v2) (8 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV3](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/mobilenet_v3) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [NonLocal Net](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/nonlocal_net) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [OCRNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/ocrnet) (24 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PointRend](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/point_rend) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [PoolFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSANet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/psanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSPNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/pspnet) (54 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ResNeSt](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/resnest) (8 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SegFormer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/segformer) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Segmenter](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/segmenter) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Semantic FPN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/sem_fpn) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SETR](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/setr) (7 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [STDC](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/stdc) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Swin Transformer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/swin) (6 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Twins](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/twins) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/unet) (25 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UPerNet](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/upernet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Vision Transformer](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/vit) (11 ckpts)
|
|
@ -1,453 +1,3 @@
|
|||
## 准备数据集(待更新)
|
||||
|
||||
推荐用软链接,将数据集根目录链接到 `$MMSEGMENTATION/data` 里。如果您的文件夹结构是不同的,您也许可以试着修改配置文件里对应的路径。
|
||||
|
||||
```none
|
||||
mmsegmentation
|
||||
├── mmseg
|
||||
├── tools
|
||||
├── configs
|
||||
├── data
|
||||
│ ├── cityscapes
|
||||
│ │ ├── leftImg8bit
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ ├── gtFine
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── VOCdevkit
|
||||
│ │ ├── VOC2012
|
||||
│ │ │ ├── JPEGImages
|
||||
│ │ │ ├── SegmentationClass
|
||||
│ │ │ ├── ImageSets
|
||||
│ │ │ │ ├── Segmentation
|
||||
│ │ ├── VOC2010
|
||||
│ │ │ ├── JPEGImages
|
||||
│ │ │ ├── SegmentationClassContext
|
||||
│ │ │ ├── ImageSets
|
||||
│ │ │ │ ├── SegmentationContext
|
||||
│ │ │ │ │ ├── train.txt
|
||||
│ │ │ │ │ ├── val.txt
|
||||
│ │ │ ├── trainval_merged.json
|
||||
│ │ ├── VOCaug
|
||||
│ │ │ ├── dataset
|
||||
│ │ │ │ ├── cls
|
||||
│ ├── ade
|
||||
│ │ ├── ADEChallengeData2016
|
||||
│ │ │ ├── annotations
|
||||
│ │ │ │ ├── training
|
||||
│ │ │ │ ├── validation
|
||||
│ │ │ ├── images
|
||||
│ │ │ │ ├── training
|
||||
│ │ │ │ ├── validation
|
||||
│ ├── CHASE_DB1
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ ├── DRIVE
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ ├── HRF
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ ├── STARE
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
| ├── dark_zurich
|
||||
| │ ├── gps
|
||||
| │ │ ├── val
|
||||
| │ │ └── val_ref
|
||||
| │ ├── gt
|
||||
| │ │ └── val
|
||||
| │ ├── LICENSE.txt
|
||||
| │ ├── lists_file_names
|
||||
| │ │ ├── val_filenames.txt
|
||||
| │ │ └── val_ref_filenames.txt
|
||||
| │ ├── README.md
|
||||
| │ └── rgb_anon
|
||||
| │ | ├── val
|
||||
| │ | └── val_ref
|
||||
| ├── NighttimeDrivingTest
|
||||
| | ├── gtCoarse_daytime_trainvaltest
|
||||
| | │ └── test
|
||||
| | │ └── night
|
||||
| | └── leftImg8bit
|
||||
| | | └── test
|
||||
| | | └── night
|
||||
│ ├── loveDA
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ │ ├── test
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── potsdam
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── vaihingen
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── iSAID
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ │ ├── test
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── synapse
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── val
|
||||
│ ├── REFUGE
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
```
|
||||
|
||||
### Cityscapes
|
||||
|
||||
注册成功后,数据集可以在 [这里](https://www.cityscapes-dataset.com/downloads/) 下载。
|
||||
|
||||
通常情况下,`**labelTrainIds.png` 被用来训练 cityscapes。
|
||||
基于 [cityscapesscripts](https://github.com/mcordts/cityscapesScripts),
|
||||
我们提供了一个 [脚本](https://github.com/open-mmlab/mmsegmentation/blob/master/tools/convert_datasets/cityscapes.py),
|
||||
去生成 `**labelTrainIds.png`。
|
||||
|
||||
```shell
|
||||
# --nproc 8 意味着有 8 个进程用来转换,它也可以被忽略。
|
||||
python tools/convert_datasets/cityscapes.py data/cityscapes --nproc 8
|
||||
```
|
||||
|
||||
### Pascal VOC
|
||||
|
||||
Pascal VOC 2012 可以在 [这里](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar) 下载。
|
||||
此外,许多最近在 Pascal VOC 数据集上的工作都会利用增广的数据,它们可以在 [这里](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz) 找到。
|
||||
|
||||
如果您想使用增广后的 VOC 数据集,请运行下面的命令来将数据增广的标注转成正确的格式。
|
||||
|
||||
```shell
|
||||
# --nproc 8 意味着有 8 个进程用来转换,它也可以被忽略。
|
||||
python tools/convert_datasets/voc_aug.py data/VOCdevkit data/VOCdevkit/VOCaug --nproc 8
|
||||
```
|
||||
|
||||
关于如何拼接数据集 (concatenate) 并一起训练它们,更多细节请参考 [拼接连接数据集](https://github.com/open-mmlab/mmsegmentation/blob/master/docs/zh_cn/tutorials/customize_datasets.md#%E6%8B%BC%E6%8E%A5%E6%95%B0%E6%8D%AE%E9%9B%86) 。
|
||||
|
||||
### ADE20K
|
||||
|
||||
ADE20K 的训练集和验证集可以在 [这里](http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip) 下载。
|
||||
您还可以在 [这里](http://data.csail.mit.edu/places/ADEchallenge/release_test.zip) 下载验证集。
|
||||
|
||||
### Pascal Context
|
||||
|
||||
Pascal Context 的训练集和验证集可以在 [这里](http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar) 下载。
|
||||
注册成功后,您还可以在 [这里](http://host.robots.ox.ac.uk:8080/eval/downloads/VOC2010test.tar) 下载验证集。
|
||||
|
||||
为了从原始数据集里切分训练集和验证集, 您可以在 [这里](https://codalabuser.blob.core.windows.net/public/trainval_merged.json)
|
||||
下载 trainval_merged.json。
|
||||
|
||||
如果您想使用 Pascal Context 数据集,
|
||||
请安装 [细节](https://github.com/zhanghang1989/detail-api) 然后再运行如下命令来把标注转换成正确的格式。
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/pascal_context.py data/VOCdevkit data/VOCdevkit/VOC2010/trainval_merged.json
|
||||
```
|
||||
|
||||
### CHASE DB1
|
||||
|
||||
CHASE DB1 的训练集和验证集可以在 [这里](https://staffnet.kingston.ac.uk/~ku15565/CHASE_DB1/assets/CHASEDB1.zip) 下载。
|
||||
|
||||
为了将 CHASE DB1 数据集转换成 MMSegmentation 的格式,您需要运行如下命令:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/chase_db1.py /path/to/CHASEDB1.zip
|
||||
```
|
||||
|
||||
这个脚本将自动生成正确的文件夹结构。
|
||||
|
||||
### DRIVE
|
||||
|
||||
DRIVE 的训练集和验证集可以在 [这里](https://drive.grand-challenge.org/) 下载。
|
||||
在此之前,您需要注册一个账号,当前 '1st_manual' 并未被官方提供,因此需要您从其他地方获取。
|
||||
|
||||
为了将 DRIVE 数据集转换成 MMSegmentation 格式,您需要运行如下命令:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/drive.py /path/to/training.zip /path/to/test.zip
|
||||
```
|
||||
|
||||
这个脚本将自动生成正确的文件夹结构。
|
||||
|
||||
### HRF
|
||||
|
||||
首先,下载 [healthy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy.zip) [glaucoma.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma.zip), [diabetic_retinopathy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy.zip), [healthy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy_manualsegm.zip), [glaucoma_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma_manualsegm.zip) 以及 [diabetic_retinopathy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy_manualsegm.zip) 。
|
||||
|
||||
为了将 HRF 数据集转换成 MMSegmentation 格式,您需要运行如下命令:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/hrf.py /path/to/healthy.zip /path/to/healthy_manualsegm.zip /path/to/glaucoma.zip /path/to/glaucoma_manualsegm.zip /path/to/diabetic_retinopathy.zip /path/to/diabetic_retinopathy_manualsegm.zip
|
||||
```
|
||||
|
||||
这个脚本将自动生成正确的文件夹结构。
|
||||
|
||||
### STARE
|
||||
|
||||
首先,下载 [stare-images.tar](http://cecas.clemson.edu/~ahoover/stare/probing/stare-images.tar), [labels-ah.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-ah.tar) 和 [labels-vk.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-vk.tar) 。
|
||||
|
||||
为了将 STARE 数据集转换成 MMSegmentation 格式,您需要运行如下命令:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/stare.py /path/to/stare-images.tar /path/to/labels-ah.tar /path/to/labels-vk.tar
|
||||
```
|
||||
|
||||
这个脚本将自动生成正确的文件夹结构。
|
||||
|
||||
### Dark Zurich
|
||||
|
||||
因为我们只支持在此数据集上测试模型,所以您只需下载[验证集](https://data.vision.ee.ethz.ch/csakarid/shared/GCMA_UIoU/Dark_Zurich_val_anon.zip) 。
|
||||
|
||||
### Nighttime Driving
|
||||
|
||||
因为我们只支持在此数据集上测试模型,所以您只需下载[测试集](http://data.vision.ee.ethz.ch/daid/NighttimeDriving/NighttimeDrivingTest.zip) 。
|
||||
|
||||
### LoveDA
|
||||
|
||||
可以从 Google Drive 里下载 [LoveDA数据集](https://drive.google.com/drive/folders/1ibYV0qwn4yuuh068Rnc-w4tPi0U0c-ti?usp=sharing) 。
|
||||
|
||||
或者它还可以从 [zenodo](https://zenodo.org/record/5706578#.YZvN7SYRXdF) 下载, 您需要运行如下命令:
|
||||
|
||||
```shell
|
||||
# Download Train.zip
|
||||
wget https://zenodo.org/record/5706578/files/Train.zip
|
||||
# Download Val.zip
|
||||
wget https://zenodo.org/record/5706578/files/Val.zip
|
||||
# Download Test.zip
|
||||
wget https://zenodo.org/record/5706578/files/Test.zip
|
||||
```
|
||||
|
||||
对于 LoveDA 数据集,请运行以下命令下载并重新组织数据集
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/loveda.py /path/to/loveDA
|
||||
```
|
||||
|
||||
请参照 [这里](https://github.com/open-mmlab/mmsegmentation/blob/master/docs/zh_cn/inference.md) 来使用训练好的模型去预测 LoveDA 测试集并且提交到官网。
|
||||
|
||||
关于 LoveDA 的更多细节可以在[这里](https://github.com/Junjue-Wang/LoveDA) 找到。
|
||||
|
||||
### ISPRS Potsdam
|
||||
|
||||
[Potsdam](https://www2.isprs.org/commissions/comm2/wg4/benchmark/2d-sem-label-potsdam/)
|
||||
数据集是一个有着2D 语义分割内容标注的城市遥感数据集。
|
||||
数据集可以从挑战[主页](https://www2.isprs.org/commissions/comm2/wg4/benchmark/data-request-form/) 获得。
|
||||
需要其中的 '2_Ortho_RGB.zip' 和 '5_Labels_all_noBoundary.zip'。
|
||||
|
||||
对于 Potsdam 数据集,请运行以下命令下载并重新组织数据集
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/potsdam.py /path/to/potsdam
|
||||
```
|
||||
|
||||
使用我们默认的配置, 将生成 3456 张图片的训练集和 2016 张图片的验证集。
|
||||
|
||||
### ISPRS Vaihingen
|
||||
|
||||
[Vaihingen](https://www2.isprs.org/commissions/comm2/wg4/benchmark/2d-sem-label-vaihingen/)
|
||||
数据集是一个有着2D 语义分割内容标注的城市遥感数据集。
|
||||
|
||||
数据集可以从挑战 [主页](https://www2.isprs.org/commissions/comm2/wg4/benchmark/data-request-form/).
|
||||
需要其中的 'ISPRS_semantic_labeling_Vaihingen.zip' 和 'ISPRS_semantic_labeling_Vaihingen_ground_truth_eroded_COMPLETE.zip'。
|
||||
|
||||
对于 Vaihingen 数据集,请运行以下命令下载并重新组织数据集
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/vaihingen.py /path/to/vaihingen
|
||||
```
|
||||
|
||||
使用我们默认的配置 (`clip_size`=512, `stride_size`=256), 将生成 344 张图片的训练集和 398 张图片的验证集。
|
||||
|
||||
### iSAID
|
||||
|
||||
iSAID 数据集(训练集/验证集/测试集)的图像可以从 [DOTA-v1.0](https://captain-whu.github.io/DOTA/dataset.html) 下载.
|
||||
|
||||
iSAID 数据集(训练集/验证集)的注释可以从 [iSAID](https://captain-whu.github.io/iSAID/dataset.html) 下载.
|
||||
|
||||
该数据集是一个大规模的实例分割(也可以用于语义分割)的遥感数据集.
|
||||
|
||||
下载后,在数据集转换前,您需要将数据集文件夹调整成如下格式.
|
||||
|
||||
```
|
||||
│ ├── iSAID
|
||||
│ │ ├── train
|
||||
│ │ │ ├── images
|
||||
│ │ │ │ ├── part1.zip
|
||||
│ │ │ │ ├── part2.zip
|
||||
│ │ │ │ ├── part3.zip
|
||||
│ │ │ ├── Semantic_masks
|
||||
│ │ │ │ ├── images.zip
|
||||
│ │ ├── val
|
||||
│ │ │ ├── images
|
||||
│ │ │ │ ├── part1.zip
|
||||
│ │ │ ├── Semantic_masks
|
||||
│ │ │ │ ├── images.zip
|
||||
│ │ ├── test
|
||||
│ │ │ ├── images
|
||||
│ │ │ │ ├── part1.zip
|
||||
│ │ │ │ ├── part2.zip
|
||||
```
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/isaid.py /path/to/iSAID
|
||||
```
|
||||
|
||||
使用我们默认的配置 (`patch_width`=896, `patch_height`=896, `overlap_area`=384), 将生成 33,978 张图片的训练集和 11,644 张图片的验证集.
|
||||
|
||||
## Synapse dataset
|
||||
|
||||
这个数据集可以在这个[网页](https://www.synapse.org/#!Synapse:syn3193805/wiki/) 里被下载.
|
||||
我们参考了 [TransUNet](https://arxiv.org/abs/2102.04306) 里面的数据集预处理的设置, 它将原始数据集 (30 套 3D 样例) 切分出 18 套用于训练, 12 套用于验证. 请参考以下步骤来准备该数据集:
|
||||
|
||||
```shell
|
||||
unzip RawData.zip
|
||||
cd ./RawData/Training
|
||||
```
|
||||
|
||||
随后新建 `train.txt` 和 `val.txt`.
|
||||
|
||||
根据 TransUNet 来将训练集和验证集如下划分:
|
||||
|
||||
train.txt
|
||||
|
||||
```none
|
||||
img0005.nii.gz
|
||||
img0006.nii.gz
|
||||
img0007.nii.gz
|
||||
img0009.nii.gz
|
||||
img0010.nii.gz
|
||||
img0021.nii.gz
|
||||
img0023.nii.gz
|
||||
img0024.nii.gz
|
||||
img0026.nii.gz
|
||||
img0027.nii.gz
|
||||
img0028.nii.gz
|
||||
img0030.nii.gz
|
||||
img0031.nii.gz
|
||||
img0033.nii.gz
|
||||
img0034.nii.gz
|
||||
img0037.nii.gz
|
||||
img0039.nii.gz
|
||||
img0040.nii.gz
|
||||
```
|
||||
|
||||
val.txt
|
||||
|
||||
```none
|
||||
img0008.nii.gz
|
||||
img0022.nii.gz
|
||||
img0038.nii.gz
|
||||
img0036.nii.gz
|
||||
img0032.nii.gz
|
||||
img0002.nii.gz
|
||||
img0029.nii.gz
|
||||
img0003.nii.gz
|
||||
img0001.nii.gz
|
||||
img0004.nii.gz
|
||||
img0025.nii.gz
|
||||
img0035.nii.gz
|
||||
```
|
||||
|
||||
此时, synapse 数据集包括了以下内容:
|
||||
|
||||
```none
|
||||
├── Training
|
||||
│ ├── img
|
||||
│ │ ├── img0001.nii.gz
|
||||
│ │ ├── img0002.nii.gz
|
||||
│ │ ├── ...
|
||||
│ ├── label
|
||||
│ │ ├── label0001.nii.gz
|
||||
│ │ ├── label0002.nii.gz
|
||||
│ │ ├── ...
|
||||
│ ├── train.txt
|
||||
│ ├── val.txt
|
||||
```
|
||||
|
||||
随后, 运行下面的数据集转换脚本来处理 synapse 数据集:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/synapse.py --dataset-path /path/to/synapse
|
||||
```
|
||||
|
||||
使用我们默认的配置, 将生成 2,211 张 2D 图片的训练集和 1,568 张图片的验证集.
|
||||
|
||||
需要注意的是 MMSegmentation 默认的评价指标 (例如平均 Dice 值) 都是基于每帧 2D 图片计算的, 这与基于每套 3D 图片计算评价指标的 [TransUNet](https://arxiv.org/abs/2102.04306) 是不同的.
|
||||
|
||||
### REFUGE
|
||||
|
||||
在[官网](https://refuge.grand-challenge.org)注册后, 下载 [REFUGE 数据集](https://refuge.grand-challenge.org/REFUGE2Download) `REFUGE2.zip` , 解压后的内容如下:
|
||||
|
||||
```none
|
||||
├── REFUGE2
|
||||
│ ├── REFUGE2
|
||||
│ │ ├── Annotation-Training400.zip
|
||||
│ │ ├── REFUGE-Test400.zip
|
||||
│ │ ├── REFUGE-Test-GT.zip
|
||||
│ │ ├── REFUGE-Training400.zip
|
||||
│ │ ├── REFUGE-Validation400.zip
|
||||
│ │ ├── REFUGE-Validation400-GT.zip
|
||||
│ ├── __MACOSX
|
||||
```
|
||||
|
||||
运行如下命令,就可以按照 REFUGE2018 挑战赛划分数据集的标准将数据集切分成训练集、验证集、测试集:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/refuge.py --raw_data_root=/path/to/refuge/REFUGE2/REFUGE2
|
||||
```
|
||||
|
||||
这个脚本将自动生成下面的文件夹结构:
|
||||
|
||||
```none
|
||||
│ ├── REFUGE
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
```
|
||||
|
||||
其中包括 400 张图片的训练集, 400 张图片的验证集和 400 张图片的测试集.
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/user_guides/2_dataset_prepare.md)
|
||||
|
|
|
@ -1,127 +1,3 @@
|
|||
## 使用预训练模型推理(待更新)
|
||||
|
||||
我们提供测试脚本来评估完整数据集(Cityscapes, PASCAL VOC, ADE20k 等)上的结果,同时为了使其他项目的整合更容易,也提供一些高级 API。
|
||||
|
||||
### 测试一个数据集
|
||||
|
||||
- 单卡 GPU
|
||||
- CPU
|
||||
- 单节点多卡 GPU
|
||||
- 多节点
|
||||
|
||||
您可以使用以下命令来测试一个数据集。
|
||||
|
||||
```shell
|
||||
# 单卡 GPU 测试
|
||||
python tools/test.py ${配置文件} ${检查点文件} [--out ${结果文件}] [--eval ${评估指标}] [--show]
|
||||
|
||||
# CPU: 如果机器没有 GPU, 则跟上述单卡 GPU 测试一致
|
||||
# CPU: 如果机器有 GPU, 那么先禁用 GPU 再运行单 GPU 测试脚本
|
||||
export CUDA_VISIBLE_DEVICES=-1 # 禁用 GPU
|
||||
python tools/test.py ${配置文件} ${检查点文件} [--out ${结果文件}] [--eval ${评估指标}] [--show]
|
||||
|
||||
# 多卡GPU 测试
|
||||
./tools/dist_test.sh ${配置文件} ${检查点文件} ${GPU数目} [--out ${结果文件}] [--eval ${评估指标}]
|
||||
```
|
||||
|
||||
可选参数:
|
||||
|
||||
- `RESULT_FILE`: pickle 格式的输出结果的文件名,如果不专门指定,结果将不会被专门保存成文件。(MMseg v0.17 之后,args.out 将只会保存评估时的中间结果或者是分割图的保存路径。)
|
||||
- `EVAL_METRICS`: 在结果里将被评估的指标。这主要取决于数据集, `mIoU` 对于所有数据集都可获得,像 Cityscapes 数据集可以通过 `cityscapes` 命令来专门评估,就像标准的 `mIoU`一样。
|
||||
- `--show`: 如果被指定,分割结果将会在一张图像里画出来并且在另一个窗口展示。它仅仅是用来调试与可视化,并且仅针对单卡 GPU 测试。请确认 GUI 在您的环境里可用,否则您也许会遇到报错 `cannot connect to X server`
|
||||
- `--show-dir`: 如果被指定,分割结果将会在一张图像里画出来并且保存在指定文件夹里。它仅仅是用来调试与可视化,并且仅针对单卡GPU测试。使用该参数时,您的环境不需要 GUI。
|
||||
- `--eval-options`: 评估时的可选参数,当设置 `efficient_test=True` 时,它将会保存中间结果至本地文件里以节约 CPU 内存。请确认您本地硬盘有足够的存储空间(大于20GB)。(MMseg v0.17 之后,`efficient_test` 不再生效,我们重构了 test api,通过使用一种渐近式的方式来提升评估和保存结果的效率。)
|
||||
|
||||
例子:
|
||||
|
||||
假设您已经下载检查点文件至文件夹 `checkpoints/` 里。
|
||||
|
||||
1. 测试 PSPNet 并可视化结果。按下任何键会进行到下一张图
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||
--show
|
||||
```
|
||||
|
||||
2. 测试 PSPNet 并保存画出的图以便于之后的可视化
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||
--show-dir psp_r50_512x1024_40ki_cityscapes_results
|
||||
```
|
||||
|
||||
3. 在数据集 PASCAL VOC (不保存测试结果) 上测试 PSPNet 并评估 mIoU
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_20k_voc12aug.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_20k_voc12aug_20200605_003338-c57ef100.pth \
|
||||
--eval mAP
|
||||
```
|
||||
|
||||
4. 使用4卡 GPU 测试 PSPNet,并且在标准 mIoU 和 cityscapes 指标里评估模型
|
||||
|
||||
```shell
|
||||
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||
4 --out results.pkl --eval mIoU cityscapes
|
||||
```
|
||||
|
||||
注意:在 cityscapes mIoU 和我们的 mIoU 指标会有一些差异 (~0.1%) 。因为 cityscapes 默认是根据类别样本数的多少进行加权平均,而我们对所有的数据集都是采取直接平均的方法来得到 mIoU。
|
||||
|
||||
5. 在 cityscapes 数据集上4卡 GPU 测试 PSPNet, 并生成 png 文件以便提交给官方评估服务器
|
||||
|
||||
首先,在配置文件里添加内容: `configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py`,
|
||||
|
||||
```python
|
||||
data = dict(
|
||||
test=dict(
|
||||
img_dir='leftImg8bit/test',
|
||||
ann_dir='gtFine/test'))
|
||||
```
|
||||
|
||||
随后,进行测试。
|
||||
|
||||
```shell
|
||||
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||
4 --format-only --eval-options "imgfile_prefix=./pspnet_test_results"
|
||||
```
|
||||
|
||||
您会在文件夹 `./pspnet_test_results` 里得到生成的 png 文件。
|
||||
您也许可以运行 `zip -r results.zip pspnet_test_results/` 并提交 zip 文件给 [evaluation server](https://www.cityscapes-dataset.com/submit/) 。
|
||||
|
||||
6. 在 Cityscapes 数据集上使用 CPU 高效内存选项来测试 DeeplabV3+ `mIoU` 指标 (没有保存测试结果)
|
||||
|
||||
```shell
|
||||
python tools/test.py \
|
||||
configs/deeplabv3plus/deeplabv3plus_r18-d8_512x1024_80k_cityscapes.py \
|
||||
deeplabv3plus_r18-d8_512x1024_80k_cityscapes_20201226_080942-cff257fe.pth \
|
||||
--eval-options efficient_test=True \
|
||||
--eval mIoU
|
||||
```
|
||||
|
||||
使用 `pmap` 可查看 CPU 内存情况, `efficient_test=True` 会使用约 2.25GB 的 CPU 内存, `efficient_test=False` 会使用约 11.06GB 的 CPU 内存。 这个可选参数可以节约很多 CPU 内存。(MMseg v0.17 之后, `efficient_test` 参数将不再生效, 我们使用了一种渐近的方式来更加有效快速地评估和保存结果。)
|
||||
|
||||
7. 在 LoveDA 数据集上1卡 GPU 测试 PSPNet, 并生成 png 文件以便提交给官方评估服务器
|
||||
|
||||
首先,在配置文件里添加内容: `configs/pspnet/pspnet_r50-d8_512x512_80k_loveda.py`,
|
||||
|
||||
```python
|
||||
data = dict(
|
||||
test=dict(
|
||||
img_dir='img_dir/test',
|
||||
ann_dir='ann_dir/test'))
|
||||
```
|
||||
|
||||
随后,进行测试。
|
||||
|
||||
```shell
|
||||
python ./tools/test.py configs/pspnet/pspnet_r50-d8_512x512_80k_loveda.py \
|
||||
checkpoints/pspnet_r50-d8_512x512_80k_loveda_20211104_155728-88610f9f.pth \
|
||||
--format-only --eval-options "imgfile_prefix=./pspnet_test_results"
|
||||
```
|
||||
|
||||
您会在文件夹 `./pspnet_test_results` 里得到生成的 png 文件。
|
||||
您也许可以运行 `zip -r -j Results.zip pspnet_test_results/` 并提交 zip 文件给 [evaluation server](https://codalab.lisn.upsaclay.fr/competitions/421) 。
|
||||
中文版文档支持中,请先阅读[英文版本](../../en/user_guides/3_inference.md)
|
||||
|
|
|
@ -43,7 +43,7 @@ python tools/train.py ${配置文件} --resume --cfg-options load_from=${检查
|
|||
export CUDA_VISIBLE_DEVICES=-1
|
||||
```
|
||||
|
||||
然后运行[上方](#在单GPU上训练)脚本。
|
||||
然后运行[上方](###在单GPU上训练)脚本。
|
||||
|
||||
### 在单GPU上测试
|
||||
|
||||
|
@ -69,7 +69,7 @@ python tools/test.py ${配置文件} ${模型权重文件} [可选参数]
|
|||
export CUDA_VISIBLE_DEVICES=-1
|
||||
```
|
||||
|
||||
然后运行[上方](#在单GPU上测试)脚本。
|
||||
然后运行[上方](###在单GPU上测试)脚本。
|
||||
|
||||
## 多GPU、多机器上训练和测试
|
||||
|
||||
|
@ -85,7 +85,7 @@ OpenMMLab2.0 通过 `MMDistributedDataParallel`实现 **分布式** 训练。
|
|||
sh tools/dist_train.sh ${配置文件} ${GPU数量} [可选参数]
|
||||
```
|
||||
|
||||
可选参数与[上方](#在单GPU上训练)相同并且还增加了可以指定gpu数量的参数。
|
||||
可选参数与[上方](###在单GPU上训练)相同并且还增加了可以指定gpu数量的参数。
|
||||
|
||||
示例:
|
||||
|
||||
|
@ -112,7 +112,7 @@ ln -s ${您的工作路径} ${MMSEG 路径}/work_dirs
|
|||
sh tools/dist_test.sh ${配置文件} ${检查点文件} ${GPU数量} [可选参数]
|
||||
```
|
||||
|
||||
可选参数与[上方](#在单GPU上测试)相同并且增加了可以指定 gpu 数量的参数。
|
||||
可选参数与[上方](###在单GPU上测试)相同并且增加了可以指定 gpu 数量的参数。
|
||||
|
||||
示例:
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ default_hooks = dict(
|
|||
work_dirs/test_visual/20220810_115248/vis_data/vis_image
|
||||
```
|
||||
|
||||
另外,如果在 `vis_backends` 中添加 `TensorboardVisBackend` ,如 [TensorBoard 的配置](#tensorboard-configuration),我们还可以运行下面的命令在 TensorBoard 中查看它们:
|
||||
另外,如果在 `vis_backends` 中添加 `TensorboardVisBackend` ,如 [TensorBoard 的配置](###TensorBoard的配置),我们还可以运行下面的命令在 TensorBoard 中查看它们:
|
||||
|
||||
```shell
|
||||
tensorboard --logdir work_dirs/test_visual/20220810_115248/vis_data
|
||||
|
|
Loading…
Reference in New Issue