first commit
This commit is contained in:
17
Seg_All_In_One_MMSeg/docs/en/.readthedocs.yaml
Normal file
17
Seg_All_In_One_MMSeg/docs/en/.readthedocs.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
version: 2
|
||||
|
||||
build:
|
||||
os: ubuntu-22.04
|
||||
tools:
|
||||
python: "3.8"
|
||||
|
||||
formats:
|
||||
- epub
|
||||
|
||||
sphinx:
|
||||
configuration: docs/en/conf.py
|
||||
|
||||
python:
|
||||
install:
|
||||
- requirements: requirements/docs.txt
|
||||
- requirements: requirements/readthedocs.txt
|
||||
20
Seg_All_In_One_MMSeg/docs/en/Makefile
Normal file
20
Seg_All_In_One_MMSeg/docs/en/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
6
Seg_All_In_One_MMSeg/docs/en/_static/css/readthedocs.css
Normal file
6
Seg_All_In_One_MMSeg/docs/en/_static/css/readthedocs.css
Normal file
@@ -0,0 +1,6 @@
|
||||
.header-logo {
|
||||
background-image: url("../images/mmsegmentation.png");
|
||||
background-size: 201px 40px;
|
||||
height: 40px;
|
||||
width: 201px;
|
||||
}
|
||||
BIN
Seg_All_In_One_MMSeg/docs/en/_static/images/mmsegmentation.png
Normal file
BIN
Seg_All_In_One_MMSeg/docs/en/_static/images/mmsegmentation.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
199
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_datasets.md
Normal file
199
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_datasets.md
Normal file
@@ -0,0 +1,199 @@
|
||||
# Add New Datasets
|
||||
|
||||
## Add new custom dataset
|
||||
|
||||
Here we show how to develop a new custom dataset.
|
||||
|
||||
1. Create a new file `mmseg/datasets/example.py`
|
||||
|
||||
```python
|
||||
from mmseg.registry import DATASETS
|
||||
from .basesegdataset import BaseSegDataset
|
||||
|
||||
|
||||
@DATASETS.register_module()
|
||||
class ExampleDataset(BaseSegDataset):
|
||||
|
||||
METAINFO = dict(
|
||||
classes=('xxx', 'xxx', ...),
|
||||
palette=[[x, x, x], [x, x, x], ...])
|
||||
|
||||
def __init__(self, arg1, arg2):
|
||||
pass
|
||||
```
|
||||
|
||||
2. Import the module in `mmseg/datasets/__init__.py`
|
||||
|
||||
```python
|
||||
from .example import ExampleDataset
|
||||
```
|
||||
|
||||
3. Use it by creating a new new dataset config file `configs/_base_/datasets/example_dataset.py`
|
||||
|
||||
```python
|
||||
dataset_type = 'ExampleDataset'
|
||||
data_root = 'data/example/'
|
||||
...
|
||||
```
|
||||
|
||||
4. Add dataset meta information in `mmseg/utils/class_names.py`
|
||||
|
||||
```python
|
||||
def example_classes():
|
||||
return [
|
||||
'xxx', 'xxx',
|
||||
...
|
||||
]
|
||||
|
||||
def example_palette():
|
||||
return [
|
||||
[x, x, x], [x, x, x],
|
||||
...
|
||||
]
|
||||
dataset_aliases ={
|
||||
'example': ['example', ...],
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
**Note:** If the new dataset does not satisfy the mmseg requirements, a data preprocessing script needs to be prepared in `tools/dataset_converters/`
|
||||
|
||||
## Customize datasets by reorganizing data
|
||||
|
||||
The simplest way is to convert your dataset to organize your data into folders.
|
||||
|
||||
An example of file structure is as followed.
|
||||
|
||||
```none
|
||||
├── data
|
||||
│ ├── my_dataset
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ │ ├── xxx{img_suffix}
|
||||
│ │ │ │ ├── yyy{img_suffix}
|
||||
│ │ │ │ ├── zzz{img_suffix}
|
||||
│ │ │ ├── val
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ │ ├── xxx{seg_map_suffix}
|
||||
│ │ │ │ ├── yyy{seg_map_suffix}
|
||||
│ │ │ │ ├── zzz{seg_map_suffix}
|
||||
│ │ │ ├── val
|
||||
|
||||
```
|
||||
|
||||
A training pair will consist of the files with same suffix in img_dir/ann_dir.
|
||||
|
||||
Some datasets don't release the test set or don't release the ground truth of the test set, and we cannot evaluate models locally without the ground truth of the test set, so we set the validation set as the default test set in config files.
|
||||
|
||||
About how to build your own datasets or implement a new dataset class please refer to the [datasets guide](./datasets.md) for more detailed information.
|
||||
|
||||
**Note:** The annotations are images of shape (H, W), the value pixel should fall in range `[0, num_classes - 1]`.
|
||||
You may use `'P'` mode of [pillow](https://pillow.readthedocs.io/en/stable/handbook/concepts.html#palette) to create your annotation image with color.
|
||||
|
||||
## Customize datasets by mixing dataset
|
||||
|
||||
MMSegmentation also supports to mix dataset for training.
|
||||
Currently it supports to concat, repeat and multi-image mix datasets.
|
||||
|
||||
### Repeat dataset
|
||||
|
||||
We use `RepeatDataset` as wrapper to repeat the dataset.
|
||||
For example, suppose the original dataset is `Dataset_A`, to repeat it, the config looks like the following
|
||||
|
||||
```python
|
||||
dataset_A_train = dict(
|
||||
type='RepeatDataset',
|
||||
times=N,
|
||||
dataset=dict( # This is the original config of Dataset_A
|
||||
type='Dataset_A',
|
||||
...
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
### Concatenate dataset
|
||||
|
||||
In case the dataset you want to concatenate is different, you can concatenate the dataset configs like the following.
|
||||
|
||||
```python
|
||||
dataset_A_train = dict()
|
||||
dataset_B_train = dict()
|
||||
concatenate_dataset = dict(
|
||||
type='ConcatDataset',
|
||||
datasets=[dataset_A_train, dataset_B_train])
|
||||
```
|
||||
|
||||
A more complex example that repeats `Dataset_A` and `Dataset_B` by N and M times, respectively, and then concatenates the repeated datasets is as the following.
|
||||
|
||||
```python
|
||||
dataset_A_train = dict(
|
||||
type='RepeatDataset',
|
||||
times=N,
|
||||
dataset=dict(
|
||||
type='Dataset_A',
|
||||
...
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
)
|
||||
dataset_A_val = dict(
|
||||
...
|
||||
pipeline=test_pipeline
|
||||
)
|
||||
dataset_A_test = dict(
|
||||
...
|
||||
pipeline=test_pipeline
|
||||
)
|
||||
dataset_B_train = dict(
|
||||
type='RepeatDataset',
|
||||
times=M,
|
||||
dataset=dict(
|
||||
type='Dataset_B',
|
||||
...
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
)
|
||||
train_dataloader = dict(
|
||||
dataset=dict(
|
||||
type='ConcatDataset',
|
||||
datasets=[dataset_A_train, dataset_B_train]))
|
||||
|
||||
val_dataloader = dict(dataset=dataset_A_val)
|
||||
test_dataloader = dict(dataset=dataset_A_test)
|
||||
|
||||
```
|
||||
|
||||
You can refer base dataset [tutorial](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/basedataset.html) from mmengine for more details
|
||||
|
||||
### Multi-image Mix Dataset
|
||||
|
||||
We use `MultiImageMixDataset` as a wrapper to mix images from multiple datasets.
|
||||
`MultiImageMixDataset` can be used by multiple images mixed data augmentation like mosaic and mixup.
|
||||
|
||||
An example of using `MultiImageMixDataset` with `Mosaic` data augmentation:
|
||||
|
||||
```python
|
||||
train_pipeline = [
|
||||
dict(type='RandomMosaic', prob=1),
|
||||
dict(type='Resize', img_scale=(1024, 512), keep_ratio=True),
|
||||
dict(type='RandomFlip', prob=0.5),
|
||||
dict(type='PackSegInputs')
|
||||
]
|
||||
|
||||
train_dataset = dict(
|
||||
type='MultiImageMixDataset',
|
||||
dataset=dict(
|
||||
type=dataset_type,
|
||||
reduce_zero_label=False,
|
||||
img_dir=data_root + "images/train",
|
||||
ann_dir=data_root + "annotations/train",
|
||||
pipeline=[
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
]
|
||||
),
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
|
||||
```
|
||||
81
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_metrics.md
Normal file
81
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_metrics.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Add New Metrics
|
||||
|
||||
## Develop with the source code of MMSegmentation
|
||||
|
||||
Here we show how to develop a new metric with an example of `CustomMetric` as the following.
|
||||
|
||||
1. Create a new file `mmseg/evaluation/metrics/custom_metric.py`.
|
||||
|
||||
```python
|
||||
from typing import List, Sequence
|
||||
|
||||
from mmengine.evaluator import BaseMetric
|
||||
|
||||
from mmseg.registry import METRICS
|
||||
|
||||
|
||||
@METRICS.register_module()
|
||||
class CustomMetric(BaseMetric):
|
||||
|
||||
def __init__(self, arg1, arg2):
|
||||
"""
|
||||
The metric first processes each batch of data_samples and predictions,
|
||||
and appends the processed results to the results list. Then it
|
||||
collects all results together from all ranks if distributed training
|
||||
is used. Finally, it computes the metrics of the entire dataset.
|
||||
"""
|
||||
|
||||
def process(self, data_batch: dict, data_samples: Sequence[dict]) -> None:
|
||||
pass
|
||||
|
||||
def compute_metrics(self, results: list) -> dict:
|
||||
pass
|
||||
|
||||
def evaluate(self, size: int) -> dict:
|
||||
pass
|
||||
```
|
||||
|
||||
In the above example, `CustomMetric` is a subclass of `BaseMetric`. It has three methods: `process`, `compute_metrics` and `evaluate`.
|
||||
|
||||
- `process()` process one batch of data samples and predictions. The processed results are stored in `self.results` which will be used to compute the metrics after all the data samples are processed. Please refer to [MMEngine documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/evaluation.md) for more details.
|
||||
|
||||
- `compute_metrics()` is used to compute the metrics from the processed results.
|
||||
|
||||
- `evaluate()` is an interface to compute the metrics and return the results. It will be called by `ValLoop` or `TestLoop` in the `Runner`. In most cases, you don't need to override this method, but you can override it if you want to do some extra work.
|
||||
|
||||
**Note:** You might find the details of calling `evaluate()` method in the `Runner` [here](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L366). The `Runner` is the executor of the training and testing process, you can find more details about it at the [engine document](./engine.md).
|
||||
|
||||
2. Import the new metric in `mmseg/evaluation/metrics/__init__.py`.
|
||||
|
||||
```python
|
||||
from .custom_metric import CustomMetric
|
||||
__all__ = ['CustomMetric', ...]
|
||||
```
|
||||
|
||||
3. Add the new metric to the config file.
|
||||
|
||||
```python
|
||||
val_evaluator = dict(type='CustomMetric', arg1=xxx, arg2=xxx)
|
||||
test_evaluator = dict(type='CustomMetric', arg1=xxx, arg2=xxx)
|
||||
```
|
||||
|
||||
## Develop with the released version of MMSegmentation
|
||||
|
||||
The above example shows how to develop a new metric with the source code of MMSegmentation. If you want to develop a new metric with the released version of MMSegmentation, you can follow the following steps.
|
||||
|
||||
1. Create a new file `/Path/to/metrics/custom_metric.py`, implement the `process`, `compute_metrics` and `evaluate` methods, `evaluate` method is optional.
|
||||
|
||||
2. Import the new metric in your code or config file.
|
||||
|
||||
```python
|
||||
from path.to.metrics import CustomMetric
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```python
|
||||
custom_imports = dict(imports=['/Path/to/metrics'], allow_failed_imports=False)
|
||||
|
||||
val_evaluator = dict(type='CustomMetric', arg1=xxx, arg2=xxx)
|
||||
test_evaluator = dict(type='CustomMetric', arg1=xxx, arg2=xxx)
|
||||
```
|
||||
260
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_models.md
Normal file
260
Seg_All_In_One_MMSeg/docs/en/advanced_guides/add_models.md
Normal file
@@ -0,0 +1,260 @@
|
||||
# Add New Modules
|
||||
|
||||
## Develop new components
|
||||
|
||||
We can customize all the components introduced at [the model documentation](./models.md), such as **backbone**, **head**, **loss function** and **data preprocessor**.
|
||||
|
||||
### Add new backbones
|
||||
|
||||
Here we show how to develop a new backbone with an example of MobileNet.
|
||||
|
||||
1. Create a new file `mmseg/models/backbones/mobilenet.py`.
|
||||
|
||||
```python
|
||||
import torch.nn as nn
|
||||
|
||||
from mmseg.registry import MODELS
|
||||
|
||||
|
||||
@MODELS.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. Import the module in `mmseg/models/backbones/__init__.py`.
|
||||
|
||||
```python
|
||||
from .mobilenet import MobileNet
|
||||
```
|
||||
|
||||
3. Use it in your config file.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
...
|
||||
backbone=dict(
|
||||
type='MobileNet',
|
||||
arg1=xxx,
|
||||
arg2=xxx),
|
||||
...
|
||||
```
|
||||
|
||||
### Add new heads
|
||||
|
||||
In MMSegmentation, we provide a [BaseDecodeHead](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/decode_heads/decode_head.py#L17) for developing all segmentation heads.
|
||||
All newly implemented decode heads should be derived from it.
|
||||
Here we show how to develop a new head with the example of [PSPNet](https://arxiv.org/abs/1612.01105) as the following.
|
||||
|
||||
First, add a new decode head in `mmseg/models/decode_heads/psp_head.py`.
|
||||
PSPNet implements a decode head for segmentation decode.
|
||||
To implement a decode head, we need to implement three functions of the new module as the following.
|
||||
|
||||
```python
|
||||
from mmseg.registry import MODELS
|
||||
|
||||
@MODELS.register_module()
|
||||
class PSPHead(BaseDecodeHead):
|
||||
|
||||
def __init__(self, pool_scales=(1, 2, 3, 6), **kwargs):
|
||||
super(PSPHead, self).__init__(**kwargs)
|
||||
|
||||
def init_weights(self):
|
||||
pass
|
||||
|
||||
def forward(self, inputs):
|
||||
pass
|
||||
```
|
||||
|
||||
Next, the users need to add the module in the `mmseg/models/decode_heads/__init__.py`, thus the corresponding registry could find and load them.
|
||||
|
||||
To config file of PSPNet is as the following
|
||||
|
||||
```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)))
|
||||
|
||||
```
|
||||
|
||||
### Add new loss
|
||||
|
||||
Assume you want to add a new loss as `MyLoss` for segmentation decode.
|
||||
To add a new loss function, the users need to implement it in `mmseg/models/losses/my_loss.py`.
|
||||
The decorator `weighted_loss` enables the loss to be weighted for each element.
|
||||
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from mmseg.registry import MODELS
|
||||
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
|
||||
|
||||
@MODELS.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
|
||||
```
|
||||
|
||||
Then the users need to add it in the `mmseg/models/losses/__init__.py`.
|
||||
|
||||
```python
|
||||
from .my_loss import MyLoss, my_loss
|
||||
|
||||
```
|
||||
|
||||
To use it, modify the `loss_xxx` field.
|
||||
Then you need to modify the `loss_decode` field in the head.
|
||||
`loss_weight` could be used to balance multiple losses.
|
||||
|
||||
```python
|
||||
loss_decode=dict(type='MyLoss', loss_weight=1.0))
|
||||
```
|
||||
|
||||
### Add new data preprocessor
|
||||
|
||||
In MMSegmentation 1.x versions, we use [SegDataPreProcessor](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/data_preprocessor.py#L13) to copy data to the target device and preprocess the data into the model input format as default. Here we show how to develop a new data preprocessor.
|
||||
|
||||
1. Create a new file `mmseg/models/my_datapreprocessor.py`.
|
||||
|
||||
```python
|
||||
from mmengine.model import BaseDataPreprocessor
|
||||
|
||||
from mmseg.registry import MODELS
|
||||
|
||||
@MODELS.register_module()
|
||||
class MyDataPreProcessor(BaseDataPreprocessor):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def forward(self, data: dict, training: bool=False) -> Dict[str, Any]:
|
||||
# TODO Define the logic for data pre-processing in the forward method
|
||||
pass
|
||||
```
|
||||
|
||||
2. Import your data preprocessor in `mmseg/models/__init__.py`
|
||||
|
||||
```python
|
||||
from .my_datapreprocessor import MyDataPreProcessor
|
||||
```
|
||||
|
||||
3. Use it in your config file.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
data_preprocessor=dict(type='MyDataPreProcessor)
|
||||
...
|
||||
)
|
||||
```
|
||||
|
||||
## Develop new segmentors
|
||||
|
||||
The segmentor is an algorithmic architecture in which users can customize their algorithms by adding customized components and defining the logic of algorithm execution. Please refer to [the model document](./models.md) for more details.
|
||||
|
||||
Since the [BaseSegmentor](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/segmentors/base.py#L15) in MMSegmentation unifies three modes for a forward process, to develop a new segmentor, users need to overwrite `loss`, `predict` and `_forward` methods corresponding to the `loss`, `predict` and `tensor` modes.
|
||||
|
||||
Here we show how to develop a new segmentor.
|
||||
|
||||
1. Create a new file `mmseg/models/segmentors/my_segmentor.py`.
|
||||
|
||||
```python
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
import torch
|
||||
|
||||
from mmseg.registry import MODELS
|
||||
from mmseg.models import BaseSegmentor
|
||||
|
||||
@MODELS.register_module()
|
||||
class MySegmentor(BaseSegmentor):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
# TODO users should build components of the network here
|
||||
|
||||
def loss(self, inputs: Tensor, data_samples: SampleList) -> dict:
|
||||
"""Calculate losses from a batch of inputs and data samples."""
|
||||
pass
|
||||
|
||||
def predict(self, inputs: Tensor, data_samples: OptSampleList=None) -> SampleList:
|
||||
"""Predict results from a batch of inputs and data samples with post-
|
||||
processing."""
|
||||
pass
|
||||
|
||||
def _forward(self,
|
||||
inputs: Tensor,
|
||||
data_samples: OptSampleList = None) -> Tuple[List[Tensor]]:
|
||||
"""Network forward process.
|
||||
|
||||
Usually includes backbone, neck and head forward without any post-
|
||||
processing.
|
||||
"""
|
||||
pass
|
||||
```
|
||||
|
||||
2. Import your segmentor in `mmseg/models/segmentors/__init__.py`.
|
||||
|
||||
```python
|
||||
from .my_segmentor import MySegmentor
|
||||
```
|
||||
|
||||
3. Use it in your config file.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
type='MySegmentor'
|
||||
...
|
||||
)
|
||||
```
|
||||
@@ -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.
|
||||
@@ -0,0 +1,168 @@
|
||||
# Customize Runtime Settings
|
||||
|
||||
## Customize hooks
|
||||
|
||||
### Step 1: Implement a new hook
|
||||
|
||||
MMEngine has implemented commonly used [hooks](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/hook.md) for training and test,
|
||||
When users have requirements for customization, they can follow examples below.
|
||||
For example, if some hyper-parameter of the model needs to be changed when model training, we can implement a new hook for it:
|
||||
|
||||
```python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from mmengine.hooks import Hook
|
||||
from mmengine.model import is_model_wrapper
|
||||
|
||||
from mmseg.registry import HOOKS
|
||||
|
||||
|
||||
@HOOKS.register_module()
|
||||
class NewHook(Hook):
|
||||
"""Docstring for NewHook.
|
||||
"""
|
||||
|
||||
def __init__(self, a: int, b: int) -> None:
|
||||
self.a = a
|
||||
self.b = b
|
||||
|
||||
def before_train_iter(self,
|
||||
runner,
|
||||
batch_idx: int,
|
||||
data_batch: Optional[Sequence[dict]] = None) -> None:
|
||||
cur_iter = runner.iter
|
||||
# acquire this model when it is in a wrapper
|
||||
if is_model_wrapper(runner.model):
|
||||
model = runner.model.module
|
||||
model.hyper_parameter = self.a * cur_iter + self.b
|
||||
```
|
||||
|
||||
### Step 2: Import a new hook
|
||||
|
||||
The module which is defined above needs to be imported into main namespace first to ensure being registered.
|
||||
We assume `NewHook` is implemented in `mmseg/engine/hooks/new_hook.py`, there are two ways to import it:
|
||||
|
||||
- Import it by modifying `mmseg/engine/hooks/__init__.py`.
|
||||
Modules should be imported in `mmseg/engine/hooks/__init__.py` thus these new modules can be found and added by registry.
|
||||
|
||||
```python
|
||||
from .new_hook import NewHook
|
||||
|
||||
__all__ = [..., NewHook]
|
||||
```
|
||||
|
||||
- Import it manually by `custom_imports` in config file.
|
||||
|
||||
```python
|
||||
custom_imports = dict(imports=['mmseg.engine.hooks.new_hook'], allow_failed_imports=False)
|
||||
```
|
||||
|
||||
### Step 3: Modify config file
|
||||
|
||||
Users can set and use customized hooks in training and test followed methods below.
|
||||
The execution priority of hooks at the same place of `Runner` can be referred [here](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/hook.md#built-in-hooks),
|
||||
Default priority of customized hook is `NORMAL`.
|
||||
|
||||
```python
|
||||
custom_hooks = [
|
||||
dict(type='NewHook', a=a_value, b=b_value, priority='ABOVE_NORMAL')
|
||||
]
|
||||
```
|
||||
|
||||
## Customize optimizer
|
||||
|
||||
### Step 1: Implement a new optimizer
|
||||
|
||||
We recommend the customized optimizer implemented in `mmseg/engine/optimizers/my_optimizer.py`. Here is an example of a new optimizer `MyOptimizer` which has parameters `a`, `b` and `c`:
|
||||
|
||||
```python
|
||||
from mmseg.registry import OPTIMIZERS
|
||||
from torch.optim import Optimizer
|
||||
|
||||
|
||||
@OPTIMIZERS.register_module()
|
||||
class MyOptimizer(Optimizer):
|
||||
|
||||
def __init__(self, a, b, c)
|
||||
```
|
||||
|
||||
### Step 2: Import a new optimizer
|
||||
|
||||
The module which is defined above needs to be imported into main namespace first to ensure being registered.
|
||||
We assume `MyOptimizer` is implemented in `mmseg/engine/optimizers/my_optimizer.py`, there are two ways to import it:
|
||||
|
||||
- Import it by modifying `mmseg/engine/optimizers/__init__.py`.
|
||||
Modules should be imported in `mmseg/engine/optimizers/__init__.py` thus these new modules can be found and added by registry.
|
||||
|
||||
```python
|
||||
from .my_optimizer import MyOptimizer
|
||||
```
|
||||
|
||||
- Import it manually by `custom_imports` in config file.
|
||||
|
||||
```python
|
||||
custom_imports = dict(imports=['mmseg.engine.optimizers.my_optimizer'], allow_failed_imports=False)
|
||||
```
|
||||
|
||||
### Step 3: Modify config file
|
||||
|
||||
Then it needs to modify `optimizer` in `optim_wrapper` of config file, if users want to use customized `MyOptimizer`, it can be modified as:
|
||||
|
||||
```python
|
||||
optim_wrapper = dict(type='OptimWrapper',
|
||||
optimizer=dict(type='MyOptimizer',
|
||||
a=a_value, b=b_value, c=c_value),
|
||||
clip_grad=None)
|
||||
```
|
||||
|
||||
## Customize optimizer constructor
|
||||
|
||||
### Step 1: Implement a new optimizer constructor
|
||||
|
||||
Optimizer constructor is used to create optimizer and optimizer wrapper for model training, which has powerful functions like specifying learning rate and weight decay for different model layers.
|
||||
Here is an example for a customized optimizer constructor.
|
||||
|
||||
```python
|
||||
from mmengine.optim import DefaultOptimWrapperConstructor
|
||||
from mmseg.registry import OPTIM_WRAPPER_CONSTRUCTORS
|
||||
|
||||
@OPTIM_WRAPPER_CONSTRUCTORS.register_module()
|
||||
class LearningRateDecayOptimizerConstructor(DefaultOptimWrapperConstructor):
|
||||
def __init__(self, optim_wrapper_cfg, paramwise_cfg=None):
|
||||
|
||||
def __call__(self, model):
|
||||
|
||||
return my_optimizer
|
||||
```
|
||||
|
||||
Default optimizer constructor is implemented [here](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/default_constructor.py#L19).
|
||||
It can also be used as base class of new optimizer constructor.
|
||||
|
||||
### Step 2: Import a new optimizer constructor
|
||||
|
||||
The module which is defined above needs to be imported into main namespace first to ensure being registered.
|
||||
We assume `MyOptimizerConstructor` is implemented in `mmseg/engine/optimizers/my_optimizer_constructor.py`, there are two ways to import it:
|
||||
|
||||
- Import it by modifying `mmseg/engine/optimizers/__init__.py`.
|
||||
Modules should be imported in `mmseg/engine/optimizers/__init__.py` thus these new modules can be found and added by registry.
|
||||
|
||||
```python
|
||||
from .my_optimizer_constructor import MyOptimizerConstructor
|
||||
```
|
||||
|
||||
- Import it manually by `custom_imports` in config file.
|
||||
|
||||
```python
|
||||
custom_imports = dict(imports=['mmseg.engine.optimizers.my_optimizer_constructor'], allow_failed_imports=False)
|
||||
```
|
||||
|
||||
### Step 3: Modify config file
|
||||
|
||||
Then it needs to modify `constructor` in `optim_wrapper` of config file, if users want to use customized `MyOptimizerConstructor`, it can be modified as:
|
||||
|
||||
```python
|
||||
optim_wrapper = dict(type='OptimWrapper',
|
||||
constructor='MyOptimizerConstructor',
|
||||
clip_grad=None)
|
||||
```
|
||||
87
Seg_All_In_One_MMSeg/docs/en/advanced_guides/data_flow.md
Normal file
87
Seg_All_In_One_MMSeg/docs/en/advanced_guides/data_flow.md
Normal file
@@ -0,0 +1,87 @@
|
||||
# Dataflow
|
||||
|
||||
In this chapter, we will introduce the dataflow and data format convention between the internal modules managed by the [Runner](https://mmengine.readthedocs.io/en/latest/tutorials/runner.html).
|
||||
|
||||
## Overview of dataflow
|
||||
|
||||
The [Runner](https://github.com/open-mmlab/mmengine/blob/main/docs/en/design/runner.md) is an "integrator" in MMEngine. It covers all aspects of the framework and shoulders the responsibility of organizing and scheduling nearly all modules, that means the dataflow between all modules also controlled by the `Runner`. As illustrated in the [Runner document of MMEngine](https://mmengine.readthedocs.io/en/latest/tutorials/runner.html), the following diagram shows the basic dataflow.
|
||||
|
||||

|
||||
|
||||
The dashed border, gray filled shapes represent different data formats, while solid boxes represent modules/methods. Due to the great flexibility and extensibility of MMEngine, some critical base classes can be inherited and their methods can be overridden. The diagram above only holds when users are not customizing `TrainLoop`, `ValLoop`, and `TestLoop` in `Runner`, and are not overriding `train_step`, `val_step` and `test_step` method in their custom model. The default setting of loops in MMSegmentation is as follows, it uses `IterBasedTrainLoop` to train models with 20000 iterations in total and do evaluation each 2000 iterations.
|
||||
|
||||
```python
|
||||
train_cfg = dict(type='IterBasedTrainLoop', max_iters=20000, val_interval=2000)
|
||||
val_cfg = dict(type='ValLoop')
|
||||
test_cfg = dict(type='TestLoop')
|
||||
```
|
||||
|
||||
In the above diagram, the red line indicates the [train_step](./models.md#train_step). At each training iteration, dataloader loads images from storage and transfer to data preprocessor, data preprocessor would put images to the specific device and stack data to batch, then model accepts the batch data as inputs, finally the outputs of the model would be sent to optimizer. The blue line indicates [val_step](./models.md#val_step) and [test_step](./models.md#test_step). The dataflow of these two process is similar to the `train_step` except the outputs of model, since model parameters are freezed when doing evaluation, the model output would be transferred to [Evaluator](./evaluation.md#ioumetric) to compute metrics.
|
||||
|
||||
## Dataflow convention in MMSegmentation
|
||||
|
||||
From the diagram above, we could see the basic dataflow. In this section, we would introduce format convention of data involved in this dataflow, respectively.
|
||||
|
||||
### DataLoader to Data Preprocessor
|
||||
|
||||
DataLoader is an essential component in training and testing pipelines of MMEngine. Conceptually, it is derived from and consistent with [PyTorch](https://pytorch.org/). DataLoader loads data from filesystem and the original data passes through data preparation pipeline, then it would be sent to Data Preprocessor.
|
||||
|
||||
MMSegmentation defines the default data format at [PackSegInputs](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/datasets/transforms/formatting.py#L12), it's the last component of `train_pipeline` and `test_pipeline`. Please refer to [data transform documentation](./transforms.md) for more information about data transform `pipeline`.
|
||||
|
||||
Without any modifications, the return value of PackSegInputs is usually a `dict` and has only two keys, `inputs` and `data_samples`. The following pseudo-code shows the data types of the data loader output in mmseg, which is a batch of fetched data samples from the dataset, and data loader packs them into a dictionary of the list. `inputs` is the list of input tensors to the model and `data_samples` contains a list of input images' meta information and corresponding ground truth.
|
||||
|
||||
```python
|
||||
dict(
|
||||
inputs=List[torch.Tensor],
|
||||
data_samples=List[SegDataSample]
|
||||
)
|
||||
```
|
||||
|
||||
**Note:** [SegDataSample](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/structures/seg_data_sample.py) is a data structure interface of MMSegmentation, it is used as an interface between different components. `SegDataSample` implements the abstract data element `mmengine.structures.BaseDataElement`, please refer to [the SegDataSample documentation](./structures.md) and [data element documentation](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/data_element.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
### Data Preprocessor to Model
|
||||
|
||||
Though drawn separately in the diagram [above](#overview-of-dataflow), data_preprocessor is a part of the model and thus can be found in [Model tutorial](./models.md) at data preprocessor chapter.
|
||||
|
||||
The return value of data preprocessor is a dictionary, containing `inputs` and `data_samples`, `inputs` is batched images, a 4D tensor, and some additional meta info used in data preprocesses would be added to the `data_samples`. When transferred to the network, the dictionary would be unpacked to two values. The following pseudo-codes show the return value of the data preprocessor and the input values of model.
|
||||
|
||||
```python
|
||||
dict(
|
||||
inputs=torch.Tensor,
|
||||
data_samples=List[SegDataSample]
|
||||
)
|
||||
```
|
||||
|
||||
```python
|
||||
class Network(BaseSegmentor):
|
||||
|
||||
def forward(self, inputs: torch.Tensor, data_samples: List[SegDataSample], mode: str):
|
||||
pass
|
||||
```
|
||||
|
||||
**Note:** Model forward has 3 kinds of mode, which is controlled by input argumentmode, please refer [model tutorial](./models.md) for more details.
|
||||
|
||||
### Model output
|
||||
|
||||
As [model tutorial](./models.md#forward) mentioned 3 kinds of mode forward with 3 kinds of output. `train_step`and `test_step`(or `val_step`) correspond to `'loss'` and `'predict'` respectively.
|
||||
|
||||
In `test_step` or `val_step`, the inference results would be transferred to `Evaluator`. You might read the [evaluation document](./evaluation.md) for more information about `Evaluator`.
|
||||
|
||||
After inference, the [BaseSegmentor](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/segmentors/base.py#L15) in MMSegmentation would do a simple post process to pack inference results, the segmentation logits produced by the neural network, segmentation mask after the `argmax` operation and ground truth(if exists) would be packed into a similar `SegDataSample` instance. The return value of [postprocess_result](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/segmentors/base.py#L132) is a **`List` of `SegDataSample`**. Following diagram shows the key properties of these `SegDataSample` instances.
|
||||
|
||||

|
||||
|
||||
The same as Data Preprocessor, loss function is also a part of the model, it's a property of [decode head](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/decode_heads/decode_head.py#L142).
|
||||
|
||||
In MMSegmentation, the method [loss_by_feat](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/models/decode_heads/decode_head.py#L291) of `decode_head` is an unified interface used to compute loss.
|
||||
|
||||
Parameters:
|
||||
|
||||
- seg_logits (Tensor): The output from decode head forward function.
|
||||
- batch_data_samples (List\[:obj:`SegDataSample`\]): The seg data samples. It usually includes information such as `metainfo` and `gt_sem_seg`.
|
||||
|
||||
Returns:
|
||||
|
||||
- dict\[str, Tensor\]: a dictionary of loss components
|
||||
|
||||
**Note:** The `train_step` transfers the loss into OptimWrapper to update the weights in model, please refer [train_step](./models.md#train_step) for more details.
|
||||
386
Seg_All_In_One_MMSeg/docs/en/advanced_guides/datasets.md
Normal file
386
Seg_All_In_One_MMSeg/docs/en/advanced_guides/datasets.md
Normal file
@@ -0,0 +1,386 @@
|
||||
# Dataset
|
||||
|
||||
Dataset classes in MMSegmentation have two functions: (1) load data information after [data preparation](../user_guides/2_dataset_prepare.md)
|
||||
and (2) send data into [dataset transform pipeline](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/datasets/basesegdataset.py#L141) to do [data augmentation](./transforms.md).
|
||||
There are 2 kinds of loaded information: (1) meta information which is original dataset information such as categories (classes) of dataset and their corresponding palette information, (2) data information which includes
|
||||
the path of dataset images and labels.
|
||||
The tutorial includes some main interfaces in MMSegmentation 1.x dataset class: methods of loading data information and modifying dataset classes in base dataset class, and the relationship between dataset and the data transform pipeline.
|
||||
|
||||
## Main Interfaces
|
||||
|
||||
Take Cityscapes as an example, if you want to run the example, please download and [preprocess](../user_guides/2_dataset_prepare.md#cityscapes)
|
||||
Cityscapes dataset in `data` directory, before running the demo code:
|
||||
|
||||
Instantiate Cityscapes training dataset:
|
||||
|
||||
```python
|
||||
from mmseg.datasets import CityscapesDataset
|
||||
from mmengine.registry import init_default_scope
|
||||
init_default_scope('mmseg')
|
||||
|
||||
data_root = 'data/cityscapes/'
|
||||
data_prefix=dict(img_path='leftImg8bit/train', seg_map_path='gtFine/train')
|
||||
train_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='RandomCrop', crop_size=(512, 1024), cat_max_ratio=0.75),
|
||||
dict(type='RandomFlip', prob=0.5),
|
||||
dict(type='PackSegInputs')
|
||||
]
|
||||
|
||||
dataset = CityscapesDataset(data_root=data_root, data_prefix=data_prefix, test_mode=False, pipeline=train_pipeline)
|
||||
```
|
||||
|
||||
Get the length of training set:
|
||||
|
||||
```python
|
||||
print(len(dataset))
|
||||
|
||||
2975
|
||||
```
|
||||
|
||||
Get data information: The type of data information is `dict` which includes several keys:
|
||||
|
||||
- `'img_path'`: path of images
|
||||
- `'seg_map_path'`: path of segmentation labels
|
||||
- `'seg_fields'`: saving label fields
|
||||
- `'sample_idx'`: the index of the current sample
|
||||
|
||||
There are also `'label_map'` and `'reduce_zero_label'` whose functions would be introduced in the next section.
|
||||
|
||||
```python
|
||||
# Acquire data information of first sample in dataset
|
||||
print(dataset.get_data_info(0))
|
||||
|
||||
{'img_path': 'data/cityscapes/leftImg8bit/train/aachen/aachen_000000_000019_leftImg8bit.png',
|
||||
'seg_map_path': 'data/cityscapes/gtFine/train/aachen/aachen_000000_000019_gtFine_labelTrainIds.png',
|
||||
'label_map': None,
|
||||
'reduce_zero_label': False,
|
||||
'seg_fields': [],
|
||||
'sample_idx': 0}
|
||||
```
|
||||
|
||||
Get dataset meta information: the type of MMSegmentation meta information is also `dict`, which includes `'classes'` field for dataset classes and `'palette'` field for corresponding colors in visualization, and has `'label_map'` field and `'reduce_zero_label'` filed.
|
||||
|
||||
```python
|
||||
print(dataset.metainfo)
|
||||
|
||||
{'classes': ('road',
|
||||
'sidewalk',
|
||||
'building',
|
||||
'wall',
|
||||
'fence',
|
||||
'pole',
|
||||
'traffic light',
|
||||
'traffic sign',
|
||||
'vegetation',
|
||||
'terrain',
|
||||
'sky',
|
||||
'person',
|
||||
'rider',
|
||||
'car',
|
||||
'truck',
|
||||
'bus',
|
||||
'train',
|
||||
'motorcycle',
|
||||
'bicycle'),
|
||||
'palette': [[128, 64, 128],
|
||||
[244, 35, 232],
|
||||
[70, 70, 70],
|
||||
[102, 102, 156],
|
||||
[190, 153, 153],
|
||||
[153, 153, 153],
|
||||
[250, 170, 30],
|
||||
[220, 220, 0],
|
||||
[107, 142, 35],
|
||||
[152, 251, 152],
|
||||
[70, 130, 180],
|
||||
[220, 20, 60],
|
||||
[255, 0, 0],
|
||||
[0, 0, 142],
|
||||
[0, 0, 70],
|
||||
[0, 60, 100],
|
||||
[0, 80, 100],
|
||||
[0, 0, 230],
|
||||
[119, 11, 32]],
|
||||
'label_map': None,
|
||||
'reduce_zero_label': False}
|
||||
```
|
||||
|
||||
The return value of dataset `__getitem__` method is the output of data samples after data augmentation, whose type is also `dict`. It has two fields: `'inputs'` corresponding to images after data augmentation,
|
||||
and `'data_samples'` corresponding to [`SegDataSample`](./structures.md) which is new data structures in MMSegmentation 1.x,
|
||||
and `gt_sem_seg` of `SegDataSample` has labels after data augmentation operations.
|
||||
|
||||
```python
|
||||
print(dataset[0])
|
||||
|
||||
{'inputs': tensor([[[131, 130, 130, ..., 23, 23, 23],
|
||||
[132, 132, 132, ..., 23, 22, 23],
|
||||
[134, 133, 133, ..., 23, 23, 23],
|
||||
...,
|
||||
[ 66, 67, 67, ..., 71, 71, 71],
|
||||
[ 66, 67, 66, ..., 68, 68, 68],
|
||||
[ 67, 67, 66, ..., 70, 70, 70]],
|
||||
|
||||
[[143, 143, 142, ..., 28, 28, 29],
|
||||
[145, 145, 145, ..., 28, 28, 29],
|
||||
[145, 145, 145, ..., 27, 28, 29],
|
||||
...,
|
||||
[ 75, 75, 76, ..., 80, 81, 81],
|
||||
[ 75, 76, 75, ..., 80, 80, 80],
|
||||
[ 77, 76, 76, ..., 82, 82, 82]],
|
||||
|
||||
[[126, 125, 126, ..., 21, 21, 22],
|
||||
[127, 127, 128, ..., 21, 21, 22],
|
||||
[127, 127, 126, ..., 21, 21, 22],
|
||||
...,
|
||||
[ 63, 63, 64, ..., 69, 69, 70],
|
||||
[ 64, 65, 64, ..., 69, 69, 69],
|
||||
[ 65, 66, 66, ..., 72, 71, 71]]], dtype=torch.uint8),
|
||||
'data_samples': <SegDataSample(
|
||||
|
||||
META INFORMATION
|
||||
img_path: 'data/cityscapes/leftImg8bit/train/aachen/aachen_000000_000019_leftImg8bit.png'
|
||||
seg_map_path: 'data/cityscapes/gtFine/train/aachen/aachen_000000_000019_gtFine_labelTrainIds.png'
|
||||
img_shape: (512, 1024, 3)
|
||||
flip_direction: None
|
||||
ori_shape: (1024, 2048)
|
||||
flip: False
|
||||
|
||||
DATA FIELDS
|
||||
gt_sem_seg: <PixelData(
|
||||
|
||||
META INFORMATION
|
||||
|
||||
DATA FIELDS
|
||||
data: tensor([[[2, 2, 2, ..., 8, 8, 8],
|
||||
[2, 2, 2, ..., 8, 8, 8],
|
||||
[2, 2, 2, ..., 8, 8, 8],
|
||||
...,
|
||||
[0, 0, 0, ..., 0, 0, 0],
|
||||
[0, 0, 0, ..., 0, 0, 0],
|
||||
[0, 0, 0, ..., 0, 0, 0]]])
|
||||
)>
|
||||
_gt_sem_seg: <PixelData(
|
||||
|
||||
META INFORMATION
|
||||
|
||||
DATA FIELDS
|
||||
data: tensor([[[2, 2, 2, ..., 8, 8, 8],
|
||||
[2, 2, 2, ..., 8, 8, 8],
|
||||
[2, 2, 2, ..., 8, 8, 8],
|
||||
...,
|
||||
[0, 0, 0, ..., 0, 0, 0],
|
||||
[0, 0, 0, ..., 0, 0, 0],
|
||||
[0, 0, 0, ..., 0, 0, 0]]])
|
||||
)>
|
||||
)}
|
||||
```
|
||||
|
||||
## BaseSegDataset
|
||||
|
||||
As mentioned above, dataset classes have the same functions, we implemented [`BaseSegDataset`](https://mmsegmentation.readthedocs.io/en/latest/api.html?highlight=BaseSegDataset#mmseg.datasets.BaseSegDataset) to reues the common functions.
|
||||
It inherits [`BaseDataset` of MMEngine](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/basedataset.md) and follows unified initialization process of OpenMMLab. It supports the highly effective interior storing format, some functions like
|
||||
dataset concatenation and repeatedly sampling. In MMSegmentation `BaseSegDataset`, the **method of loading data information** (`load_data_list`) is redefined and adds new `get_label_map` method to **modify dataset classes information**.
|
||||
|
||||
### Loading Dataset Information
|
||||
|
||||
The loaded data information includes the path of images samples and annotations samples, the detailed implementation could be found in
|
||||
[`load_data_list`](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/datasets/basesegdataset.py#L231) of `BaseSegDataset` in MMSegmentation.
|
||||
There are two main methods to acquire the path of images and labels:
|
||||
|
||||
1. Load file paths according to the dirictory and suffix of input images and annotations
|
||||
|
||||
If the dataset directory structure is organized as below, the [`load_data_list`](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/datasets/basesegdataset.py#L231) can parse dataset directory Structure:
|
||||
|
||||
```
|
||||
├── data
|
||||
│ ├── my_dataset
|
||||
│ │ ├── img_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ │ ├── xxx{img_suffix}
|
||||
│ │ │ │ ├── yyy{img_suffix}
|
||||
│ │ │ ├── val
|
||||
│ │ │ │ ├── zzz{img_suffix}
|
||||
│ │ ├── ann_dir
|
||||
│ │ │ ├── train
|
||||
│ │ │ │ ├── xxx{seg_map_suffix}
|
||||
│ │ │ │ ├── yyy{seg_map_suffix}
|
||||
│ │ │ ├── val
|
||||
│ │ │ │ ├── zzz{seg_map_suffix}
|
||||
```
|
||||
|
||||
Here is an example pf ADE20K, and below the directory structure of the dataset:
|
||||
|
||||
```
|
||||
├── ade
|
||||
│ ├── ADEChallengeData2016
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ │ ├── ADE_train_00000001.png
|
||||
│ │ │ │ ├── ...
|
||||
│ │ │ │── validation
|
||||
│ │ │ │ ├── ADE_val_00000001.png
|
||||
│ │ │ │ ├── ...
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ │ ├── ADE_train_00000001.jpg
|
||||
│ │ │ │ ├── ...
|
||||
│ │ │ ├── validation
|
||||
│ │ │ │ ├── ADE_val_00000001.jpg
|
||||
│ │ │ │ ├── ...
|
||||
```
|
||||
|
||||
```python
|
||||
from mmseg.datasets import ADE20KDataset
|
||||
|
||||
ADE20KDataset(data_root = 'data/ade/ADEChallengeData2016',
|
||||
data_prefix=dict(img_path='images/training', seg_map_path='annotations/training'),
|
||||
img_suffix='.jpg',
|
||||
seg_map_suffix='.png',
|
||||
reduce_zero_label=True)
|
||||
```
|
||||
|
||||
2. Load file paths from annotation file
|
||||
|
||||
Dataset also can load an annotation file which includes the data sample paths of dataset.
|
||||
Take PascalContext dataset instance as an example, its input annotation file is:
|
||||
|
||||
```python
|
||||
2008_000008
|
||||
...
|
||||
```
|
||||
|
||||
It needs to define `ann_file` when instantiation:
|
||||
|
||||
```python
|
||||
PascalContextDataset(data_root='data/VOCdevkit/VOC2010/',
|
||||
data_prefix=dict(img_path='JPEGImages', seg_map_path='SegmentationClassContext'),
|
||||
ann_file='ImageSets/SegmentationContext/train.txt')
|
||||
```
|
||||
|
||||
### Modification of Dataset Classes
|
||||
|
||||
- Use `metainfo` input argument
|
||||
|
||||
Meta information is defined as class variables, such as `METAINFO` variable of Cityscapes:
|
||||
|
||||
```python
|
||||
class CityscapesDataset(BaseSegDataset):
|
||||
"""Cityscapes dataset.
|
||||
|
||||
The ``img_suffix`` is fixed to '_leftImg8bit.png' and ``seg_map_suffix`` is
|
||||
fixed to '_gtFine_labelTrainIds.png' for Cityscapes dataset.
|
||||
"""
|
||||
METAINFO = dict(
|
||||
classes=('road', 'sidewalk', 'building', 'wall', 'fence', 'pole',
|
||||
'traffic light', 'traffic sign', 'vegetation', 'terrain',
|
||||
'sky', 'person', 'rider', 'car', 'truck', 'bus', 'train',
|
||||
'motorcycle', 'bicycle'),
|
||||
palette=[[128, 64, 128], [244, 35, 232], [70, 70, 70], [102, 102, 156],
|
||||
[190, 153, 153], [153, 153, 153], [250, 170,
|
||||
30], [220, 220, 0],
|
||||
[107, 142, 35], [152, 251, 152], [70, 130, 180],
|
||||
[220, 20, 60], [255, 0, 0], [0, 0, 142], [0, 0, 70],
|
||||
[0, 60, 100], [0, 80, 100], [0, 0, 230], [119, 11, 32]])
|
||||
|
||||
```
|
||||
|
||||
Here `'classes'` defines class names of Cityscapes dataset annotations, if users only concern some classes about vehicles and **ignore other classes**,
|
||||
the meta information of dataset could be modified by defined input argument `metainfo` when instantiating Cityscapes dataset:
|
||||
|
||||
```python
|
||||
from mmseg.datasets import CityscapesDataset
|
||||
|
||||
data_root = 'data/cityscapes/'
|
||||
data_prefix=dict(img_path='leftImg8bit/train', seg_map_path='gtFine/train')
|
||||
# metainfo only keep classes below:
|
||||
metainfo=dict(classes=( 'car', 'truck', 'bus', 'train', 'motorcycle', 'bicycle'))
|
||||
dataset = CityscapesDataset(data_root=data_root, data_prefix=data_prefix, metainfo=metainfo)
|
||||
|
||||
print(dataset.metainfo)
|
||||
|
||||
{'classes': ('car', 'truck', 'bus', 'train', 'motorcycle', 'bicycle'),
|
||||
'palette': [[0, 0, 142],
|
||||
[0, 0, 70],
|
||||
[0, 60, 100],
|
||||
[0, 80, 100],
|
||||
[0, 0, 230],
|
||||
[119, 11, 32],
|
||||
[128, 64, 128],
|
||||
[244, 35, 232],
|
||||
[70, 70, 70],
|
||||
[102, 102, 156],
|
||||
[190, 153, 153],
|
||||
[153, 153, 153],
|
||||
[250, 170, 30],
|
||||
[220, 220, 0],
|
||||
[107, 142, 35],
|
||||
[152, 251, 152],
|
||||
[70, 130, 180],
|
||||
[220, 20, 60],
|
||||
[255, 0, 0]],
|
||||
# pixels whose label index are 255 would be ignored when calculating loss
|
||||
'label_map': {0: 255,
|
||||
1: 255,
|
||||
2: 255,
|
||||
3: 255,
|
||||
4: 255,
|
||||
5: 255,
|
||||
6: 255,
|
||||
7: 255,
|
||||
8: 255,
|
||||
9: 255,
|
||||
10: 255,
|
||||
11: 255,
|
||||
12: 255,
|
||||
13: 0,
|
||||
14: 1,
|
||||
15: 2,
|
||||
16: 3,
|
||||
17: 4,
|
||||
18: 5},
|
||||
'reduce_zero_label': False}
|
||||
```
|
||||
|
||||
Meta information is different from default setting of Cityscapes dataset. Moreover, `label_map` field is also defined, which is used for modifying label index of each pixel on segmentation mask.
|
||||
The segmentation label would re-map class information by `label_map`, [here](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/datasets/basesegdataset.py#L151) is detailed implementation:
|
||||
|
||||
```python
|
||||
gt_semantic_seg_copy = gt_semantic_seg.copy()
|
||||
for old_id, new_id in results['label_map'].items():
|
||||
gt_semantic_seg[gt_semantic_seg_copy == old_id] = new_id
|
||||
```
|
||||
|
||||
- Using `reduce_zero_label` input argument
|
||||
|
||||
To ignore label 0 (such as ADE20K dataset), we can use `reduce_zero_label` (default to `False`) argument of BaseSegDataset and its subclasses.
|
||||
When `reduce_zero_label` is `True`, label 0 in segmentation annotations would be set as 255 (models of MMSegmentation would ignore label 255 in calculating loss) and indices of other labels will minus 1:
|
||||
|
||||
```python
|
||||
gt_semantic_seg[gt_semantic_seg == 0] = 255
|
||||
gt_semantic_seg = gt_semantic_seg - 1
|
||||
gt_semantic_seg[gt_semantic_seg == 254] = 255
|
||||
```
|
||||
|
||||
## Dataset and Data Transform Pipeline
|
||||
|
||||
If the argument `pipeline` is defined, the return value of `__getitem__` method is after data argument.
|
||||
If dataset input argument does not define pipeline, it is the same as return value of `get_data_info` method.
|
||||
|
||||
```python
|
||||
from mmseg.datasets import CityscapesDataset
|
||||
|
||||
data_root = 'data/cityscapes/'
|
||||
data_prefix=dict(img_path='leftImg8bit/train', seg_map_path='gtFine/train')
|
||||
dataset = CityscapesDataset(data_root=data_root, data_prefix=data_prefix, test_mode=False)
|
||||
|
||||
print(dataset[0])
|
||||
|
||||
{'img_path': 'data/cityscapes/leftImg8bit/train/aachen/aachen_000000_000019_leftImg8bit.png',
|
||||
'seg_map_path': 'data/cityscapes/gtFine/train/aachen/aachen_000000_000019_gtFine_labelTrainIds.png',
|
||||
'label_map': None,
|
||||
'reduce_zero_label': False,
|
||||
'seg_fields': [],
|
||||
'sample_idx': 0}
|
||||
```
|
||||
279
Seg_All_In_One_MMSeg/docs/en/advanced_guides/engine.md
Normal file
279
Seg_All_In_One_MMSeg/docs/en/advanced_guides/engine.md
Normal file
@@ -0,0 +1,279 @@
|
||||
# Training Engine
|
||||
|
||||
MMEngine defined some [basic loop controllers](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py) such as epoch-based training loop (`EpochBasedTrainLoop`), iteration-based training loop (`IterBasedTrainLoop`), standard validation loop (`ValLoop`), and standard testing loop (`TestLoop`).
|
||||
|
||||
OpenMMLab's algorithm libraries like MMSegmentation abstract model training, testing, and inference as `Runner` to handle. Users can use the default `Runner` in MMEngine directly or modify the `Runner` to meet customized needs. This document mainly introduces how users can configure existing running settings, hooks, and optimizers' basic concepts and usage methods.
|
||||
|
||||
## Configuring Runtime Settings
|
||||
|
||||
### Configuring Training Iterations
|
||||
|
||||
Loop controllers refer to the execution process during training, validation, and testing. `train_cfg`, `val_cfg`, and `test_cfg` are used to build these processes in the configuration file. MMSegmentation sets commonly used training iterations in `train_cfg` under the `configs/_base_/schedules` folder.
|
||||
For example, to train for 80,000 iterations using the iteration-based training loop (`IterBasedTrainLoop`) and perform validation every 8,000 iterations, you can set it as follows:
|
||||
|
||||
```python
|
||||
train_cfg = dict(type='IterBasedTrainLoop', max_iters=80000, val_interval=8000)
|
||||
```
|
||||
|
||||
### Configuring Training Optimizers
|
||||
|
||||
Here's an example of a SGD optimizer:
|
||||
|
||||
```python
|
||||
optim_wrapper = dict(
|
||||
type='OptimWrapper',
|
||||
optimizer=dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005),
|
||||
clip_grad=None)
|
||||
```
|
||||
|
||||
OpenMMLab supports all optimizers in PyTorch. For more details, please refer to the [MMEngine optimizer documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/optim_wrapper.md).
|
||||
|
||||
It is worth emphasizing that `optim_wrapper` is a variable of `runner`, so when configuring the optimizer, the field to configure is the `optim_wrapper` field. For more information on using optimizers, see the [Optimizer](#Optimizer) section below.
|
||||
|
||||
### Configuring Training Parameter Schedulers
|
||||
|
||||
Before configuring the training parameter scheduler, it is recommended to first understand the basic concepts of parameter schedulers in the [MMEngine documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/param_scheduler.md).
|
||||
|
||||
Here's an example of a parameter scheduler. During training, a linearly changing learning rate strategy is used for warm-up in the first 1,000 iterations. After the first 1,000 iterations until the 16,000 iterations in the end, the default polynomial learning rate decay is used:
|
||||
|
||||
```python
|
||||
param_scheduler = [
|
||||
dict(type='LinearLR', by_epoch=False, start_factor=0.1, begin=0, end=1000),
|
||||
dict(
|
||||
type='PolyLR',
|
||||
eta_min=1e-4,
|
||||
power=0.9,
|
||||
begin=1000,
|
||||
end=160000,
|
||||
by_epoch=False,
|
||||
)
|
||||
]
|
||||
```
|
||||
|
||||
Note: When modifying the `max_iters` in `train_cfg`, make sure the parameters in the parameter scheduler `param_scheduler` are also modified accordingly.
|
||||
|
||||
## Hook
|
||||
|
||||
### Introduction
|
||||
|
||||
OpenMMLab abstracts the model training and testing process as `Runner`. Inserting hooks can implement the corresponding functionality needed at different training and testing stages (such as "before and after each training iter", "before and after each validation iter", etc.) in `Runner`. For more introduction on hook mechanisms, please refer to [here](https://www.calltutors.com/blog/what-is-hook).
|
||||
|
||||
Hooks used in `Runner` are divided into two categories:
|
||||
|
||||
- Default hooks:
|
||||
|
||||
They implement essential functions during training and are defined in the configuration file by `default_hooks` and passed to `Runner`. `Runner` registers them through the [`register_default_hooks`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L1780) method.
|
||||
|
||||
Hooks have corresponding priorities; the higher the priority, the earlier the runner calls them. If the priorities are the same, the calling order is consistent with the hook registration order.
|
||||
|
||||
It is not recommended for users to modify the default hook priorities. Please refer to the [MMEngine hooks documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/hook.md) to understand the hook priority definitions.
|
||||
|
||||
The following are the default hooks used in MMSegmentation:
|
||||
|
||||
| Hook | Function | Priority |
|
||||
| :--------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------: | :---------------: |
|
||||
| [IterTimerHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/iter_timer_hook.py) | Record the time spent on each iteration. | NORMAL (50) |
|
||||
| [LoggerHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/logger_hook.py) | Collect log records from different components in `Runner` and output them to terminal, JSON file, tensorboard, wandb, etc. | BELOW_NORMAL (60) |
|
||||
| [ParamSchedulerHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/param_scheduler_hook.py) | Update some hyperparameters in the optimizer, such as learning rate momentum. | LOW (70) |
|
||||
| [CheckpointHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/checkpoint_hook.py) | Regularly save checkpoint files. | VERY_LOW (90) |
|
||||
| [DistSamplerSeedHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/sampler_seed_hook.py) | Ensure the distributed sampler shuffle is enabled. | NORMAL (50) |
|
||||
| [SegVisualizationHook](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/visualization/local_visualizer.py) | Visualize prediction results during validation and testing. | NORMAL (50) |
|
||||
|
||||
MMSegmentation registers some hooks with essential training functions in `default_hooks`:
|
||||
|
||||
```python
|
||||
default_hooks = dict(
|
||||
timer=dict(type='IterTimerHook'),
|
||||
logger=dict(type='LoggerHook', interval=50, log_metric_by_epoch=False),
|
||||
param_scheduler=dict(type='ParamSchedulerHook'),
|
||||
checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=32000),
|
||||
sampler_seed=dict(type='DistSamplerSeedHook'),
|
||||
visualization=dict(type='SegVisualizationHook'))
|
||||
```
|
||||
|
||||
All the default hooks mentioned above, except for `SegVisualizationHook`, are implemented in MMEngine. The `SegVisualizationHook` is a hook implemented in MMSegmentation, which will be introduced later.
|
||||
|
||||
- Modifying default hooks
|
||||
|
||||
We will use the `logger` and `checkpoint` in `default_hooks` as examples to demonstrate how to modify the default hooks in `default_hooks`.
|
||||
|
||||
(1) Model saving configuration
|
||||
|
||||
`default_hooks` uses the `checkpoint` field to initialize the [model saving hook (CheckpointHook)](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/checkpoint_hook.py#L19).
|
||||
|
||||
```python
|
||||
checkpoint = dict(type='CheckpointHook', interval=1)
|
||||
```
|
||||
|
||||
Users can set `max_keep_ckpts` to save only a small number of checkpoints or use `save_optimizer` to determine whether to save optimizer information. More details on related parameters can be found [here](https://mmengine.readthedocs.io/en/latest/api/generated/mmengine.hooks.CheckpointHook.html#checkpointhook).
|
||||
|
||||
(2) Logging configuration
|
||||
|
||||
The `LoggerHook` is used to collect log information from different components in `Runner` and write it to terminal, JSON files, tensorboard, wandb, etc.
|
||||
|
||||
```python
|
||||
logger=dict(type='LoggerHook', interval=10)
|
||||
```
|
||||
|
||||
In the latest 1.x version of MMSegmentation, some logger hooks (LoggerHook) such as `TextLoggerHook`, `WandbLoggerHook`, and `TensorboardLoggerHook` will no longer be used. Instead, MMEngine uses `LogProcessor` to handle the information processed by the aforementioned hooks, which are now in [`MessageHub`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/logging/message_hub.py#L17), [`WandbVisBackend`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/visualization/vis_backend.py#L324), and [`TensorboardVisBackend`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/visualization/vis_backend.py#L472).
|
||||
|
||||
Detailed usage is as follows, configuring the visualizer and specifying the visualization backend at the same time, here using Tensorboard as the visualizer's backend:
|
||||
|
||||
```python
|
||||
# TensorboardVisBackend
|
||||
visualizer = dict(
|
||||
type='SegLocalVisualizer', vis_backends=[dict(type='TensorboardVisBackend')], name='visualizer')
|
||||
```
|
||||
|
||||
For more related usage, please refer to [MMEngine Visualization Backend User Tutorial](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/visualization.md).
|
||||
|
||||
- Custom hooks
|
||||
|
||||
Custom hooks are defined in the configuration through `custom_hooks`, and `Runner` registers them using the [`register_custom_hooks`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L1820) method.
|
||||
|
||||
The priority of custom hooks needs to be set in the configuration file; if not, it will be set to `NORMAL` by default. The following are some custom hooks implemented in MMEngine:
|
||||
|
||||
| Hook | Usage |
|
||||
| :----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| [EMAHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/ema_hook.py) | Use Exponential Moving Average (EMA) during model training. |
|
||||
| [EmptyCacheHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/empty_cache_hook.py) | Release all GPU memory not occupied by the cache during training |
|
||||
| [SyncBuffersHook](https://github.com/open-mmlab/mmengine/blob/main/mmengine/hooks/sync_buffer_hook.py) | Synchronize the parameters in the model buffer, such as `running_mean` and `running_var` in BN, at the end of each training epoch. |
|
||||
|
||||
The following is a use case for `EMAHook`, where the config file includes the configuration of the implemented custom hooks as members of the `custom_hooks` list.
|
||||
|
||||
```python
|
||||
custom_hooks = [
|
||||
dict(type='EMAHook', start_iters=500, priority='NORMAL')
|
||||
]
|
||||
```
|
||||
|
||||
### SegVisualizationHook
|
||||
|
||||
MMSegmentation implemented [`SegVisualizationHook`](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/engine/hooks/visualization_hook.py#L17), which is used to visualize prediction results during validation and testing.
|
||||
`SegVisualizationHook` overrides the `_after_iter` method in the base class `Hook`. During validation or testing, it calls the `add_datasample` method of `visualizer` to draw semantic segmentation results according to the specified iteration interval. The specific implementation is as follows:
|
||||
|
||||
```python
|
||||
...
|
||||
@HOOKS.register_module()
|
||||
class SegVisualizationHook(Hook):
|
||||
...
|
||||
def _after_iter(self,
|
||||
runner: Runner,
|
||||
batch_idx: int,
|
||||
data_batch: dict,
|
||||
outputs: Sequence[SegDataSample],
|
||||
mode: str = 'val') -> None:
|
||||
...
|
||||
# If it's a training phase or self.draw is False, then skip it
|
||||
if self.draw is False or mode == 'train':
|
||||
return
|
||||
...
|
||||
if self.every_n_inner_iters(batch_idx, self.interval):
|
||||
for output in outputs:
|
||||
img_path = output.img_path
|
||||
img_bytes = self.file_client.get(img_path)
|
||||
img = mmcv.imfrombytes(img_bytes, channel_order='rgb')
|
||||
window_name = f'{mode}_{osp.basename(img_path)}'
|
||||
|
||||
self._visualizer.add_datasample(
|
||||
window_name,
|
||||
img,
|
||||
data_sample=output,
|
||||
show=self.show,
|
||||
wait_time=self.wait_time,
|
||||
step=runner.iter)
|
||||
|
||||
```
|
||||
|
||||
For more details about visualization, you can check [here](../user_guides/visualization.md).
|
||||
|
||||
## Optimizer
|
||||
|
||||
In the previous configuration and runtime settings, we provided a simple example of configuring the training optimizer. This section will further detailly introduce how to configure optimizers in MMSegmentation.
|
||||
|
||||
## Optimizer Wrapper
|
||||
|
||||
OpenMMLab 2.0 introduces an optimizer wrapper that supports different training strategies, including mixed-precision training, gradient accumulation, and gradient clipping. Users can choose the appropriate training strategy according to their needs. The optimizer wrapper also defines a standard parameter update process, allowing users to switch between different training strategies within the same code. For more information, please refer to the [MMEngine optimizer wrapper documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/optim_wrapper.md).
|
||||
|
||||
Here are some common usage methods in MMSegmentation:
|
||||
|
||||
#### Configuring PyTorch Supported Optimizers
|
||||
|
||||
OpenMMLab 2.0 supports all native PyTorch optimizers, as referenced [here](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/optim_wrapper.md).
|
||||
|
||||
To set the optimizer used by the `Runner` during training in the configuration file, you need to define `optim_wrapper` instead of `optimizer`. Below is an example of configuring an optimizer during training:
|
||||
|
||||
```python
|
||||
optim_wrapper = dict(
|
||||
type='OptimWrapper',
|
||||
optimizer=dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005),
|
||||
clip_grad=None)
|
||||
```
|
||||
|
||||
#### Configuring Gradient Clipping
|
||||
|
||||
When the model training requires gradient clipping, you can configure it as shown in the following example:
|
||||
|
||||
```python
|
||||
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
|
||||
optim_wrapper = dict(type='OptimWrapper', optimizer=optimizer,
|
||||
clip_grad=dict(max_norm=0.01, norm_type=2))
|
||||
```
|
||||
|
||||
Here, `max_norm` refers to the maximum value of the gradient after clipping, and `norm_type` refers to the norm used when clipping the gradient. Related methods can be found in [torch.nn.utils.clip_grad_norm\_](https://pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_norm_.html).
|
||||
|
||||
#### Configuring Mixed Precision Training
|
||||
|
||||
When mixed precision training is needed to reduce memory usage, you can use `AmpOptimWrapper`. The specific configuration is as follows:
|
||||
|
||||
```python
|
||||
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
|
||||
optim_wrapper = dict(type='AmpOptimWrapper', optimizer=optimizer)
|
||||
```
|
||||
|
||||
The default setting for `loss_scale` in [`AmpOptimWrapper`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/amp_optimizer_wrapper.py#L20) is `dynamic`.
|
||||
|
||||
#### Configuring Hyperparameters for Different Layers of the Model Network
|
||||
|
||||
In model training, if you want to set different optimization strategies for different parameters in the optimizer, such as setting different learning rates, weight decay, and other hyperparameters, you can achieve this by setting `paramwise_cfg` in the `optim_wrapper` of the configuration file.
|
||||
|
||||
The following config file uses the [ViT `optim_wrapper`](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/vit/vit_vit-b16-ln_mln_upernet_8xb2-160k_ade20k-512x512.py#L15-L27) as an example to introduce the use of `paramwise_cfg` parameters. During training, the weight decay parameter coefficients for the `pos_embed`, `mask_token`, and `norm` modules are set to 0. That is, during training, the weight decay for these modules will be changed to `weight_decay * decay_mult`=0.
|
||||
|
||||
```python
|
||||
optimizer = dict(
|
||||
type='AdamW', lr=0.00006, betas=(0.9, 0.999), weight_decay=0.01)
|
||||
optim_wrapper = dict(
|
||||
type='OptimWrapper',
|
||||
optimizer=optimizer,
|
||||
paramwise_cfg=dict(
|
||||
custom_keys={
|
||||
'pos_embed': dict(decay_mult=0.),
|
||||
'cls_token': dict(decay_mult=0.),
|
||||
'norm': dict(decay_mult=0.)
|
||||
}))
|
||||
```
|
||||
|
||||
Here, `decay_mult` refers to the weight decay coefficient for the corresponding parameters. For more information on the usage of `paramwise_cfg`, please refer to the [MMEngine optimizer wrapper documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/optim_wrapper.md).
|
||||
|
||||
### Optimizer Wrapper Constructor
|
||||
|
||||
The default optimizer wrapper constructor [`DefaultOptimWrapperConstructor`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/default_constructor.py#L19) builds the optimizer used in training based on the input `optim_wrapper` and `paramwise_cfg` defined in the `optim_wrapper`. When the functionality of [`DefaultOptimWrapperConstructor`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/default_constructor.py#L19) does not meet the requirements, you can customize the optimizer wrapper constructor to implement the configuration of hyperparameters.
|
||||
|
||||
MMSegmentation has implemented the [`LearningRateDecayOptimizerConstructor`](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/engine/optimizers/layer_decay_optimizer_constructor.py#L104), which can decay the learning rate of model parameters in the backbone networks of ConvNeXt, BEiT, and MAE models during training according to the defined decay ratio (`decay_rate`). The configuration in the configuration file is as follows:
|
||||
|
||||
```python
|
||||
optim_wrapper = dict(
|
||||
_delete_=True,
|
||||
type='AmpOptimWrapper',
|
||||
optimizer=dict(
|
||||
type='AdamW', lr=0.0001, betas=(0.9, 0.999), weight_decay=0.05),
|
||||
paramwise_cfg={
|
||||
'decay_rate': 0.9,
|
||||
'decay_type': 'stage_wise',
|
||||
'num_layers': 12
|
||||
},
|
||||
constructor='LearningRateDecayOptimizerConstructor',
|
||||
loss_scale='dynamic')
|
||||
```
|
||||
|
||||
The purpose of `_delete_=True` is to ignore the inherited configuration in the OpenMMLab Config. In this code snippet, the inherited `optim_wrapper` configuration is ignored. For more information on `_delete_` fields, please refer to the [MMEngine documentation](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/config.md#delete-key-in-dict).
|
||||
155
Seg_All_In_One_MMSeg/docs/en/advanced_guides/evaluation.md
Normal file
155
Seg_All_In_One_MMSeg/docs/en/advanced_guides/evaluation.md
Normal file
@@ -0,0 +1,155 @@
|
||||
# Evaluation
|
||||
|
||||
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).
|
||||
|
||||

|
||||
|
||||
In MMSegmentation, we write the settings of dataloader and metrics in the config files of datasets and the configuration of the evaluation loop in the `schedule_x` config files by default.
|
||||
|
||||
For example, in the ADE20K config file `configs/_base_/dataset/ade20k.py`, on lines 37 to 48, we configured the `val_dataloader`, on line 51, we select `IoUMetric` as the evaluator and set `mIoU` as the metric:
|
||||
|
||||
```python
|
||||
val_dataloader = dict(
|
||||
batch_size=1,
|
||||
num_workers=4,
|
||||
persistent_workers=True,
|
||||
sampler=dict(type='DefaultSampler', shuffle=False),
|
||||
dataset=dict(
|
||||
type=dataset_type,
|
||||
data_root=data_root,
|
||||
data_prefix=dict(
|
||||
img_path='images/validation',
|
||||
seg_map_path='annotations/validation'),
|
||||
pipeline=test_pipeline))
|
||||
|
||||
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
|
||||
```
|
||||
|
||||
To be able to evaluate the model during training, for example, we add the evaluation configuration to the file `configs/schedules/schedule_40k.py` on lines 15 to 16:
|
||||
|
||||
```python
|
||||
train_cfg = dict(type='IterBasedTrainLoop', max_iters=40000, val_interval=4000)
|
||||
val_cfg = dict(type='ValLoop')
|
||||
```
|
||||
|
||||
With the above two settings, MMSegmentation evaluates the **mIoU** metric of the model once every 4000 iterations during the training of 40K iterations.
|
||||
|
||||
If we would like to test the model after training, we need to add the `test_dataloader`, `test_evaluator` and `test_cfg` configs to the config file.
|
||||
|
||||
```python
|
||||
test_dataloader = dict(
|
||||
batch_size=1,
|
||||
num_workers=4,
|
||||
persistent_workers=True,
|
||||
sampler=dict(type='DefaultSampler', shuffle=False),
|
||||
dataset=dict(
|
||||
type=dataset_type,
|
||||
data_root=data_root,
|
||||
data_prefix=dict(
|
||||
img_path='images/validation',
|
||||
seg_map_path='annotations/validation'),
|
||||
pipeline=test_pipeline))
|
||||
|
||||
test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
|
||||
test_cfg = dict(type='TestLoop')
|
||||
```
|
||||
|
||||
In MMSegmentation, the settings of `test_dataloader` and `test_evaluator` are the same as the `ValLoop`'s dataloader and evaluator by default, we can modify these settings to meet our needs.
|
||||
|
||||
## IoUMetric
|
||||
|
||||
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.
|
||||
|
||||
Here we briefly describe the arguments and the two main methods of `IoUMetric`.
|
||||
|
||||
The constructor of `IoUMetric` has some additional parameters besides the base `collect_device` and `prefix`.
|
||||
|
||||
The arguments of the constructor:
|
||||
|
||||
- ignore_index (int) - Index that will be ignored in evaluation. Default: 255.
|
||||
- iou_metrics (list\[str\] | str) - Metrics to be calculated, the options includes 'mIoU', 'mDice' and 'mFscore'.
|
||||
- nan_to_num (int, optional) - If specified, NaN values will be replaced by the numbers defined by the user. Default: None.
|
||||
- beta (int) - Determines the weight of recall in the combined score. Default: 1.
|
||||
- collect_device (str) - Device name used for collecting results from different ranks during distributed training. Must be 'cpu' or 'gpu'. Defaults to 'cpu'.
|
||||
- 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.
|
||||
|
||||
`IoUMetric` implements the IoU metric calculation, the core two methods of `IoUMetric` are `process` and `compute_metrics`.
|
||||
|
||||
- `process` method processes one batch of data and data_samples.
|
||||
- `compute_metrics` method computes the metrics from processed results.
|
||||
|
||||
### IoUMetric.process
|
||||
|
||||
Parameters:
|
||||
|
||||
- data_batch (Any) - A batch of data from the dataloader.
|
||||
- data_samples (Sequence\[dict\]) - A batch of outputs from the model.
|
||||
|
||||
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
|
||||
|
||||
Parameters:
|
||||
|
||||
- results (list) - The processed results of each batch.
|
||||
|
||||
Returns:
|
||||
|
||||
- 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**.
|
||||
|
||||
## CityscapesMetric
|
||||
|
||||
`CityscapesMetric` uses the official [CityscapesScripts](https://github.com/mcordts/cityscapesScripts) provided by Cityscapes to evaluate model performance.
|
||||
|
||||
### Usage
|
||||
|
||||
Before using it, please install the `cityscapesscripts` package first:
|
||||
|
||||
```shell
|
||||
pip install cityscapesscripts
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```python
|
||||
val_evaluator = dict(type='CityscapesMetric', output_dir='tmp')
|
||||
test_evaluator = val_evaluator
|
||||
```
|
||||
|
||||
### Interface
|
||||
|
||||
The arguments of the constructor:
|
||||
|
||||
- output_dir (str) - The directory for output prediction
|
||||
- ignore_index (int) - Index that will be ignored in evaluation. Default: 255.
|
||||
- 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.
|
||||
- keep_results (bool) - Whether to keep the results. When `format_only` is True, `keep_results` must be True. Defaults to False.
|
||||
- collect_device (str) - Device name used for collecting results from different ranks during distributed training. Must be 'cpu' or 'gpu'. Defaults to 'cpu'.
|
||||
- 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.
|
||||
|
||||
#### CityscapesMetric.process
|
||||
|
||||
This method would draw the masks on images and save the painted images to `work_dir`.
|
||||
|
||||
Parameters:
|
||||
|
||||
- data_batch (dict) - A batch of data from the dataloader.
|
||||
- data_samples (Sequence\[dict\]) - A batch of outputs from the model.
|
||||
|
||||
Returns:
|
||||
|
||||
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.
|
||||
|
||||
#### CityscapesMetric.compute_metrics
|
||||
|
||||
This method would call `cityscapesscripts.evaluation.evalPixelLevelSemanticLabeling` tool to calculate metrics.
|
||||
|
||||
Parameters:
|
||||
|
||||
- results (list) - Testing results of the dataset.
|
||||
|
||||
Returns:
|
||||
|
||||
- dict\[str: float\] - Cityscapes evaluation results.
|
||||
26
Seg_All_In_One_MMSeg/docs/en/advanced_guides/index.rst
Normal file
26
Seg_All_In_One_MMSeg/docs/en/advanced_guides/index.rst
Normal file
@@ -0,0 +1,26 @@
|
||||
Basic Concepts
|
||||
***************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
data_flow.md
|
||||
structures.md
|
||||
models.md
|
||||
datasets.md
|
||||
transforms.md
|
||||
evaluation.md
|
||||
engine.md
|
||||
training_tricks.md
|
||||
|
||||
Component Customization
|
||||
************************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
add_models.md
|
||||
add_datasets.md
|
||||
add_transforms.md
|
||||
add_metrics.md
|
||||
customize_runtime.md
|
||||
164
Seg_All_In_One_MMSeg/docs/en/advanced_guides/models.md
Normal file
164
Seg_All_In_One_MMSeg/docs/en/advanced_guides/models.md
Normal file
@@ -0,0 +1,164 @@
|
||||
# Models
|
||||
|
||||
We usually define a neural network in a deep learning task as a model, and this model is the core of an algorithm. [MMEngine](https://github.com/open-mmlab/mmengine) abstracts a unified model [BaseModel](https://github.com/open-mmlab/mmengine/blob/main/mmengine/model/base_model/base_model.py#L16) to standardize the interfaces for training, testing and other processes. All models implemented by MMSegmentation inherit from `BaseModel`, and in MMSegmentation we implemented forward and added some functions for the semantic segmentation algorithm.
|
||||
|
||||
## Common components
|
||||
|
||||
### Segmentor
|
||||
|
||||
In MMSegmentation, we abstract the network architecture as a **Segmentor**, it is a model that contains all components of a network. We have already implemented **EncoderDecoder** and **CascadeEncoderDecoder**, which typically consist of **Data preprocessor**, **Backbone**, **Decode head** and **Auxiliary head**.
|
||||
|
||||
### Data preprocessor
|
||||
|
||||
**Data preprocessor** is the part that copies data to the target device and preprocesses the data into the model input format.
|
||||
|
||||
### Backbone
|
||||
|
||||
**Backbone** is the part that transforms an image to feature maps, such as a **ResNet-50** without the last fully connected layer.
|
||||
|
||||
### Neck
|
||||
|
||||
**Neck** is the part that connects the backbone and heads. It performs some refinements or reconfigurations on the raw feature maps produced by the backbone. An example is **Feature Pyramid Network (FPN)**.
|
||||
|
||||
### Decode head
|
||||
|
||||
**Decode head** is the part that transforms the feature maps into a segmentation mask, such as **PSPNet**.
|
||||
|
||||
### Auxiliary head
|
||||
|
||||
**Auxiliary head** is an optional component that transforms the feature maps into segmentation masks which only used for computing auxiliary losses.
|
||||
|
||||
## Basic interfaces
|
||||
|
||||
MMSegmentation wraps `BaseModel` and implements the [BaseSegmentor](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/models/segmentors/base.py#L15) class, which mainly provides the interfaces `forward`, `train_step`, `val_step` and `test_step`. The following will introduce these interfaces in detail.
|
||||
|
||||
### forward
|
||||
|
||||

|
||||

|
||||
|
||||
The `forward` method returns losses or predictions of training, validation, testing, and a simple inference process.
|
||||
|
||||
The method should accept three modes: "tensor", "predict" and "loss":
|
||||
|
||||
- "tensor": Forward the whole network and return the tensor or tuple of tensor without any post-processing, same as a common `nn.Module`.
|
||||
- "predict": Forward and return the predictions, which are fully processed to a list of `SegDataSample`.
|
||||
- "loss": Forward and return a `dict` of losses according to the given inputs and data samples.
|
||||
|
||||
**Note:** [SegDataSample](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/structures/seg_data_sample.py) is a data structure interface of MMSegmentation, it is used as an interface between different components. `SegDataSample` implements the abstract data element `mmengine.structures.BaseDataElement`, please refer to [the SegDataSample documentation](https://mmsegmentation.readthedocs.io/en/1.x/advanced_guides/structures.html) and [data element documentation](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/data_element.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
Note that this method doesn't handle either backpropagation or optimizer updating, which are done in the method `train_step`.
|
||||
|
||||
Parameters:
|
||||
|
||||
- inputs (torch.Tensor) - The input tensor with shape (N, C, ...) in general.
|
||||
- data_sample (list\[[SegDataSample](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/structures/seg_data_sample.py)\]) - The seg data samples. It usually includes information such as `metainfo` and `gt_sem_seg`. Default to None.
|
||||
- mode (str) - Return what kind of value. Defaults to 'tensor'.
|
||||
|
||||
Returns:
|
||||
|
||||
- `dict` or `list`:
|
||||
- If `mode == "loss"`, return a `dict` of loss tensor used for backward and logging.
|
||||
- If `mode == "predict"`, return a `list` of `SegDataSample`, the inference results will be incrementally added to the `data_sample` parameter passed to the forward method, each `SegDataSample` contains the following keys:
|
||||
- pred_sem_seg (`PixelData`): Prediction of semantic segmentation.
|
||||
- seg_logits (`PixelData`): Predicted logits of semantic segmentation before normalization.
|
||||
- If `mode == "tensor"`, return a `tensor` or `tuple of tensor` or `dict` of `tensor` for custom use.
|
||||
|
||||
### prediction modes
|
||||
|
||||
We briefly describe the fields of the model's configuration in [the config documentation](../user_guides/1_config.md), here we elaborate on the `model.test_cfg` field. `model.test_cfg` is used to control forward behavior, the `forward` method in `"predict"` mode can run in two modes:
|
||||
|
||||
- `whole_inference`: If `cfg.model.test_cfg.mode == 'whole'`, model will inference with full images.
|
||||
|
||||
An `whole_inference` mode example config:
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
type='EncoderDecoder'
|
||||
...
|
||||
test_cfg=dict(mode='whole')
|
||||
)
|
||||
```
|
||||
|
||||
- `slide_inference`: If `cfg.model.test_cfg.mode == 'slide'`, model will inference by sliding-window. **Note:** if you select the `slide` mode, `cfg.model.test_cfg.stride` and `cfg.model.test_cfg.crop_size` should also be specified.
|
||||
|
||||
An `slide_inference` mode example config:
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
type='EncoderDecoder'
|
||||
...
|
||||
test_cfg=dict(mode='slide', crop_size=256, stride=170)
|
||||
)
|
||||
```
|
||||
|
||||
### train_step
|
||||
|
||||
The `train_step` method calls the forward interface of the `loss` mode to get the loss `dict`. The `BaseModel` class implements the default model training process including preprocessing, model forward propagation, loss calculation, optimization, and back-propagation.
|
||||
|
||||
Parameters:
|
||||
|
||||
- data (dict or tuple or list) - Data sampled from the dataset. In MMSegmentation, the data dict contains `inputs` and `data_samples` two fields.
|
||||
- optim_wrapper (OptimWrapper) - OptimWrapper instance used to update model parameters.
|
||||
|
||||
**Note:** [OptimWrapper](https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/optimizer_wrapper.py#L17) provides a common interface for updating parameters, please refer to optimizer wrapper [documentation](https://mmengine.readthedocs.io/en/latest/tutorials/optim_wrapper.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
Returns:
|
||||
|
||||
- Dict\[str, `torch.Tensor`\]: A `dict` of tensor for logging.
|
||||
|
||||

|
||||
|
||||
### val_step
|
||||
|
||||
The `val_step` method calls the forward interface of the `predict` mode and returns the prediction result, which is further passed to the process interface of the evaluator and the `after_val_iter` interface of the Hook.
|
||||
|
||||
Parameters:
|
||||
|
||||
- data (`dict` or `tuple` or `list`) - Data sampled from the dataset. In MMSegmentation, the data dict contains `inputs` and `data_samples` two fields.
|
||||
|
||||
Returns:
|
||||
|
||||
- `list` - The predictions of given data.
|
||||
|
||||

|
||||
|
||||
### test_step
|
||||
|
||||
The `BaseModel` implements `test_step` the same as `val_step`.
|
||||
|
||||
## Data Preprocessor
|
||||
|
||||
The [SegDataPreProcessor](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/models/data_preprocessor.py#L13) implemented by MMSegmentation inherits from the [BaseDataPreprocessor](https://github.com/open-mmlab/mmengine/blob/main/mmengine/model/base_model/data_preprocessor.py#L18) implemented by [MMEngine](https://github.com/open-mmlab/mmengine) and provides the functions of data preprocessing and copying data to the target device.
|
||||
|
||||
The runner carries the model to the specified device during the construction stage, while the data is carried to the specified device by the [SegDataPreProcessor](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/models/data_preprocessor.py#L13) in `train_step`, `val_step`, and `test_step`, and the processed data is further passed to the model.
|
||||
|
||||
The parameters of the `SegDataPreProcessor` constructor:
|
||||
|
||||
- mean (Sequence\[Number\], optional) - The pixel mean of R, G, B channels. Defaults to None.
|
||||
- std (Sequence\[Number\], optional) - The pixel standard deviation of R, G, B channels. Defaults to None.
|
||||
- size (tuple, optional) - Fixed padding size.
|
||||
- size_divisor (int, optional) - The divisor of padded size.
|
||||
- pad_val (float, optional) - Padding value. Default: 0.
|
||||
- seg_pad_val (float, optional) - Padding value of segmentation map. Default: 255.
|
||||
- bgr_to_rgb (bool) - whether to convert image from BGR to RGB. Defaults to False.
|
||||
- rgb_to_bgr (bool) - whether to convert image from RGB to BGR. Defaults to False.
|
||||
- batch_augments (list\[dict\], optional) - Batch-level augmentations. Default to None.
|
||||
|
||||
The data will be processed as follows:
|
||||
|
||||
- Collate and move data to the target device.
|
||||
- Pad inputs to the input size with defined `pad_val`, and pad seg map with defined `seg_pad_val`.
|
||||
- Stack inputs to batch_inputs.
|
||||
- Convert inputs from bgr to rgb if the shape of input is (3, H, W).
|
||||
- Normalize image with defined std and mean.
|
||||
- Do batch augmentations like Mixup and Cutmix during training.
|
||||
|
||||
The parameters of the `forward` method:
|
||||
|
||||
- data (dict) - data sampled from dataloader.
|
||||
- training (bool) - Whether to enable training time augmentation.
|
||||
|
||||
The returns of the `forward` method:
|
||||
|
||||
- Dict: Data in the same format as the model input.
|
||||
104
Seg_All_In_One_MMSeg/docs/en/advanced_guides/structures.md
Normal file
104
Seg_All_In_One_MMSeg/docs/en/advanced_guides/structures.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# Structures
|
||||
|
||||
To unify input and output interfaces between different models and modules, OpenMMLab 2.0 MMEngine defines an abstract data structure,
|
||||
it has implemented basic functions of `Create`, `Read`, `Update`, `Delete`, supported data transferring among different types of devices
|
||||
and tensor-like or dictionary-like operations such as `.cpu()`, `.cuda()`, `.get()` and `.detach()`.
|
||||
More details can be found [here](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/data_element.md).
|
||||
|
||||
MMSegmentation also follows this interface protocol and defines `SegDataSample` which is used to encapsulate the data of semantic segmentation task.
|
||||
|
||||
## Semantic Segmentation Data SegDataSample
|
||||
|
||||
[SegDataSample](mmseg.structures.SegDataSample) includes three main fields `gt_sem_seg`, `pred_sem_seg` and `seg_logits`, which are used to store the annotation information and prediction results respectively.
|
||||
|
||||
| Field | Type | Description |
|
||||
| -------------- | ------------------------- | ------------------------------------------ |
|
||||
| gt_sem_seg | [`PixelData`](#pixeldata) | Annotation information. |
|
||||
| pred_instances | [`PixelData`](#pixeldata) | The predicted result. |
|
||||
| seg_logits | [`PixelData`](#pixeldata) | The raw (non-normalized) predicted result. |
|
||||
|
||||
The following sample code demonstrates the use of `SegDataSample`.
|
||||
|
||||
```python
|
||||
import torch
|
||||
from mmengine.structures import PixelData
|
||||
from mmseg.structures import SegDataSample
|
||||
|
||||
img_meta = dict(img_shape=(4, 4, 3),
|
||||
pad_shape=(4, 4, 3))
|
||||
data_sample = SegDataSample()
|
||||
# defining gt_segmentations for encapsulate the ground truth data
|
||||
gt_segmentations = PixelData(metainfo=img_meta)
|
||||
gt_segmentations.data = torch.randint(0, 2, (1, 4, 4))
|
||||
|
||||
# add and process property in SegDataSample
|
||||
data_sample.gt_sem_seg = gt_segmentations
|
||||
assert 'gt_sem_seg' in data_sample
|
||||
assert 'sem_seg' in data_sample.gt_sem_seg
|
||||
assert 'img_shape' in data_sample.gt_sem_seg.metainfo_keys()
|
||||
print(data_sample.gt_sem_seg.shape)
|
||||
'''
|
||||
(4, 4)
|
||||
'''
|
||||
print(data_sample)
|
||||
'''
|
||||
<SegDataSample(
|
||||
|
||||
META INFORMATION
|
||||
|
||||
DATA FIELDS
|
||||
gt_sem_seg: <PixelData(
|
||||
|
||||
META INFORMATION
|
||||
img_shape: (4, 4, 3)
|
||||
pad_shape: (4, 4, 3)
|
||||
|
||||
DATA FIELDS
|
||||
data: tensor([[[1, 1, 1, 0],
|
||||
[1, 0, 1, 1],
|
||||
[1, 1, 1, 1],
|
||||
[0, 1, 0, 1]]])
|
||||
) at 0x1c2b4156460>
|
||||
) at 0x1c2aae44d60>
|
||||
'''
|
||||
|
||||
# delete and change property in SegDataSample
|
||||
data_sample = SegDataSample()
|
||||
gt_segmentations = PixelData(metainfo=img_meta)
|
||||
gt_segmentations.data = torch.randint(0, 2, (1, 4, 4))
|
||||
data_sample.gt_sem_seg = gt_segmentations
|
||||
data_sample.gt_sem_seg.set_metainfo(dict(img_shape=(4,4,9), pad_shape=(4,4,9)))
|
||||
del data_sample.gt_sem_seg.img_shape
|
||||
|
||||
# Tensor-like operations
|
||||
data_sample = SegDataSample()
|
||||
gt_segmentations = PixelData(metainfo=img_meta)
|
||||
gt_segmentations.data = torch.randint(0, 2, (1, 4, 4))
|
||||
cuda_gt_segmentations = gt_segmentations.cuda()
|
||||
cuda_gt_segmentations = gt_segmentations.to('cuda:0')
|
||||
cpu_gt_segmentations = cuda_gt_segmentations.cpu()
|
||||
cpu_gt_segmentations = cuda_gt_segmentations.to('cpu')
|
||||
```
|
||||
|
||||
## Customize New Property in SegDataSample
|
||||
|
||||
If you want to customize new property in `SegDataSample`, you may follow [SegDataSample](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/structures/seg_data_sample.py) below:
|
||||
|
||||
```python
|
||||
class SegDataSample(BaseDataElement):
|
||||
...
|
||||
|
||||
@property
|
||||
def xxx_property(self) -> xxxData:
|
||||
return self._xxx_property
|
||||
|
||||
@xxx_property.setter
|
||||
def xxx_property(self, value: xxxData) -> None:
|
||||
self.set_field(value, '_xxx_property', dtype=xxxData)
|
||||
|
||||
@xxx_property.deleter
|
||||
def xxx_property(self) -> None:
|
||||
del self._xxx_property
|
||||
```
|
||||
|
||||
Then a new property would be added to `SegDataSample`.
|
||||
@@ -0,0 +1,75 @@
|
||||
# Training Tricks
|
||||
|
||||
MMSegmentation support following training tricks out of box.
|
||||
|
||||
## Different Learning Rate(LR) for Backbone and Heads
|
||||
|
||||
In semantic segmentation, some methods make the LR of heads larger than backbone to achieve better performance or faster convergence.
|
||||
|
||||
In MMSegmentation, you may add following lines to config to make the LR of heads 10 times of backbone.
|
||||
|
||||
```python
|
||||
optim_wrapper=dict(
|
||||
paramwise_cfg = dict(
|
||||
custom_keys={
|
||||
'head': dict(lr_mult=10.)}))
|
||||
```
|
||||
|
||||
With this modification, the LR of any parameter group with `'head'` in name will be multiplied by 10.
|
||||
You may refer to [MMEngine documentation](https://mmengine.readthedocs.io/en/latest/tutorials/optim_wrapper.html#advanced-usages) for further details.
|
||||
|
||||
## Online Hard Example Mining (OHEM)
|
||||
|
||||
We implement pixel sampler for training sampling, like OHEM (Online Hard Example Mining),
|
||||
which is used for remove the "easy" examples for model training.
|
||||
Here is an example config of training PSPNet with OHEM enabled.
|
||||
|
||||
```python
|
||||
_base_ = './pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
model=dict(
|
||||
decode_head=dict(
|
||||
sampler=dict(type='OHEMPixelSampler', thresh=0.7, min_kept=100000)) )
|
||||
```
|
||||
|
||||
In this way, only pixels with confidence score under 0.7 are used to train. And we keep at least 100000 pixels during training. If `thresh` is not specified, pixels of top `min_kept` loss will be selected.
|
||||
|
||||
## Class Balanced Loss
|
||||
|
||||
For dataset that is not balanced in classes distribution, you may change the loss weight of each class.
|
||||
Here is an example for cityscapes dataset.
|
||||
|
||||
```python
|
||||
_base_ = './pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
model=dict(
|
||||
decode_head=dict(
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0,
|
||||
# DeepLab used this class weight for cityscapes
|
||||
class_weight=[0.8373, 0.9180, 0.8660, 1.0345, 1.0166, 0.9969, 0.9754,
|
||||
1.0489, 0.8786, 1.0023, 0.9539, 0.9843, 1.1116, 0.9037,
|
||||
1.0865, 1.0955, 1.0865, 1.1529, 1.0507])))
|
||||
```
|
||||
|
||||
`class_weight` will be passed into `CrossEntropyLoss` as `weight` argument. Please refer to [PyTorch Doc](https://pytorch.org/docs/stable/nn.html?highlight=crossentropy#torch.nn.CrossEntropyLoss) for details.
|
||||
|
||||
## Multiple Losses
|
||||
|
||||
For loss calculation, we support multiple losses training concurrently. Here is an example config of training `unet` on `DRIVE` dataset, whose loss function is `1:3` weighted sum of `CrossEntropyLoss` and `DiceLoss`:
|
||||
|
||||
```python
|
||||
_base_ = './fcn_unet_s5-d16_64x64_40k_drive.py'
|
||||
model = dict(
|
||||
decode_head=dict(loss_decode=[
|
||||
dict(type='CrossEntropyLoss', loss_name='loss_ce', loss_weight=1.0),
|
||||
dict(type='DiceLoss', loss_name='loss_dice', loss_weight=3.0)
|
||||
]),
|
||||
auxiliary_head=dict(loss_decode=[
|
||||
dict(type='CrossEntropyLoss', loss_name='loss_ce', loss_weight=1.0),
|
||||
dict(type='DiceLoss', loss_name='loss_dice', loss_weight=3.0)
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
In this way, `loss_weight` and `loss_name` will be weight and name in training log of corresponding loss, respectively.
|
||||
|
||||
Note: If you want this loss item to be included into the backward graph, `loss_` must be the prefix of the name.
|
||||
119
Seg_All_In_One_MMSeg/docs/en/advanced_guides/transforms.md
Normal file
119
Seg_All_In_One_MMSeg/docs/en/advanced_guides/transforms.md
Normal file
@@ -0,0 +1,119 @@
|
||||
# Data Transforms
|
||||
|
||||
In this tutorial, we introduce the design of transforms pipeline in MMSegmentation.
|
||||
|
||||
The structure of this guide is as follows:
|
||||
|
||||
- [Data Transforms](#data-transforms)
|
||||
- [Design of Data pipelines](#design-of-data-pipelines)
|
||||
- [Data loading](#data-loading)
|
||||
- [Pre-processing](#pre-processing)
|
||||
- [Formatting](#formatting)
|
||||
|
||||
## Design of Data pipelines
|
||||
|
||||
Following typical conventions, we use `Dataset` and `DataLoader` for data loading with multiple workers. `Dataset` returns a dict of data items corresponding the arguments of models' forward method. Since the data in semantic segmentation may not be the same size, we introduce a new `DataContainer` type in MMCV to help collect and distribute data of different size. See [here](https://github.com/open-mmlab/mmcv/blob/master/mmcv/parallel/data_container.py) for more details.
|
||||
|
||||
In 1.x version of MMSegmentation, all data transformations are inherited from [`BaseTransform`](https://github.com/open-mmlab/mmcv/blob/2.x/mmcv/transforms/base.py#L6).
|
||||
|
||||
The input and output types of transformations are both dict. A simple example is as follows:
|
||||
|
||||
```python
|
||||
>>> from mmseg.datasets.transforms import LoadAnnotations
|
||||
>>> transforms = LoadAnnotations()
|
||||
>>> img_path = './data/cityscapes/leftImg8bit/train/aachen/aachen_000000_000019_leftImg8bit.png.png'
|
||||
>>> gt_path = './data/cityscapes/gtFine/train/aachen/aachen_000015_000019_gtFine_instanceTrainIds.png'
|
||||
>>> results = dict(
|
||||
>>> img_path=img_path,
|
||||
>>> seg_map_path=gt_path,
|
||||
>>> reduce_zero_label=False,
|
||||
>>> seg_fields=[])
|
||||
>>> data_dict = transforms(results)
|
||||
>>> print(data_dict.keys())
|
||||
dict_keys(['img_path', 'seg_map_path', 'reduce_zero_label', 'seg_fields', 'gt_seg_map'])
|
||||
```
|
||||
|
||||
The data preparation pipeline and the dataset are decomposed. Usually a dataset defines how to process the annotations and a data pipeline defines all the steps to prepare a data dict. A pipeline consists of a sequence of operations. Each operation takes a dict as input and also outputs a dict for the next transform.
|
||||
|
||||
The operations are categorized into data loading, pre-processing, formatting and test-time augmentation.
|
||||
|
||||
Here is a pipeline example for PSPNet:
|
||||
|
||||
```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', prob=0.5),
|
||||
dict(type='PhotoMetricDistortion'),
|
||||
dict(type='PackSegInputs')
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='Resize', scale=(2048, 1024), keep_ratio=True),
|
||||
# add loading annotation after ``Resize`` because ground truth
|
||||
# does not need to resize data transform
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='PackSegInputs')
|
||||
]
|
||||
```
|
||||
|
||||
For each operation, we list the related dict fields that are `added`/`updated`/`removed`. Before pipelines, the information we can directly obtain from the datasets are `img_path` and `seg_map_path`.
|
||||
|
||||
### Data loading
|
||||
|
||||
`LoadImageFromFile`: Load an image from file.
|
||||
|
||||
- add: `img`, `img_shape`, `ori_shape`
|
||||
|
||||
`LoadAnnotations`: Load semantic segmentation maps provided by dataset.
|
||||
|
||||
- add: `seg_fields`, `gt_seg_map`
|
||||
|
||||
### Pre-processing
|
||||
|
||||
`RandomResize`: Random resize image & segmentation map.
|
||||
|
||||
- add: `scale`, `scale_factor`, `keep_ratio`
|
||||
- update: `img`, `img_shape`, `gt_seg_map`
|
||||
|
||||
`Resize`: Resize image & segmentation map.
|
||||
|
||||
- add: `scale`, `scale_factor`, `keep_ratio`
|
||||
- update: `img`, `gt_seg_map`, `img_shape`
|
||||
|
||||
`RandomCrop`: Random crop image & segmentation map.
|
||||
|
||||
- update: `img`, `gt_seg_map`, `img_shape`
|
||||
|
||||
`RandomFlip`: Flip the image & segmentation map.
|
||||
|
||||
- add: `flip`, `flip_direction`
|
||||
- update: `img`, `gt_seg_map`
|
||||
|
||||
`PhotoMetricDistortion`: Apply photometric distortion to image sequentially, every transformation is applied with a probability of 0.5. The position of random contrast is in second or second to last(mode 0 or 1 below, respectively).
|
||||
|
||||
```
|
||||
1. random brightness
|
||||
2. random contrast (mode 0)
|
||||
3. convert color from BGR to HSV
|
||||
4. random saturation
|
||||
5. random hue
|
||||
6. convert color from HSV to BGR
|
||||
7. random contrast (mode 1)
|
||||
```
|
||||
|
||||
- update: `img`
|
||||
|
||||
### Formatting
|
||||
|
||||
`PackSegInputs`: Pack the inputs data for the semantic segmentation.
|
||||
|
||||
- add: `inputs`, `data_sample`
|
||||
- remove: keys specified by `meta_keys` (merged into the metainfo of data_sample), all other keys
|
||||
95
Seg_All_In_One_MMSeg/docs/en/api.rst
Normal file
95
Seg_All_In_One_MMSeg/docs/en/api.rst
Normal file
@@ -0,0 +1,95 @@
|
||||
mmseg.apis
|
||||
--------------
|
||||
.. automodule:: mmseg.apis
|
||||
:members:
|
||||
|
||||
mmseg.datasets
|
||||
--------------
|
||||
|
||||
datasets
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets
|
||||
:members:
|
||||
|
||||
transforms
|
||||
^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.datasets.transforms
|
||||
:members:
|
||||
|
||||
mmseg.engine
|
||||
--------------
|
||||
|
||||
hooks
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.engine.hooks
|
||||
:members:
|
||||
|
||||
optimizers
|
||||
^^^^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.engine.optimizers
|
||||
:members:
|
||||
|
||||
mmseg.evaluation
|
||||
-----------------
|
||||
|
||||
metrics
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.evaluation.metrics
|
||||
:members:
|
||||
|
||||
mmseg.models
|
||||
--------------
|
||||
|
||||
backbones
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.backbones
|
||||
:members:
|
||||
|
||||
decode_heads
|
||||
^^^^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.decode_heads
|
||||
:members:
|
||||
|
||||
segmentors
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.segmentors
|
||||
:members:
|
||||
|
||||
losses
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.losses
|
||||
:members:
|
||||
|
||||
necks
|
||||
^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.necks
|
||||
:members:
|
||||
|
||||
utils
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.models.utils
|
||||
:members:
|
||||
|
||||
|
||||
mmseg.structures
|
||||
--------------------
|
||||
|
||||
structures
|
||||
^^^^^^^^^^^^^^^^^
|
||||
.. automodule:: mmseg.structures
|
||||
:members:
|
||||
|
||||
sampler
|
||||
^^^^^^^^^^
|
||||
.. automodule:: mmseg.structures.sampler
|
||||
:members:
|
||||
|
||||
mmseg.visualization
|
||||
--------------------
|
||||
.. automodule:: mmseg.visualization
|
||||
:members:
|
||||
|
||||
mmseg.utils
|
||||
--------------
|
||||
.. automodule:: mmseg.utils
|
||||
:members:
|
||||
133
Seg_All_In_One_MMSeg/docs/en/conf.py
Normal file
133
Seg_All_In_One_MMSeg/docs/en/conf.py
Normal file
@@ -0,0 +1,133 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytorch_sphinx_theme
|
||||
|
||||
sys.path.insert(0, os.path.abspath('../../'))
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'MMSegmentation'
|
||||
copyright = '2020-2021, OpenMMLab'
|
||||
author = 'MMSegmentation Authors'
|
||||
version_file = '../../mmseg/version.py'
|
||||
|
||||
|
||||
def get_version():
|
||||
with open(version_file) as f:
|
||||
exec(compile(f.read(), version_file, 'exec'))
|
||||
return locals()['__version__']
|
||||
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = get_version()
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx.ext.viewcode',
|
||||
'sphinx_markdown_tables', 'sphinx_copybutton', 'myst_parser'
|
||||
]
|
||||
|
||||
autodoc_mock_imports = [
|
||||
'matplotlib', 'pycocotools', 'mmseg.version', 'mmcv.ops'
|
||||
]
|
||||
|
||||
# Ignore >>> when copying code
|
||||
copybutton_prompt_text = r'>>> |\.\.\. '
|
||||
copybutton_prompt_is_regexp = True
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
source_suffix = {
|
||||
'.rst': 'restructuredtext',
|
||||
'.md': 'markdown',
|
||||
}
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
# html_theme = 'sphinx_rtd_theme'
|
||||
html_theme = 'pytorch_sphinx_theme'
|
||||
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
|
||||
html_theme_options = {
|
||||
'logo_url':
|
||||
'https://mmsegmentation.readthedocs.io/en/latest/',
|
||||
'menu': [
|
||||
{
|
||||
'name':
|
||||
'Tutorial',
|
||||
'url':
|
||||
'https://github.com/open-mmlab/mmsegmentation/blob/master/'
|
||||
'demo/MMSegmentation_Tutorial.ipynb'
|
||||
},
|
||||
{
|
||||
'name': 'GitHub',
|
||||
'url': 'https://github.com/open-mmlab/mmsegmentation'
|
||||
},
|
||||
{
|
||||
'name':
|
||||
'Upstream',
|
||||
'children': [
|
||||
{
|
||||
'name': 'MMCV',
|
||||
'url': 'https://github.com/open-mmlab/mmcv',
|
||||
'description': 'Foundational library for computer vision'
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
# Specify the language of shared menu
|
||||
'menu_lang':
|
||||
'en'
|
||||
}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
html_css_files = ['css/readthedocs.css']
|
||||
|
||||
# Enable ::: for my_st
|
||||
myst_enable_extensions = ['colon_fence']
|
||||
|
||||
language = 'en'
|
||||
|
||||
|
||||
def builder_inited_handler(app):
|
||||
subprocess.run(['./stat.py'])
|
||||
|
||||
|
||||
def setup(app):
|
||||
app.connect('builder-inited', builder_inited_handler)
|
||||
39
Seg_All_In_One_MMSeg/docs/en/device/npu.md
Normal file
39
Seg_All_In_One_MMSeg/docs/en/device/npu.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# NPU (HUAWEI Ascend)
|
||||
|
||||
## Usage
|
||||
|
||||
Please refer to the [building documentation of MMCV](https://mmcv.readthedocs.io/en/latest/get_started/build.html#build-mmcv-full-on-ascend-npu-machine) to install MMCV on NPU devices
|
||||
|
||||
Here we use 4 NPUs on your computer to train the model with the following command:
|
||||
|
||||
```shell
|
||||
bash tools/dist_train.sh configs/deeplabv3/deeplabv3_r50-d8_4xb2-40k_cityscapes-512x1024.py 4
|
||||
```
|
||||
|
||||
Also, you can use only one NPU to train the model with the following command:
|
||||
|
||||
```shell
|
||||
python tools/train.py configs/deeplabv3/deeplabv3_r50-d8_4xb2-40k_cityscapes-512x1024.py
|
||||
```
|
||||
|
||||
## Models Results
|
||||
|
||||
| Model | mIoU | Config | Download |
|
||||
| :-----------------: | :---: | :----------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| [deeplabv3](<>) | 78.85 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/deeplabv3/deeplabv3_r50-d8_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/deeplabv3_r50-d8_4xb2-40k_cityscapes-512x1024_20230115_205626.json) |
|
||||
| [deeplabv3plus](<>) | 79.23 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/deeplabv3plus/deeplabv3plus_r50-d8_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/deeplabv3plus_r50-d8_4xb2-40k_cityscapes-512x1024_20230116_043450.json) |
|
||||
| [hrnet](<>) | 78.1 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/hrnet/fcn_hr18_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/fcn_hr18_4xb2-40k_cityscapes-512x1024_20230116_215821.json) |
|
||||
| [fcn](<>) | 74.15 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/fcn/fcn_r50-d8_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/fcn_r50-d8_4xb2-40k_cityscapes-512x1024_20230111_083014.json) |
|
||||
| [icnet](<>) | 69.25 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/icnet/icnet_r50-d8_4xb2-80k_cityscapes-832x832.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/icnet_r50-d8_4xb2-80k_cityscapes-832x832_20230119_002929.json) |
|
||||
| [pspnet](<>) | 77.21 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/pspnet/pspnet_r50b-d8_4xb2-80k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/pspnet_r50b-d8_4xb2-80k_cityscapes-512x1024_20230114_042721.json) |
|
||||
| [unet](<>) | 68.86 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/unet/unet-s5-d16_fcn_4xb4-160k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/unet-s5-d16_fcn_4xb4-160k_cityscapes-512x1024_20230129_224750.json) |
|
||||
| [upernet](<>) | 77.81 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/upernet/upernet_r50_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/upernet_r50_4xb2-40k_cityscapes-512x1024_20230129_014634.json) |
|
||||
| [apcnet](<>) | 78.02 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/apcnet/apcnet_r50-d8_4xb2-40k_cityscapes-512x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/apcnet_r50-d8_4xb2-40k_cityscapes-512x1024_20230209_212545.json) |
|
||||
| [bisenetv1](<>) | 76.04 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/bisenetv1/bisenetv1_r50-d32_4xb4-160k_cityscapes-1024x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/bisenetv1_r50-d32_4xb4-160k_cityscapes-1024x1024_20230201_023946.json) |
|
||||
| [bisenetv2](<>) | 72.44 | [config](https://github.com/open-mmlab/mmsegmentation/tree/1.x/configs/bisenetv2/bisenetv2_fcn_4xb4-amp-160k_cityscapes-1024x1024.py) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/device/npu/bisenetv2_fcn_4xb4-amp-160k_cityscapes-1024x1024_20230205_215606.json) |
|
||||
|
||||
**Notes:**
|
||||
|
||||
- If not specially marked, the results on NPU with amp are the basically same as those on the GPU with FP32.
|
||||
|
||||
**All above models are provided by Huawei Ascend group.**
|
||||
211
Seg_All_In_One_MMSeg/docs/en/get_started.md
Normal file
211
Seg_All_In_One_MMSeg/docs/en/get_started.md
Normal file
@@ -0,0 +1,211 @@
|
||||
# Get started: Install and Run MMSeg
|
||||
|
||||
## Prerequisites
|
||||
|
||||
In this section we demonstrate how to prepare an environment with PyTorch.
|
||||
|
||||
MMSegmentation works on Linux, Windows and macOS. It requires Python 3.7+, CUDA 10.2+ and PyTorch 1.8+.
|
||||
|
||||
**Note:**
|
||||
If you are experienced with PyTorch and have already installed it, just skip this part and jump to the [next section](##installation). Otherwise, you can follow these steps for the preparation.
|
||||
|
||||
**Step 0.** Download and install Miniconda from the [official website](https://docs.conda.io/en/latest/miniconda.html).
|
||||
|
||||
**Step 1.** Create a conda environment and activate it.
|
||||
|
||||
```shell
|
||||
conda create --name openmmlab python=3.8 -y
|
||||
conda activate openmmlab
|
||||
```
|
||||
|
||||
**Step 2.** Install PyTorch following [official instructions](https://pytorch.org/get-started/locally/), e.g.
|
||||
|
||||
On GPU platforms:
|
||||
|
||||
```shell
|
||||
conda install pytorch torchvision -c pytorch
|
||||
```
|
||||
|
||||
On CPU platforms:
|
||||
|
||||
```shell
|
||||
conda install pytorch torchvision cpuonly -c pytorch
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
We recommend that users follow our best practices to install MMSegmentation. However, the whole process is highly customizable. See [Customize Installation](#customize-installation) section for more information.
|
||||
|
||||
### Best Practices
|
||||
|
||||
**Step 0.** Install [MMCV](https://github.com/open-mmlab/mmcv) using [MIM](https://github.com/open-mmlab/mim).
|
||||
|
||||
```shell
|
||||
pip install -U openmim
|
||||
mim install mmengine
|
||||
mim install "mmcv>=2.0.0"
|
||||
```
|
||||
|
||||
**Step 1.** Install MMSegmentation.
|
||||
|
||||
Case a: If you develop and run mmseg directly, install it from source:
|
||||
|
||||
```shell
|
||||
git clone -b main https://github.com/open-mmlab/mmsegmentation.git
|
||||
cd mmsegmentation
|
||||
pip install -v -e .
|
||||
# '-v' means verbose, or more output
|
||||
# '-e' means installing a project in editable mode,
|
||||
# thus any local modifications made to the code will take effect without reinstallation.
|
||||
```
|
||||
|
||||
Case b: If you use mmsegmentation as a dependency or third-party package, install it with pip:
|
||||
|
||||
```shell
|
||||
pip install "mmsegmentation>=1.0.0"
|
||||
```
|
||||
|
||||
### Verify the installation
|
||||
|
||||
To verify whether MMSegmentation is installed correctly, we provide some sample codes to run an inference demo.
|
||||
|
||||
**Step 1.** We need to download config and checkpoint files.
|
||||
|
||||
```shell
|
||||
mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest .
|
||||
```
|
||||
|
||||
The downloading will take several seconds or more, depending on your network environment. When it is done, you will find two files `pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py` and `pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth` in your current folder.
|
||||
|
||||
**Step 2.** Verify the inference demo.
|
||||
|
||||
Option (a). If you install mmsegmentation from source, just run the following command.
|
||||
|
||||
```shell
|
||||
python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg
|
||||
```
|
||||
|
||||
You will see a new image `result.jpg` on your current folder, where segmentation masks are covered on all objects.
|
||||
|
||||
Option (b). If you install mmsegmentation with pip, open you python interpreter and copy&paste the following codes.
|
||||
|
||||
```python
|
||||
from mmseg.apis import inference_model, init_model, show_result_pyplot
|
||||
import mmcv
|
||||
|
||||
config_file = 'pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
checkpoint_file = 'pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_model(config_file, checkpoint_file, device='cuda:0')
|
||||
|
||||
# test a single image and show the results
|
||||
img = 'demo/demo.png' # or img = mmcv.imread(img), which will only load it once
|
||||
result = inference_model(model, img)
|
||||
# visualize the results in a new window
|
||||
show_result_pyplot(model, img, result, show=True)
|
||||
# or save the visualization results to image files
|
||||
# you can change the opacity of the painted segmentation map in (0, 1].
|
||||
show_result_pyplot(model, img, result, show=True, out_file='result.jpg', opacity=0.5)
|
||||
# test a video and show the results
|
||||
video = mmcv.VideoReader('video.mp4')
|
||||
for frame in video:
|
||||
result = inference_model(model, frame)
|
||||
show_result_pyplot(model, frame, result, wait_time=1)
|
||||
```
|
||||
|
||||
You can modify the code above to test a single image or a video, both of these options can verify that the installation was successful.
|
||||
|
||||
### Customize Installation
|
||||
|
||||
#### CUDA versions
|
||||
|
||||
When installing PyTorch, you need to specify the version of CUDA. If you are not clear on which to choose, follow our recommendations:
|
||||
|
||||
- For Ampere-based NVIDIA GPUs, such as GeForce 30 series and NVIDIA A100, CUDA 11 is a must.
|
||||
- For older NVIDIA GPUs, CUDA 11 is backward compatible, but CUDA 10.2 offers better compatibility and is more lightweight.
|
||||
|
||||
Please make sure the GPU driver satisfies the minimum version requirements. See [this table](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions__table-cuda-toolkit-driver-versions) for more information.
|
||||
|
||||
**Note:**
|
||||
Installing CUDA runtime libraries is enough if you follow our best practices, because no CUDA code will be compiled locally. However if you hope to compile MMCV from source or develop other CUDA operators, you need to install the complete CUDA toolkit from NVIDIA's [website](https://developer.nvidia.com/cuda-downloads), and its version should match the CUDA version of PyTorch. i.e., the specified version of cudatoolkit in `conda install` command.
|
||||
|
||||
#### Install MMCV without MIM
|
||||
|
||||
MMCV contains C++ and CUDA extensions, thus depending on PyTorch in a complex way. MIM solves such dependencies automatically and makes the installation easier. However, it is not a must.
|
||||
|
||||
To install MMCV with pip instead of MIM, please follow [MMCV installation guides](https://mmcv.readthedocs.io/en/latest/get_started/installation.html). This requires manually specifying a find-url based on PyTorch version and its CUDA version.
|
||||
|
||||
For example, the following command install mmcv==2.0.0 built for PyTorch 1.10.x and CUDA 11.3.
|
||||
|
||||
```shell
|
||||
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html
|
||||
```
|
||||
|
||||
#### Install on CPU-only platforms
|
||||
|
||||
MMSegmentation can be built for CPU only environment. In CPU mode you can train (requires MMCV version >= 2.0.0), test or inference a model.
|
||||
|
||||
#### Install on Google Colab
|
||||
|
||||
[Google Colab](https://research.google.com/) usually has PyTorch installed,
|
||||
thus we only need to install MMCV and MMSegmentation with the following commands.
|
||||
|
||||
**Step 1.** Install [MMCV](https://github.com/open-mmlab/mmcv) using [MIM](https://github.com/open-mmlab/mim).
|
||||
|
||||
```shell
|
||||
!pip3 install openmim
|
||||
!mim install mmengine
|
||||
!mim install "mmcv>=2.0.0"
|
||||
```
|
||||
|
||||
**Step 2.** Install MMSegmentation from the source.
|
||||
|
||||
```shell
|
||||
!git clone https://github.com/open-mmlab/mmsegmentation.git
|
||||
%cd mmsegmentation
|
||||
!git checkout main
|
||||
!pip install -e .
|
||||
```
|
||||
|
||||
**Step 3.** Verification.
|
||||
|
||||
```python
|
||||
import mmseg
|
||||
print(mmseg.__version__)
|
||||
# Example output: 1.0.0
|
||||
```
|
||||
|
||||
**Note:**
|
||||
Within Jupyter, the exclamation mark `!` is used to call external executables and `%cd` is a [magic command](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-cd) to change the current working directory of Python.
|
||||
|
||||
### Using MMSegmentation with Docker
|
||||
|
||||
We provide a [Dockerfile](https://github.com/open-mmlab/mmsegmentation/blob/main/docker/Dockerfile) to build an image. Ensure that your [docker version](https://docs.docker.com/engine/install/) >=19.03.
|
||||
|
||||
```shell
|
||||
# build an image with PyTorch 1.11, CUDA 11.3
|
||||
# If you prefer other versions, just modified the Dockerfile
|
||||
docker build -t mmsegmentation docker/
|
||||
```
|
||||
|
||||
Run it with
|
||||
|
||||
```shell
|
||||
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmsegmentation/data mmsegmentation
|
||||
```
|
||||
|
||||
### Optional Dependencies
|
||||
|
||||
#### Install GDAL
|
||||
|
||||
[GDAL](https://gdal.org/) is a translator library for raster and vector geospatial data formats. Install GDAL to read complex formats and extremely large remote sensing images.
|
||||
|
||||
```shell
|
||||
conda install GDAL
|
||||
```
|
||||
|
||||
## Trouble shooting
|
||||
|
||||
If you have some issues during the installation, please first view the [FAQ](notes/faq.md) page.
|
||||
You may [open an issue](https://github.com/open-mmlab/mmsegmentation/issues/new/choose) on GitHub if no solution is found.
|
||||
63
Seg_All_In_One_MMSeg/docs/en/index.rst
Normal file
63
Seg_All_In_One_MMSeg/docs/en/index.rst
Normal file
@@ -0,0 +1,63 @@
|
||||
Welcome to MMSegmentation's documentation!
|
||||
===========================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Get Started
|
||||
|
||||
overview.md
|
||||
get_started.md
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: User Guides
|
||||
|
||||
user_guides/index.rst
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Advanced Guides
|
||||
|
||||
advanced_guides/index.rst
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Migration
|
||||
|
||||
migration/index.rst
|
||||
|
||||
.. toctree::
|
||||
:caption: API Reference
|
||||
|
||||
api.rst
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Model Zoo
|
||||
|
||||
model_zoo.md
|
||||
modelzoo_statistics.md
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Notes
|
||||
|
||||
notes/changelog.md
|
||||
notes/faq.md
|
||||
|
||||
.. toctree::
|
||||
:caption: Device Support
|
||||
|
||||
device/npu.md
|
||||
|
||||
.. toctree::
|
||||
:caption: Switch Language
|
||||
|
||||
switch_language.md
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`search`
|
||||
35
Seg_All_In_One_MMSeg/docs/en/make.bat
Normal file
35
Seg_All_In_One_MMSeg/docs/en/make.bat
Normal file
@@ -0,0 +1,35 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
||||
8
Seg_All_In_One_MMSeg/docs/en/migration/index.rst
Normal file
8
Seg_All_In_One_MMSeg/docs/en/migration/index.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
Migration
|
||||
***************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
interface.md
|
||||
package.md
|
||||
525
Seg_All_In_One_MMSeg/docs/en/migration/interface.md
Normal file
525
Seg_All_In_One_MMSeg/docs/en/migration/interface.md
Normal file
@@ -0,0 +1,525 @@
|
||||
# Migration from MMSegmentation 0.x
|
||||
|
||||
## Introduction
|
||||
|
||||
This guide describes the fundamental differences between MMSegmentation 0.x and MMSegmentation 1.x in terms of behaviors and the APIs, and how these all relate to your migration journey.
|
||||
|
||||
## New dependencies
|
||||
|
||||
MMSegmentation 1.x depends on some new packages, you can prepare a new clean environment and install again according to the [installation tutorial](../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 **2.0.0** version or above.
|
||||
|
||||
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 **1.0.0rc6** 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 **3.0.0** version or above.
|
||||
|
||||
## Train launch
|
||||
|
||||
The main improvement of OpenMMLab 2.0 is releasing MMEngine which provides universal and powerful runner for unified interfaces to launch training jobs.
|
||||
|
||||
Compared with MMSeg0.x, MMSeg1.x provides fewer command line arguments in `tools/train.py`
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Function</td>
|
||||
<td>Original</td>
|
||||
<td>New</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Loading pre-trained checkpoint</td>
|
||||
<td>--load_from=$CHECKPOINT</td>
|
||||
<td>--cfg-options load_from=$CHECKPOINT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resuming Train from specific checkpoint</td>
|
||||
<td>--resume-from=$CHECKPOINT</td>
|
||||
<td>--resume=$CHECKPOINT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Resuming Train from the latest checkpoint</td>
|
||||
<td>--auto-resume</td>
|
||||
<td>--resume='auto'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Whether not to evaluate the checkpoint during training</td>
|
||||
<td>--no-validate</td>
|
||||
<td>--cfg-options val_cfg=None val_dataloader=None val_evaluator=None</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Training device assignment</td>
|
||||
<td>--gpu-id=$DEVICE_ID</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Whether or not set different seeds for different ranks</td>
|
||||
<td>--diff-seed</td>
|
||||
<td>--cfg-options randomness.diff_rank_seed=True</td>
|
||||
</tr>
|
||||
<td>Whether to set deterministic options for CUDNN backend</td>
|
||||
<td>--deterministic</td>
|
||||
<td>--cfg-options randomness.deterministic=True</td>
|
||||
</table>
|
||||
|
||||
## Test launch
|
||||
|
||||
Similar to training launch, there are only common arguments in tools/test.py of MMSegmentation 1.x.
|
||||
Below is the difference in test scripts,
|
||||
please refer to [this documentation](../user_guides/4_train_test.md) for more details about test launch.
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Function</td>
|
||||
<td>0.x</td>
|
||||
<td>1.x</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Evaluation metrics</td>
|
||||
<td>--eval mIoU</td>
|
||||
<td>--cfg-options test_evaluator.type=IoUMetric</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Whether to use test time augmentation</td>
|
||||
<td>--aug-test</td>
|
||||
<td>--tta</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Whether save the output results without perform evaluation</td>
|
||||
<td>--format-only</td>
|
||||
<td>--cfg-options test_evaluator.format_only=True</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Configuration file
|
||||
|
||||
### Model settings
|
||||
|
||||
No changes in `model.backbone`, `model.neck`, `model.decode_head` and `model.losses` fields.
|
||||
|
||||
Add `model.data_preprocessor` field to configure the `DataPreProcessor`, including:
|
||||
|
||||
- `mean` (Sequence, optional): The pixel mean of R, G, B channels. Defaults to None.
|
||||
|
||||
- `std` (Sequence, optional): The pixel standard deviation of R, G, B channels. Defaults to None.
|
||||
|
||||
- `size` (Sequence, optional): Fixed padding size.
|
||||
|
||||
- `size_divisor` (int, optional): The divisor of padded size.
|
||||
|
||||
- `seg_pad_val` (float, optional): Padding value of segmentation map. Default: 255.
|
||||
|
||||
- `padding_mode` (str): Type of padding. Default: 'constant'.
|
||||
|
||||
- constant: pads with a constant value, this value is specified with pad_val.
|
||||
|
||||
- `bgr_to_rgb` (bool): whether to convert image from BGR to RGB.Defaults to False.
|
||||
|
||||
- `rgb_to_bgr` (bool): whether to convert image from RGB to BGR. Defaults to False.
|
||||
|
||||
**Note:**
|
||||
Please refer [models documentation](../advanced_guides/models.md) for more details.
|
||||
|
||||
### Dataset settings
|
||||
|
||||
Changes in **data**:
|
||||
|
||||
The original `data` field is split to `train_dataloader`, `val_dataloader` and `test_dataloader`. This allows us to configure them in fine-grained. For example, you can specify different sampler and batch size during training and test.
|
||||
The `samples_per_gpu` is renamed to `batch_size`.
|
||||
The `workers_per_gpu` is renamed to `num_workers`.
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</td>
|
||||
<td>
|
||||
|
||||
```python
|
||||
data = dict(
|
||||
samples_per_gpu=4,
|
||||
workers_per_gpu=4,
|
||||
train=dict(...),
|
||||
val=dict(...),
|
||||
test=dict(...),
|
||||
)
|
||||
```
|
||||
|
||||
</td>
|
||||
<tr>
|
||||
<td>New</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>
|
||||
|
||||
Changes in **pipeline**
|
||||
|
||||
- The original formatting transforms **`ToTensor`**、**`ImageToTensor`**、**`Collect`** are combined as [`PackSegInputs`](mmseg.datasets.transforms.PackSegInputs)
|
||||
- We don't recommend to do **`Normalize`** and **Pad** in the dataset pipeline. Please remove it from pipelines and set it in the `data_preprocessor` field.
|
||||
- The original **`Resize`** in MMSeg 1.x has been changed to **`RandomResize`** and the input arguments `img_scale` is renamed to `scale`, and the default value of `keep_ratio` is modified to False.
|
||||
- The original `test_pipeline` combines single-scale test and multi-scale test together, in MMSeg 1.x we separate it into `test_pipeline` and `tta_pipeline`.
|
||||
|
||||
**Note:**
|
||||
We move some work of data transforms to the data preprocessor, like normalization, see [the documentation](package.md) for more details.
|
||||
|
||||
train_pipeline
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</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>New</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>
|
||||
|
||||
test_pipeline
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</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>New</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>
|
||||
|
||||
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.
|
||||
- `'mIoU'` has been changed to `'IoUMetric'`.
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</td>
|
||||
<td>
|
||||
|
||||
```python
|
||||
evaluation = dict(interval=2000, metric='mIoU', pre_eval=True)
|
||||
```
|
||||
|
||||
</td>
|
||||
<tr>
|
||||
<td>New</td>
|
||||
<td>
|
||||
|
||||
```python
|
||||
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
|
||||
test_evaluator = val_evaluator
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Optimizer and Schedule settings
|
||||
|
||||
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.
|
||||
- `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`.
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</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>New</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>
|
||||
|
||||
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 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>
|
||||
<td>Original</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>New</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>
|
||||
|
||||
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.
|
||||
|
||||
<table class="docutils">
|
||||
<tr>
|
||||
<td>Original</td>
|
||||
<td>
|
||||
|
||||
```python
|
||||
runner = dict(type='IterBasedRunner', max_iters=20000)
|
||||
```
|
||||
|
||||
</td>
|
||||
<tr>
|
||||
<td>New</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>
|
||||
|
||||
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
|
||||
|
||||
Changes in **`checkpoint_config`** and **`log_config`**:
|
||||
|
||||
The `checkpoint_config` are moved to `default_hooks.checkpoint` and the `log_config` are moved to `default_hooks.logger`.
|
||||
And we move many hooks settings from the script code to the `default_hooks` field in the runtime configuration.
|
||||
|
||||
```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'))
|
||||
```
|
||||
|
||||
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>
|
||||
<td>Original</td>
|
||||
<td>
|
||||
|
||||
```python
|
||||
log_config = dict(
|
||||
interval=100,
|
||||
hooks=[
|
||||
dict(type='TextLoggerHook'),
|
||||
dict(type='TensorboardLoggerHook'),
|
||||
])
|
||||
```
|
||||
|
||||
</td>
|
||||
<tr>
|
||||
<td>New</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>
|
||||
|
||||
Changes in **`load_from`** and **`resume_from`**:
|
||||
|
||||
- The `resume_from` is removed. And we use `resume` and `load_from` to replace it.
|
||||
- If `resume=True` and `load_from` is **not None**, resume training from the checkpoint in `load_from`.
|
||||
- If `resume=True` and `load_from` is **None**, try to resume from the latest checkpoint in the work directory.
|
||||
- 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`.
|
||||
|
||||
```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'),
|
||||
)
|
||||
```
|
||||
|
||||
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 **`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.
|
||||
113
Seg_All_In_One_MMSeg/docs/en/migration/package.md
Normal file
113
Seg_All_In_One_MMSeg/docs/en/migration/package.md
Normal file
@@ -0,0 +1,113 @@
|
||||
# Package structures changes
|
||||
|
||||
This section is included if you are curious about what has changed between MMSeg 0.x and 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>
|
||||
|
||||
## Removed packages
|
||||
|
||||
### `mmseg.core`
|
||||
|
||||
In OpenMMLab 2.0, `core` package has been removed. `hooks` and `optimizers` of `core` are moved in `mmseg.engine`, and `evaluation` in `core` is mmseg.evaluation currently.
|
||||
|
||||
## `mmseg.ops`
|
||||
|
||||
`ops` package included `encoding` and `wrappers`, which are moved in `mmseg.models.utils`.
|
||||
|
||||
## Added packages
|
||||
|
||||
### `mmseg.engine`
|
||||
|
||||
OpenMMLab 2.0 adds a new foundational library for training deep learning, MMEngine. It servers as the training engine of all OpenMMLab codebases.
|
||||
`engine` package of mmseg is some customized modules for semantic segmentation task, like `SegVisualizationHook` which works for visualizing segmentation mask.
|
||||
|
||||
### `mmseg.structure`
|
||||
|
||||
In OpenMMLab 2.0, we designed data structure for computer vision task, and in mmseg, we implements `SegDataSample` in `structure` package.
|
||||
|
||||
### `mmseg.evaluation`
|
||||
|
||||
We move all evaluation metric in `mmseg.evaluation`.
|
||||
|
||||
### `mmseg.registry`
|
||||
|
||||
We moved registry implementations for all kinds of modules in MMSegmentation in `mmseg.registry`.
|
||||
|
||||
## Modified packages
|
||||
|
||||
### `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`.
|
||||
|
||||
Here is the changes of `mmseg.apis`:
|
||||
|
||||
| Function | Changes |
|
||||
| :-------------------: | :---------------------------------------------- |
|
||||
| `init_segmentor` | Renamed to `init_model` |
|
||||
| `inference_segmentor` | Rename to `inference_model` |
|
||||
| `show_result_pyplot` | Implemented based on `SegLocalVisualizer` |
|
||||
| `train_model` | Removed, use `runner.train` to train. |
|
||||
| `multi_gpu_test` | Removed, use `runner.test` to test. |
|
||||
| `single_gpu_test` | Removed, use `runner.test` to test. |
|
||||
| `set_random_seed` | Removed, use `mmengine.runner.set_random_seed`. |
|
||||
| `init_random_seed` | Removed, use `mmengine.dist.sync_random_seed`. |
|
||||
|
||||
### `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 |
|
||||
| :-------------------: | :------------------------------------------------------------------------------------------ |
|
||||
| `mmseg.pipelines` | Moved in `mmcv.transforms` |
|
||||
| `mmseg.sampler` | Moved in `mmengine.dataset.sampler` |
|
||||
| `CustomDataset` | Renamed to `BaseSegDataset` and inherited from `BaseDataset` in MMEngine |
|
||||
| `DefaultFormatBundle` | Replaced with `PackSegInputs` |
|
||||
| `LoadImageFromFile` | Moved in `mmcv.transforms.LoadImageFromFile` |
|
||||
| `LoadAnnotations` | Moved in `mmcv.transforms.LoadAnnotations` |
|
||||
| `Resize` | Moved in `mmcv.transforms` and split into `Resize`, `RandomResize` and `RandomChoiceResize` |
|
||||
| `RandomFlip` | Moved in `mmcv.transforms.RandomFlip` |
|
||||
| `Pad` | Moved in `mmcv.transforms.Pad` |
|
||||
| `Normalize` | Moved in `mmcv.transforms.Normalize` |
|
||||
| `Compose` | Moved in `mmcv.transforms.Compose` |
|
||||
| `ImageToTensor` | Moved in `mmcv.transforms.ImageToTensor` |
|
||||
|
||||
### `mmseg.models`
|
||||
|
||||
`models` has not changed a lot, just added the `encoding` and `wrappers` from previous `mmseg.ops`
|
||||
186
Seg_All_In_One_MMSeg/docs/en/model_zoo.md
Normal file
186
Seg_All_In_One_MMSeg/docs/en/model_zoo.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# Benchmark and Model Zoo
|
||||
|
||||
## Common settings
|
||||
|
||||
- We use distributed training with 4 GPUs by default.
|
||||
|
||||
- All pytorch-style pretrained backbones on ImageNet are train by ourselves, with the same procedure in the [paper](https://arxiv.org/pdf/1812.01187.pdf).
|
||||
Our ResNet style backbone are based on ResNetV1c variant, where the 7x7 conv in the input stem is replaced with three 3x3 convs.
|
||||
|
||||
- For the consistency across different hardwares, we report the GPU memory as the maximum value of `torch.cuda.max_memory_allocated()` for all 4 GPUs with `torch.backends.cudnn.benchmark=False`.
|
||||
Note that this value is usually less than what `nvidia-smi` shows.
|
||||
|
||||
- We report the inference time as the total time of network forwarding and post-processing, excluding the data loading time.
|
||||
Results are obtained with the script `tools/benchmark.py` which computes the average time on 200 images with `torch.backends.cudnn.benchmark=False`.
|
||||
|
||||
- There are two inference modes in this framework.
|
||||
|
||||
- `slide` mode: The `test_cfg` will be like `dict(mode='slide', crop_size=(769, 769), stride=(513, 513))`.
|
||||
|
||||
In this mode, multiple patches will be cropped from input image, passed into network individually.
|
||||
The crop size and stride between patches are specified by `crop_size` and `stride`.
|
||||
The overlapping area will be merged by average
|
||||
|
||||
- `whole` mode: The `test_cfg` will be like `dict(mode='whole')`.
|
||||
|
||||
In this mode, the whole imaged will be passed into network directly.
|
||||
|
||||
By default, we use `slide` inference for 769x769 trained model, `whole` inference for the rest.
|
||||
|
||||
- For input size of 8x+1 (e.g. 769), `align_corner=True` is adopted as a traditional practice.
|
||||
Otherwise, for input size of 8x (e.g. 512, 1024), `align_corner=False` is adopted.
|
||||
|
||||
## Baselines
|
||||
|
||||
### FCN
|
||||
|
||||
Please refer to [FCN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/fcn) for details.
|
||||
|
||||
### PSPNet
|
||||
|
||||
Please refer to [PSPNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/pspnet) for details.
|
||||
|
||||
### DeepLabV3
|
||||
|
||||
Please refer to [DeepLabV3](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/deeplabv3) for details.
|
||||
|
||||
### PSANet
|
||||
|
||||
Please refer to [PSANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/psanet) for details.
|
||||
|
||||
### DeepLabV3+
|
||||
|
||||
Please refer to [DeepLabV3+](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/deeplabv3plus) for details.
|
||||
|
||||
### UPerNet
|
||||
|
||||
Please refer to [UPerNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/upernet) for details.
|
||||
|
||||
### NonLocal Net
|
||||
|
||||
Please refer to [NonLocal Net](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/nonlocal_net) for details.
|
||||
|
||||
### EncNet
|
||||
|
||||
Please refer to [EncNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/encnet) for details.
|
||||
|
||||
### CCNet
|
||||
|
||||
Please refer to [CCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/ccnet) for details.
|
||||
|
||||
### DANet
|
||||
|
||||
Please refer to [DANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/danet) for details.
|
||||
|
||||
### APCNet
|
||||
|
||||
Please refer to [APCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/apcnet) for details.
|
||||
|
||||
### HRNet
|
||||
|
||||
Please refer to [HRNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/hrnet) for details.
|
||||
|
||||
### GCNet
|
||||
|
||||
Please refer to [GCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/gcnet) for details.
|
||||
|
||||
### DMNet
|
||||
|
||||
Please refer to [DMNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/dmnet) for details.
|
||||
|
||||
### ANN
|
||||
|
||||
Please refer to [ANN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/ann) for details.
|
||||
|
||||
### OCRNet
|
||||
|
||||
Please refer to [OCRNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/ocrnet) for details.
|
||||
|
||||
### Fast-SCNN
|
||||
|
||||
Please refer to [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/fastscnn) for details.
|
||||
|
||||
### ResNeSt
|
||||
|
||||
Please refer to [ResNeSt](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/resnest) for details.
|
||||
|
||||
### Semantic FPN
|
||||
|
||||
Please refer to [Semantic FPN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/sem_fpn) for details.
|
||||
|
||||
### PointRend
|
||||
|
||||
Please refer to [PointRend](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/point_rend) for details.
|
||||
|
||||
### MobileNetV2
|
||||
|
||||
Please refer to [MobileNetV2](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mobilenet_v2) for details.
|
||||
|
||||
### MobileNetV3
|
||||
|
||||
Please refer to [MobileNetV3](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mobilenet_v3) for details.
|
||||
|
||||
### EMANet
|
||||
|
||||
Please refer to [EMANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/emanet) for details.
|
||||
|
||||
### DNLNet
|
||||
|
||||
Please refer to [DNLNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/dnlnet) for details.
|
||||
|
||||
### CGNet
|
||||
|
||||
Please refer to [CGNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/cgnet) for details.
|
||||
|
||||
### Mixed Precision (FP16) Training
|
||||
|
||||
Please refer [Mixed Precision (FP16) Training on BiSeNetV2](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/bisenetv2/bisenetv2_fcn_4xb4-160k_cityscapes-1024x1024.py) for details.
|
||||
|
||||
### U-Net
|
||||
|
||||
Please refer to [U-Net](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/unet/README.md) for details.
|
||||
|
||||
### ViT
|
||||
|
||||
Please refer to [ViT](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/vit/README.md) for details.
|
||||
|
||||
### Swin
|
||||
|
||||
Please refer to [Swin](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/swin/README.md) for details.
|
||||
|
||||
### SETR
|
||||
|
||||
Please refer to [SETR](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/setr/README.md) for details.
|
||||
|
||||
## Speed benchmark
|
||||
|
||||
### Hardware
|
||||
|
||||
- 8 NVIDIA Tesla V100 (32G) GPUs
|
||||
- Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
|
||||
|
||||
### Software environment
|
||||
|
||||
- Python 3.7
|
||||
- PyTorch 1.5
|
||||
- CUDA 10.1
|
||||
- CUDNN 7.6.03
|
||||
- NCCL 2.4.08
|
||||
|
||||
### Training speed
|
||||
|
||||
For fair comparison, we benchmark all implementations with ResNet-101V1c.
|
||||
The input size is fixed to 1024x512 with batch size 2.
|
||||
|
||||
The training speed is reported as followed, in terms of second per iter (s/iter). The lower, the better.
|
||||
|
||||
| Implementation | PSPNet (s/iter) | DeepLabV3+ (s/iter) |
|
||||
| --------------------------------------------------------------------------- | --------------- | ------------------- |
|
||||
| [MMSegmentation](https://github.com/open-mmlab/mmsegmentation) | **0.83** | **0.85** |
|
||||
| [SegmenTron](https://github.com/LikeLy-Journey/SegmenTron) | 0.84 | 0.85 |
|
||||
| [CASILVision](https://github.com/CSAILVision/semantic-segmentation-pytorch) | 1.15 | N/A |
|
||||
| [vedaseg](https://github.com/Media-Smart/vedaseg) | 0.95 | 1.25 |
|
||||
|
||||
:::{note}
|
||||
The output stride of DeepLabV3+ is 8.
|
||||
:::
|
||||
102
Seg_All_In_One_MMSeg/docs/en/modelzoo_statistics.md
Normal file
102
Seg_All_In_One_MMSeg/docs/en/modelzoo_statistics.md
Normal file
@@ -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/main/configs/ann) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [APCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/apcnet) (12 ckpts)
|
||||
|
||||
- \[BACKBONE\] [BEiT](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/beit) (2 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV1](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/bisenetv1) (11 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [BiSeNetV2](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/bisenetv2) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/ccnet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [CGNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/cgnet) (2 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ConvNeXt](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/convnext) (6 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/danet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/deeplabv3) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DeepLabV3+](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/deeplabv3plus) (42 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DMNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/dmnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DNLNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/dnlnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [DPT](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/dpt) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EMANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/emanet) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [EncNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/encnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ERFNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/erfnet) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FastFCN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/fastfcn) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/fastscnn) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [FCN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/fcn) (41 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [GCNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/gcnet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [HRNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/hrnet) (37 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ICNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/icnet) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [ISANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/isanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [K-Net](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/knet) (7 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MAE](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mae) (1 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Mask2Former](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mask2former) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [MaskFormer](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/maskformer) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV2](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mobilenet_v2) (8 ckpts)
|
||||
|
||||
- \[BACKBONE\] [MobileNetV3](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/mobilenet_v3) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [NonLocal Net](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/nonlocal_net) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [OCRNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/ocrnet) (24 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PointRend](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/point_rend) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [PoolFormer](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/poolformer) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSANet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/psanet) (16 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [PSPNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/pspnet) (54 ckpts)
|
||||
|
||||
- \[BACKBONE\] [ResNeSt](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/resnest) (8 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SegFormer](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/segformer) (13 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Segmenter](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/segmenter) (5 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [Semantic FPN](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/sem_fpn) (4 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [SETR](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/setr) (7 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [STDC](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/stdc) (4 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Swin Transformer](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/swin) (6 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Twins](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/twins) (12 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/unet) (25 ckpts)
|
||||
|
||||
- \[ALGORITHM\] [UPerNet](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/upernet) (16 ckpts)
|
||||
|
||||
- \[BACKBONE\] [Vision Transformer](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/vit) (11 ckpts)
|
||||
506
Seg_All_In_One_MMSeg/docs/en/notes/changelog.md
Normal file
506
Seg_All_In_One_MMSeg/docs/en/notes/changelog.md
Normal file
@@ -0,0 +1,506 @@
|
||||
# Changelog of v1.x
|
||||
|
||||
## v1.2.2 (12/14/2023)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix bug in cross entropy loss ([#3457](https://github.com/open-mmlab/mmsegmentation/pull/3457))
|
||||
- Allow custom visualizer ([#3455](https://github.com/open-mmlab/mmsegmentation/pull/3455))
|
||||
- test resize with pad_shape ([#3421](https://github.com/open-mmlab/mmsegmentation/pull/3421))
|
||||
- add with-labels args to inferencer for visualization without labels ([#3466](https://github.com/open-mmlab/mmsegmentation/pull/3466))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @okotaku made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3421
|
||||
|
||||
## v1.2.1 (10/17/2023)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Add bpe_simple_vocab_16e6.txt.gz to release ([#3386](https://github.com/open-mmlab/mmsegmentation/pull/3386))
|
||||
- Fix init api ([#3388](https://github.com/open-mmlab/mmsegmentation/pull/3388))
|
||||
|
||||
## v1.2.0 (10/12/2023)
|
||||
|
||||
### Features
|
||||
|
||||
- Support Side Adapter Network ([#3232](https://github.com/open-mmlab/mmsegmentation/pull/3232))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- fix wrong variables passing for `set_dataset_meta` ([#3348](https://github.com/open-mmlab/mmsegmentation/pull/3348))
|
||||
|
||||
### Documentation
|
||||
|
||||
- add documentation of Finetune ONNX Models (MMSegemetation) Inference for NVIDIA Jetson ([#3372](https://github.com/open-mmlab/mmsegmentation/pull/3372))
|
||||
|
||||
## v1.1.2(09/20/2023)
|
||||
|
||||
### Features
|
||||
|
||||
- Add semantic label to the segmentation visualization results ([#3229](https://github.com/open-mmlab/mmsegmentation/pull/3229))
|
||||
- Support NYU depth estimation dataset ([#3269](https://github.com/open-mmlab/mmsegmentation/pull/3269))
|
||||
- Support Kullback-Leibler divergence Loss ([#3242](https://github.com/open-mmlab/mmsegmentation/pull/3242))
|
||||
- Support depth metrics ([#3297](https://github.com/open-mmlab/mmsegmentation/pull/3297))
|
||||
- Support Remote sensing inferencer ([#3131](https://github.com/open-mmlab/mmsegmentation/pull/3131))
|
||||
- Support VPD Depth Estimator ((#3321)(https://github.com/open-mmlab/mmsegmentation/pull/3321))
|
||||
- Support inference and visualization of VPD ([#3331](https://github.com/open-mmlab/mmsegmentation/pull/3331))
|
||||
- Support using the pytorch-grad-cam tool to visualize Class Activation Maps (CAM) ([#3324](https://github.com/open-mmlab/mmsegmentation/pull/3324))
|
||||
|
||||
### New projects
|
||||
|
||||
- Support PP-Mobileseg ([#3239](https://github.com/open-mmlab/mmsegmentation/pull/3239))
|
||||
- Support CAT-Seg (CVPR'2023) ([#3098](https://github.com/open-mmlab/mmsegmentation/pull/3098))
|
||||
- Support Adabins ([#3257](https://github.com/open-mmlab/mmsegmentation/pull/3257))
|
||||
- Add pp_mobileseg onnx inference script ([#3268](https://github.com/open-mmlab/mmsegmentation/pull/3268))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix module PascalContextDataset ([#3235](https://github.com/open-mmlab/mmsegmentation/pull/3235))
|
||||
- Fix one hot encoding for dice loss ([#3237](https://github.com/open-mmlab/mmsegmentation/pull/3237))
|
||||
- Fix confusion_matrix.py ([#3291](https://github.com/open-mmlab/mmsegmentation/pull/3291))
|
||||
- Fix inferencer visualization ([#3333](https://github.com/open-mmlab/mmsegmentation/pull/3333))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Translate doc for docs/zh_cn/user_guides/5_deployment.md ([#3281](https://github.com/open-mmlab/mmsegmentation/pull/3281))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @angiecao made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3235
|
||||
- @yeedrag made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3237
|
||||
- @Yang-Changhui made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3239
|
||||
- @ooooo-create made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3261
|
||||
- @Ben-Louis made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3269
|
||||
- @crazysteeaam made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3284
|
||||
- @zen0no made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3242
|
||||
- @XiandongWang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3291
|
||||
- @ZhaoQiiii made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3332
|
||||
- @zhen6618 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3324
|
||||
|
||||
## v1.1.1(07/24/2023)
|
||||
|
||||
### Features
|
||||
|
||||
- Add bdd100K datasets ([#3158](https://github.com/open-mmlab/mmsegmentation/pull/3158))
|
||||
- Remove batch inference assertion ([#3210](https://github.com/open-mmlab/mmsegmentation/pull/3210))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix train map path for coco-stuff164k.py ([#3187](https://github.com/open-mmlab/mmsegmentation/pull/3187))
|
||||
- Fix mim search error ([#3194](https://github.com/open-mmlab/mmsegmentation/pull/3194))
|
||||
- Fix SegTTAModel with no attribute '\_gt_sem_seg' error ([#3152](https://github.com/open-mmlab/mmsegmentation/pull/3152))
|
||||
- Fix Albumentations default key mapping mismatch ([#3195](https://github.com/open-mmlab/mmsegmentation/pull/3195))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @OliverGrace made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3187
|
||||
- @ZiAn-Su made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3152
|
||||
- @CastleDream made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3158
|
||||
- @coding-famer made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3174
|
||||
- @Alias-z made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3195
|
||||
|
||||
## v1.1.0(06/28/2023)
|
||||
|
||||
## What's Changed
|
||||
|
||||
### Features
|
||||
|
||||
- Support albu transform ([#2943](https://github.com/open-mmlab/mmsegmentation/pull/2943))
|
||||
- Support DDRNet ([#2855](https://github.com/open-mmlab/mmsegmentation/pull/2855))
|
||||
- Add GDAL backend and Support LEVIR-CD Dataset ([#2903](https://github.com/open-mmlab/mmsegmentation/pull/2903))
|
||||
- Support DSDL Dataset ([#2925](https://github.com/open-mmlab/mmsegmentation/pull/2925))
|
||||
- huasdorff distance loss ([#2820](https://github.com/open-mmlab/mmsegmentation/pull/2820))
|
||||
|
||||
### New Projects
|
||||
|
||||
- Support SAM inferencer ([#2897](https://github.com/open-mmlab/mmsegmentation/pull/2897))
|
||||
- Added a supported for Visual Attention Network (VAN) ([#2987](https://github.com/open-mmlab/mmsegmentation/pull/2987))
|
||||
- add GID dataset ([#3038](https://github.com/open-mmlab/mmsegmentation/pull/3038))
|
||||
- add Medical semantic seg dataset: Bactteria ([#2568](https://github.com/open-mmlab/mmsegmentation/pull/2568))
|
||||
- add Medical semantic seg dataset: Vampire ([#2633](https://github.com/open-mmlab/mmsegmentation/pull/2633))
|
||||
- add Medical semantic seg dataset: Ravir ([#2635](https://github.com/open-mmlab/mmsegmentation/pull/2635))
|
||||
- add Medical semantic seg dataset: Cranium ([#2675](https://github.com/open-mmlab/mmsegmentation/pull/2675))
|
||||
- add Medical semantic seg dataset: bccs ([#2861](https://github.com/open-mmlab/mmsegmentation/pull/2861))
|
||||
- add Medical semantic seg dataset: Gamma Task3 dataset ([#2695](https://github.com/open-mmlab/mmsegmentation/pull/2695))
|
||||
- add Medical semantic seg dataset: consep ([#2724](https://github.com/open-mmlab/mmsegmentation/pull/2724))
|
||||
- add Medical semantic seg dataset: breast_cancer_cell_seg dataset ([#2726](https://github.com/open-mmlab/mmsegmentation/pull/2726))
|
||||
- add Medical semantic seg dataset: chest_image_pneum dataset ([#2727](https://github.com/open-mmlab/mmsegmentation/pull/2727))
|
||||
- add Medical semantic seg dataset: conic2022 ([#2725](https://github.com/open-mmlab/mmsegmentation/pull/2725))
|
||||
- add Medical semantic seg dataset: dr_hagis ([#2729](https://github.com/open-mmlab/mmsegmentation/pull/2729))
|
||||
- add Medical semantic seg dataset: orvs ([#2728](https://github.com/open-mmlab/mmsegmentation/pull/2728))
|
||||
- add Medical semantic seg dataset: ISIC-2016 Task1 ([#2708](https://github.com/open-mmlab/mmsegmentation/pull/2708))
|
||||
- add Medical semantic seg dataset: ISIC-2017 Task1 ([#2709](https://github.com/open-mmlab/mmsegmentation/pull/2709))
|
||||
- add Medical semantic seg dataset: Kvasir seg ([#2677](https://github.com/open-mmlab/mmsegmentation/pull/2677))
|
||||
- add Medical semantic seg dataset: Kvasir seg aliyun ([#2678](https://github.com/open-mmlab/mmsegmentation/pull/2678))
|
||||
- add Medical semantic seg dataset: Rite ([#2680](https://github.com/open-mmlab/mmsegmentation/pull/2680))
|
||||
- add Medical semantic seg dataset: Fusc2021 ([#2682](https://github.com/open-mmlab/mmsegmentation/pull/2682))
|
||||
- add Medical semantic seg dataset: 2pm vessel ([#2685](https://github.com/open-mmlab/mmsegmentation/pull/2685))
|
||||
- add Medical semantic seg dataset: Pcam ([#2684](https://github.com/open-mmlab/mmsegmentation/pull/2684))
|
||||
- add Medical semantic seg dataset: Pannuke ([#2683](https://github.com/open-mmlab/mmsegmentation/pull/2683))
|
||||
- add Medical semantic seg dataset: Covid 19 ct cxr ([#2688](https://github.com/open-mmlab/mmsegmentation/pull/2688))
|
||||
- add Medical semantic seg dataset: Crass ([#2690](https://github.com/open-mmlab/mmsegmentation/pull/2690))
|
||||
- add Medical semantic seg dataset: Chest x ray images with pneumothorax masks ([#2687](https://github.com/open-mmlab/mmsegmentation/pull/2687))
|
||||
|
||||
### Enhancement
|
||||
|
||||
- Robust mapping from image path to seg map path ([#3091](https://github.com/open-mmlab/mmsegmentation/pull/3091))
|
||||
- Change assertion logic inference cfg.model.test_cfg ([#3012](https://github.com/open-mmlab/mmsegmentation/pull/3012))
|
||||
- Refactor dice loss ([#3002](https://github.com/open-mmlab/mmsegmentation/pull/3002))
|
||||
- Update Dockerfile libgl1-mesa-dev ([#3095](https://github.com/open-mmlab/mmsegmentation/pull/3095))
|
||||
- Prevent passed `ann_file` from silently failing to load ([#2966](https://github.com/open-mmlab/mmsegmentation/pull/2966))
|
||||
- Update the translation of models documentation ([#2833](https://github.com/open-mmlab/mmsegmentation/pull/2833))
|
||||
- Add docs contents at README.md ([#3083](https://github.com/open-mmlab/mmsegmentation/pull/3083))
|
||||
- Enhance swin pretrained model loading ([#3097](https://github.com/open-mmlab/mmsegmentation/pull/3097))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Handle case where device is neither CPU nor CUDA in HamHead ([#2868](https://github.com/open-mmlab/mmsegmentation/pull/2868))
|
||||
- Fix bugs when out_channels==1 ([#2911](https://github.com/open-mmlab/mmsegmentation/pull/2911))
|
||||
- Fix binary C=1 focal loss & dataset fileio ([#2935](https://github.com/open-mmlab/mmsegmentation/pull/2935))
|
||||
- Fix isaid dataset pre-processing tool ([#3010](https://github.com/open-mmlab/mmsegmentation/pull/3010))
|
||||
- Fix bug cannot use both '--tta' and '--out' while testing ([#3067](https://github.com/open-mmlab/mmsegmentation/pull/3067))
|
||||
- Fix inferencer ut ([#3117](https://github.com/open-mmlab/mmsegmentation/pull/3117))
|
||||
- Fix document ([#2863](https://github.com/open-mmlab/mmsegmentation/pull/2863), [#2896](https://github.com/open-mmlab/mmsegmentation/pull/2896), [#2919](https://github.com/open-mmlab/mmsegmentation/pull/2919), [#2951](https://github.com/open-mmlab/mmsegmentation/pull/2951), [#2970](https://github.com/open-mmlab/mmsegmentation/pull/2970), [#2961](https://github.com/open-mmlab/mmsegmentation/pull/2961), [#3042](https://github.com/open-mmlab/mmsegmentation/pull/3042), )
|
||||
- Fix squeeze error when N=1 and C=1 ([#2933](https://github.com/open-mmlab/mmsegmentation/pull/2933))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @liu-mengyang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2896
|
||||
- @likyoo made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2911
|
||||
- @1qh made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2902
|
||||
- @JoshuaChou2018 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2951
|
||||
- @jts250 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2833
|
||||
- @MGAMZ made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2970
|
||||
- @tianbinli made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2568
|
||||
- @Provable0816 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2633
|
||||
- @Zoulinx made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2903
|
||||
- @wufan-tb made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2925
|
||||
- @haruishi43 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2966
|
||||
- @Masaaki-75 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2675
|
||||
- @tang576225574 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2987
|
||||
- @Kedreamix made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3010
|
||||
- @nightrain01 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3067
|
||||
- @shigengtian made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3095
|
||||
- @SheffieldCao made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3097
|
||||
- @wangruohui made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3091
|
||||
- @LHamnett made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/3012
|
||||
|
||||
## v1.0.0(04/06/2023)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Add Mapillary Vistas Datasets support to MMSegmentation Core Package ([#2576](https://github.com/open-mmlab/mmsegmentation/pull/2576))
|
||||
- Support PIDNet ([#2609](https://github.com/open-mmlab/mmsegmentation/pull/2609))
|
||||
- Support SegNeXt ([#2654](https://github.com/open-mmlab/mmsegmentation/pull/2654))
|
||||
|
||||
### Features
|
||||
|
||||
- Support calculating FLOPs of segmentors ([#2706](https://github.com/open-mmlab/mmsegmentation/pull/2706))
|
||||
- Support multi-band image for Mosaic ([#2748](https://github.com/open-mmlab/mmsegmentation/pull/2748))
|
||||
- Support dump segment prediction ([#2712](https://github.com/open-mmlab/mmsegmentation/pull/2712))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Fix format_result and fix prefix param in cityscape metric, and rename CitysMetric to CityscapesMetric ([#2660](https://github.com/open-mmlab/mmsegmentation/pull/2660))
|
||||
- Support input gt seg map is not 2D ([#2739](https://github.com/open-mmlab/mmsegmentation/pull/2739))
|
||||
- Fix accepting an unexpected argument `local-rank` in PyTorch 2.0 ([#2812](https://github.com/open-mmlab/mmsegmentation/pull/2812))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add Chinese version of various documentation ([#2673](https://github.com/open-mmlab/mmsegmentation/pull/2673), [#2702](https://github.com/open-mmlab/mmsegmentation/pull/2702), [#2703](https://github.com/open-mmlab/mmsegmentation/pull/2703), [#2701](https://github.com/open-mmlab/mmsegmentation/pull/2701), [#2722](https://github.com/open-mmlab/mmsegmentation/pull/2722), [#2733](https://github.com/open-mmlab/mmsegmentation/pull/2733), [#2769](https://github.com/open-mmlab/mmsegmentation/pull/2769), [#2790](https://github.com/open-mmlab/mmsegmentation/pull/2790), [#2798](https://github.com/open-mmlab/mmsegmentation/pull/2798))
|
||||
- Update and refine various English documentation ([#2715](https://github.com/open-mmlab/mmsegmentation/pull/2715), [#2755](https://github.com/open-mmlab/mmsegmentation/pull/2755), [#2745](https://github.com/open-mmlab/mmsegmentation/pull/2745), [#2797](https://github.com/open-mmlab/mmsegmentation/pull/2797), [#2799](https://github.com/open-mmlab/mmsegmentation/pull/2799), [#2821](https://github.com/open-mmlab/mmsegmentation/pull/2821), [#2827](https://github.com/open-mmlab/mmsegmentation/pull/2827), [#2831](https://github.com/open-mmlab/mmsegmentation/pull/2831))
|
||||
- Add deeplabv3 model structure documentation ([#2426](https://github.com/open-mmlab/mmsegmentation/pull/2426))
|
||||
- Add custom metrics documentation ([#2799](https://github.com/open-mmlab/mmsegmentation/pull/2799))
|
||||
- Add faq in dev-1.x branch ([#2765](https://github.com/open-mmlab/mmsegmentation/pull/2765))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @liuruiqiang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2554
|
||||
- @wangjiangben-hw made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2569
|
||||
- @jinxianwei made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2557
|
||||
- @KKIEEK made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2747
|
||||
- @Renzhihan made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2765
|
||||
|
||||
## v1.0.0rc6(03/03/2023)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Support MMSegInferencer ([#2413](https://github.com/open-mmlab/mmsegmentation/pull/2413), [#2658](https://github.com/open-mmlab/mmsegmentation/pull/2658))
|
||||
- Support REFUGE dataset ([#2554](https://github.com/open-mmlab/mmsegmentation/pull/2554))
|
||||
|
||||
### Features
|
||||
|
||||
- Support auto import modules from registry ([#2481](https://github.com/open-mmlab/mmsegmentation/pull/2481))
|
||||
- Replace numpy ascontiguousarray with torch contiguous to speed-up ([#2604](https://github.com/open-mmlab/mmsegmentation/pull/2604))
|
||||
- Add browse_dataset.py tool ([#2649](https://github.com/open-mmlab/mmsegmentation/pull/2649))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Rename and Fix bug of projects HieraSeg ([#2565](https://github.com/open-mmlab/mmsegmentation/pull/2565))
|
||||
- Add out_channels in `CascadeEncoderDecoder` and update OCRNet and MobileNet v2 results ([#2656](https://github.com/open-mmlab/mmsegmentation/pull/2656))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add dataflow documentation of Chinese version ([#2652](https://github.com/open-mmlab/mmsegmentation/pull/2652))
|
||||
- Add custmized runtime documentation of English version ([#2533](https://github.com/open-mmlab/mmsegmentation/pull/2533))
|
||||
- Add documentation for visualizing feature map using wandb backend ([#2557](https://github.com/open-mmlab/mmsegmentation/pull/2557))
|
||||
- Add documentation for benchmark results on NPU (HUAWEI Ascend) ([#2569](https://github.com/open-mmlab/mmsegmentation/pull/2569), [#2596](https://github.com/open-mmlab/mmsegmentation/pull/2596), [#2610](https://github.com/open-mmlab/mmsegmentation/pull/2610))
|
||||
- Fix api name error in the migration doc ([#2601](https://github.com/open-mmlab/mmsegmentation/pull/2601))
|
||||
- Refine projects documentation ([#2586](https://github.com/open-mmlab/mmsegmentation/pull/2586))
|
||||
- Refine MMSegmentation documentation ([#2668](https://github.com/open-mmlab/mmsegmentation/pull/2668), [#2659](https://github.com/open-mmlab/mmsegmentation/pull/2659))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @zccjjj made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2548
|
||||
- @liuruiqiang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2554
|
||||
- @wangjiangben-hw made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2569
|
||||
- @jinxianwei made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2557
|
||||
|
||||
## v1.0.0rc5(02/01/2023)
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Fix MaskFormer and Mask2Former when install mmdet from source ([#2532](https://github.com/open-mmlab/mmsegmentation/pull/2532))
|
||||
- Support new fileio interface in `MMCV>=2.0.0rc4` ([#2543](https://github.com/open-mmlab/mmsegmentation/pull/2543))
|
||||
- Fix ERFNet URL in dev-1.x branch ([#2537](https://github.com/open-mmlab/mmsegmentation/pull/2537))
|
||||
- Fix misleading `List[Tensor]` types ([#2546](https://github.com/open-mmlab/mmsegmentation/pull/2546))
|
||||
- Rename typing.py to typing_utils.py ([#2548](https://github.com/open-mmlab/mmsegmentation/pull/2548))
|
||||
|
||||
## v1.0.0rc4(01/30/2023)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Support ISNet (ICCV'2021) in projects ([#2400](https://github.com/open-mmlab/mmsegmentation/pull/2400))
|
||||
- Support HSSN (CVPR'2022) in projects ([#2444](https://github.com/open-mmlab/mmsegmentation/pull/2444))
|
||||
|
||||
### Features
|
||||
|
||||
- Add Gaussian Noise and Blur for biomedical data ([#2373](https://github.com/open-mmlab/mmsegmentation/pull/2373))
|
||||
- Add BioMedicalRandomGamma ([#2406](https://github.com/open-mmlab/mmsegmentation/pull/2406))
|
||||
- Add BioMedical3DPad ([#2383](https://github.com/open-mmlab/mmsegmentation/pull/2383))
|
||||
- Add BioMedical3DRandomFlip ([#2404](https://github.com/open-mmlab/mmsegmentation/pull/2404))
|
||||
- Add `gt_edge_map` field to SegDataSample ([#2466](https://github.com/open-mmlab/mmsegmentation/pull/2466))
|
||||
- Support synapse dataset ([#2432](https://github.com/open-mmlab/mmsegmentation/pull/2432), [#2465](https://github.com/open-mmlab/mmsegmentation/pull/2465))
|
||||
- Support Mapillary Vistas Dataset in projects ([#2484](https://github.com/open-mmlab/mmsegmentation/pull/2484))
|
||||
- Switch order of `reduce_zero_label` and applying `label_map` ([#2517](https://github.com/open-mmlab/mmsegmentation/pull/2517))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add ZN Customized_runtime Doc ([#2502](https://github.com/open-mmlab/mmsegmentation/pull/2502))
|
||||
- Add EN datasets.md ([#2464](https://github.com/open-mmlab/mmsegmentation/pull/2464))
|
||||
- Fix minor typo in migration `package.md` ([#2518](https://github.com/open-mmlab/mmsegmentation/pull/2518))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Fix incorrect `img_shape` value assignment in RandomCrop ([#2469](https://github.com/open-mmlab/mmsegmentation/pull/2469))
|
||||
- Fix inference api and support setting palette to SegLocalVisualizer ([#2475](https://github.com/open-mmlab/mmsegmentation/pull/2475))
|
||||
- Unfinished label conversion from `-1` to `255` ([#2516](https://github.com/open-mmlab/mmsegmentation/pull/2516))
|
||||
|
||||
### New Contributors
|
||||
|
||||
- @blueyo0 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2373
|
||||
- @Fivethousand5k made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2406
|
||||
- @suyanzhou626 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2383
|
||||
- @unrealMJ made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2400
|
||||
- @Dominic23331 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2432
|
||||
- @AI-Tianlong made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2444
|
||||
- @morkovka1337 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2492
|
||||
- @Leeinsn made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2404
|
||||
- @siddancha made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/2516
|
||||
|
||||
## v1.0.0rc3(31/12/2022)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Support test time augmentation ([#2184](https://github.com/open-mmlab/mmsegmentation/pull/2184))
|
||||
- Add 'Projects/' folder and the first example project ([#2412](https://github.com/open-mmlab/mmsegmentation/pull/2412))
|
||||
|
||||
### Features
|
||||
|
||||
- Add Biomedical 3D array random crop transform ([#2378](https://github.com/open-mmlab/mmsegmentation/pull/2378))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add Chinese version of config tutorial ([#2371](https://github.com/open-mmlab/mmsegmentation/pull/2371))
|
||||
- Add Chinese version of train & test tutorial ([#2355](https://github.com/open-mmlab/mmsegmentation/pull/2355))
|
||||
- Add Chinese version of overview ([(#2397)](https://github.com/open-mmlab/mmsegmentation/pull/2397)))
|
||||
- Add Chinese version of get_started ([#2417](https://github.com/open-mmlab/mmsegmentation/pull/2417))
|
||||
- Add datasets in Chinese ([#2387](https://github.com/open-mmlab/mmsegmentation/pull/2387))
|
||||
- Add dataflow document ([#2403](https://github.com/open-mmlab/mmsegmentation/pull/2403))
|
||||
- Add pspnet model structure graph ([#2437](https://github.com/open-mmlab/mmsegmentation/pull/2437))
|
||||
- Update some content of engine Chinese documentation ([#2341](https://github.com/open-mmlab/mmsegmentation/pull/2341))
|
||||
- Update TTA to migration documentation ([#2335](https://github.com/open-mmlab/mmsegmentation/pull/2335))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Remove dependency mmdet when do not use MaskFormerHead and MMDET_Mask2FormerHead ([#2448](https://github.com/open-mmlab/mmsegmentation/pull/2448))
|
||||
|
||||
### Enhancement
|
||||
|
||||
- Add torch1.13 checking in CI ([#2402](https://github.com/open-mmlab/mmsegmentation/pull/2402))
|
||||
- Fix pytorch version for merge stage test ([#2449](https://github.com/open-mmlab/mmsegmentation/pull/2449))
|
||||
|
||||
## v1.0.0rc2(6/12/2022)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Support MaskFormer ([#2215](https://github.com/open-mmlab/mmsegmentation/pull/2215))
|
||||
- Support Mask2Former ([#2255](https://github.com/open-mmlab/mmsegmentation/pull/2255))
|
||||
|
||||
### Features
|
||||
|
||||
- Add ResizeShortestEdge transform ([#2339](https://github.com/open-mmlab/mmsegmentation/pull/2339))
|
||||
- Support padding in data pre-processor for model testing([#2290](https://github.com/open-mmlab/mmsegmentation/pull/2290))
|
||||
- Fix the problem of post-processing not removing padding ([#2367](https://github.com/open-mmlab/mmsegmentation/pull/2367))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Fix links in README ([#2024](https://github.com/open-mmlab/mmsegmentation/pull/2024))
|
||||
- Fix swin load state_dict ([#2304](https://github.com/open-mmlab/mmsegmentation/pull/2304))
|
||||
- Fix typo of BaseSegDataset docstring ([#2322](https://github.com/open-mmlab/mmsegmentation/pull/2322))
|
||||
- Fix the bug in the visualization step ([#2326](https://github.com/open-mmlab/mmsegmentation/pull/2326))
|
||||
- Fix ignore class id from -1 to 255 in BaseSegDataset ([#2332](https://github.com/open-mmlab/mmsegmentation/pull/2332))
|
||||
- Fix KNet IterativeDecodeHead bug ([#2334](https://github.com/open-mmlab/mmsegmentation/pull/2334))
|
||||
- Add input argument for datasets ([#2379](https://github.com/open-mmlab/mmsegmentation/pull/2379))
|
||||
- Fix typo in warning on binary classification ([#2382](https://github.com/open-mmlab/mmsegmentation/pull/2382))
|
||||
|
||||
### Enhancement
|
||||
|
||||
- Fix ci for 1.x ([#2011](https://github.com/open-mmlab/mmsegmentation/pull/2011), [#2019](https://github.com/open-mmlab/mmsegmentation/pull/2019))
|
||||
- Fix lint and pre-commit hook ([#2308](https://github.com/open-mmlab/mmsegmentation/pull/2308))
|
||||
- Add `data` string in .gitignore file in dev-1.x branch ([#2336](https://github.com/open-mmlab/mmsegmentation/pull/2336))
|
||||
- Make scipy as a default dependency in runtime ([#2362](https://github.com/open-mmlab/mmsegmentation/pull/2362))
|
||||
- Delete mmcls in runtime.txt ([#2368](https://github.com/open-mmlab/mmsegmentation/pull/2368))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Update configuration documentation ([#2048](https://github.com/open-mmlab/mmsegmentation/pull/2048))
|
||||
- Update inference documentation ([#2052](https://github.com/open-mmlab/mmsegmentation/pull/2052))
|
||||
- Update train test documentation ([#2061](https://github.com/open-mmlab/mmsegmentation/pull/2061))
|
||||
- Update get started documentatin ([#2148](https://github.com/open-mmlab/mmsegmentation/pull/2148))
|
||||
- Update transforms documentation ([#2088](https://github.com/open-mmlab/mmsegmentation/pull/2088))
|
||||
- Add MMEval projects like in README ([#2259](https://github.com/open-mmlab/mmsegmentation/pull/2259))
|
||||
- Translate the visualization.md ([#2298](https://github.com/open-mmlab/mmsegmentation/pull/2298))
|
||||
|
||||
## v1.0.0rc1 (2/11/2022)
|
||||
|
||||
### Highlights
|
||||
|
||||
- Support PoolFormer ([#2191](https://github.com/open-mmlab/mmsegmentation/pull/2191))
|
||||
- Add Decathlon dataset ([#2227](https://github.com/open-mmlab/mmsegmentation/pull/2227))
|
||||
|
||||
### Features
|
||||
|
||||
- Add BioMedical data loading ([#2176](https://github.com/open-mmlab/mmsegmentation/pull/2176))
|
||||
- Add LIP dataset ([#2251](https://github.com/open-mmlab/mmsegmentation/pull/2251))
|
||||
- Add `GenerateEdge` data transform ([#2210](https://github.com/open-mmlab/mmsegmentation/pull/2210))
|
||||
|
||||
### Bug fix
|
||||
|
||||
- Fix segmenter-vit-s_fcn config ([#2037](https://github.com/open-mmlab/mmsegmentation/pull/2037))
|
||||
- Fix binary segmentation ([#2101](https://github.com/open-mmlab/mmsegmentation/pull/2101))
|
||||
- Fix MMSegmentation colab demo ([#2089](https://github.com/open-mmlab/mmsegmentation/pull/2089))
|
||||
- Fix ResizeToMultiple transform ([#2185](https://github.com/open-mmlab/mmsegmentation/pull/2185))
|
||||
- Use SyncBN in mobilenet_v2 ([#2198](https://github.com/open-mmlab/mmsegmentation/pull/2198))
|
||||
- Fix typo in installation ([#2175](https://github.com/open-mmlab/mmsegmentation/pull/2175))
|
||||
- Fix typo in visualization.md ([#2116](https://github.com/open-mmlab/mmsegmentation/pull/2116))
|
||||
|
||||
### Enhancement
|
||||
|
||||
- Add mim extras_requires in setup.py ([#2012](https://github.com/open-mmlab/mmsegmentation/pull/2012))
|
||||
- Fix CI ([#2029](https://github.com/open-mmlab/mmsegmentation/pull/2029))
|
||||
- Remove ops module ([#2063](https://github.com/open-mmlab/mmsegmentation/pull/2063))
|
||||
- Add pyupgrade pre-commit hook ([#2078](https://github.com/open-mmlab/mmsegmentation/pull/2078))
|
||||
- Add `out_file` in `add_datasample` of `SegLocalVisualizer` to directly save image ([#2090](https://github.com/open-mmlab/mmsegmentation/pull/2090))
|
||||
- Upgrade pre commit hooks ([#2154](https://github.com/open-mmlab/mmsegmentation/pull/2154))
|
||||
- Ignore test timm in CI when torch\<1.7 ([#2158](https://github.com/open-mmlab/mmsegmentation/pull/2158))
|
||||
- Update requirements ([#2186](https://github.com/open-mmlab/mmsegmentation/pull/2186))
|
||||
- Fix Windows platform CI ([#2202](https://github.com/open-mmlab/mmsegmentation/pull/2202))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add `Overview` documentation ([#2042](https://github.com/open-mmlab/mmsegmentation/pull/2042))
|
||||
- Add `Evaluation` documentation ([#2077](https://github.com/open-mmlab/mmsegmentation/pull/2077))
|
||||
- Add `Migration` documentation ([#2066](https://github.com/open-mmlab/mmsegmentation/pull/2066))
|
||||
- Add `Structures` documentation ([#2070](https://github.com/open-mmlab/mmsegmentation/pull/2070))
|
||||
- Add `Structures` ZN documentation ([#2129](https://github.com/open-mmlab/mmsegmentation/pull/2129))
|
||||
- Add `Engine` ZN documentation ([#2157](https://github.com/open-mmlab/mmsegmentation/pull/2157))
|
||||
- Update `Prepare datasets` and `Visualization` doc ([#2054](https://github.com/open-mmlab/mmsegmentation/pull/2054))
|
||||
- Update `Models` documentation ([#2160](https://github.com/open-mmlab/mmsegmentation/pull/2160))
|
||||
- Update `Add New Modules` documentation ([#2067](https://github.com/open-mmlab/mmsegmentation/pull/2067))
|
||||
- Fix the installation commands in get_started.md ([#2174](https://github.com/open-mmlab/mmsegmentation/pull/2174))
|
||||
- Add MMYOLO to README.md ([#2220](https://github.com/open-mmlab/mmsegmentation/pull/2220))
|
||||
|
||||
## v1.0.0rc0 (31/8/2022)
|
||||
|
||||
We are excited to announce the release of MMSegmentation 1.0.0rc0.
|
||||
MMSeg 1.0.0rc0 is the first version of MMSegmentation 1.x, a part of the OpenMMLab 2.0 projects.
|
||||
Built upon the new [training engine](https://github.com/open-mmlab/mmengine),
|
||||
MMSeg 1.x unifies the interfaces of dataset, models, evaluation, and visualization with faster training and testing speed.
|
||||
|
||||
### Highlights
|
||||
|
||||
1. **New engines** MMSeg 1.x is based on [MMEngine](https://github.com/open-mmlab/mmengine), which provides a general and powerful runner that allows more flexible customizations and significantly simplifies the entrypoints of high-level interfaces.
|
||||
|
||||
2. **Unified interfaces** As a part of the OpenMMLab 2.0 projects, MMSeg 1.x unifies and refactors the interfaces and internal logics of train, testing, datasets, models, evaluation, and visualization. All the OpenMMLab 2.0 projects share the same design in those interfaces and logics to allow the emergence of multi-task/modality algorithms.
|
||||
|
||||
3. **Faster speed** We optimize the training and inference speed for common models.
|
||||
|
||||
4. **New features**:
|
||||
|
||||
- Support TverskyLoss function
|
||||
|
||||
5. **More documentation and tutorials**. We add a bunch of documentation and tutorials to help users get started more smoothly. Read it [here](https://mmsegmentation.readthedocs.io/en/1.x/).
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
We briefly list the major breaking changes here.
|
||||
We will update the [migration guide](../migration.md) to provide complete details and migration instructions.
|
||||
|
||||
#### Training and testing
|
||||
|
||||
- MMSeg 1.x runs on PyTorch>=1.6. We have deprecated the support of PyTorch 1.5 to embrace the mixed precision training and other new features since PyTorch 1.6. Some models can still run on PyTorch 1.5, but the full functionality of MMSeg 1.x is not guaranteed.
|
||||
|
||||
- MMSeg 1.x uses Runner in [MMEngine](https://github.com/open-mmlab/mmengine) rather than that in MMCV. The new Runner implements and unifies the building logic of dataset, model, evaluation, and visualizer. Therefore, MMSeg 1.x no longer maintains the building logics of those modules in `mmseg.train.apis` and `tools/train.py`. Those code have been migrated into [MMEngine](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py). Please refer to the [migration guide of Runner in MMEngine](https://mmengine.readthedocs.io/en/latest/migration/runner.html) for more details.
|
||||
|
||||
- The Runner in MMEngine also supports testing and validation. The testing scripts are also simplified, which has similar logic as that in training scripts to build the runner.
|
||||
|
||||
- The execution points of hooks in the new Runner have been enriched to allow more flexible customization. Please refer to the [migration guide of Hook in MMEngine](https://mmengine.readthedocs.io/en/latest/migration/hook.html) for more details.
|
||||
|
||||
- Learning rate and momentum scheduling has been migrated from `Hook` to `Parameter Scheduler` in MMEngine. Please refer to the [migration guide of Parameter Scheduler in MMEngine](https://mmengine.readthedocs.io/en/latest/migration/param_scheduler.html) for more details.
|
||||
|
||||
#### Configs
|
||||
|
||||
- The [Runner in MMEngine](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py) uses a different config structures to ease the understanding of the components in runner. Users can read the [config example of mmseg](../user_guides/config.md) or refer to the [migration guide in MMEngine](https://mmengine.readthedocs.io/en/latest/migration/runner.html) for migration details.
|
||||
- The file names of configs and models are also refactored to follow the new rules unified across OpenMMLab 2.0 projects. Please refer to the [user guides of config](../user_guides/1_config.md) for more details.
|
||||
|
||||
#### Components
|
||||
|
||||
- Dataset
|
||||
- Data Transforms
|
||||
- Model
|
||||
- Evaluation
|
||||
- Visualization
|
||||
|
||||
### Improvements
|
||||
|
||||
- Support mixed precision training of all the models. However, some models may got Nan results due to some numerical issues. We will update the documentation and list their results (accuracy of failure) of mixed precision training.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix several config file errors [#1994](https://github.com/open-mmlab/mmsegmentation/pull/1994)
|
||||
|
||||
### New Features
|
||||
|
||||
1. Support data structures and encapsulating `seg_logits` in data samples, which can be return from models to support more common evaluation metrics.
|
||||
|
||||
### Ongoing changes
|
||||
|
||||
1. Test-time augmentation: which is supported in MMSeg 0.x is not implemented in this version due to limited time slot. We will support it in the following releases with a new and simplified design.
|
||||
|
||||
2. Inference interfaces: a unified inference interfaces will be supported in the future to ease the use of released models.
|
||||
|
||||
3. Interfaces of useful tools that can be used in notebook: more useful tools that implemented in the `tools` directory will have their python interfaces so that they can be used through notebook and in downstream libraries.
|
||||
|
||||
4. Documentation: we will add more design docs, tutorials, and migration guidance so that the community can deep dive into our new design, participate the future development, and smoothly migrate downstream libraries to MMSeg 1.x.
|
||||
720
Seg_All_In_One_MMSeg/docs/en/notes/changelog_v0.x.md
Normal file
720
Seg_All_In_One_MMSeg/docs/en/notes/changelog_v0.x.md
Normal file
@@ -0,0 +1,720 @@
|
||||
## Changelog
|
||||
|
||||
### V0.24.1 (5/1/2022)
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix `LayerDecayOptimizerConstructor` for MAE training ([#1539](https://github.com/open-mmlab/mmsegmentation/pull/1539), [#1540](https://github.com/open-mmlab/mmsegmentation/pull/1540))
|
||||
|
||||
### V0.24.0 (4/29/2022)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support MAE: Masked Autoencoders Are Scalable Vision Learners
|
||||
- Support Resnet strikes back
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support MAE: Masked Autoencoders Are Scalable Vision Learners ([#1307](https://github.com/open-mmlab/mmsegmentation/pull/1307), [#1523](https://github.com/open-mmlab/mmsegmentation/pull/1523))
|
||||
- Support Resnet strikes back ([#1390](https://github.com/open-mmlab/mmsegmentation/pull/1390))
|
||||
- Support extra dataloader settings in configs ([#1435](https://github.com/open-mmlab/mmsegmentation/pull/1435))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix input previous results for the last cascade_decode_head ([#1450](https://github.com/open-mmlab/mmsegmentation/pull/1450))
|
||||
- Fix validation loss logging ([#1494](https://github.com/open-mmlab/mmsegmentation/pull/1494))
|
||||
- Fix the bug in binary_cross_entropy ([1527](https://github.com/open-mmlab/mmsegmentation/pull/1527))
|
||||
- Support single channel prediction for Binary Cross Entropy Loss ([#1454](https://github.com/open-mmlab/mmsegmentation/pull/1454))
|
||||
- Fix potential bugs in accuracy.py ([1496](https://github.com/open-mmlab/mmsegmentation/pull/1496))
|
||||
- Avoid converting label ids twice by label map during evaluation ([1417](https://github.com/open-mmlab/mmsegmentation/pull/1417))
|
||||
- Fix bug about label_map ([1445](https://github.com/open-mmlab/mmsegmentation/pull/1445))
|
||||
- Fix image save path bug in Windows ([1423](https://github.com/open-mmlab/mmsegmentation/pull/1423))
|
||||
- Fix MMSegmentation Colab demo ([1501](https://github.com/open-mmlab/mmsegmentation/pull/1501), [1452](https://github.com/open-mmlab/mmsegmentation/pull/1452))
|
||||
- Migrate azure blob for beit checkpoints ([1503](https://github.com/open-mmlab/mmsegmentation/pull/1503))
|
||||
- Fix bug in `tools/analyse_logs.py` caused by wrong plot_iter in some cases ([1428](https://github.com/open-mmlab/mmsegmentation/pull/1428))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Merge BEiT and ConvNext's LR decay optimizer constructors ([#1438](https://github.com/open-mmlab/mmsegmentation/pull/1438))
|
||||
- Register optimizer constructor with mmseg ([#1456](https://github.com/open-mmlab/mmsegmentation/pull/1456))
|
||||
- Refactor transformer encode layer in ViT and BEiT backbone ([#1481](https://github.com/open-mmlab/mmsegmentation/pull/1481))
|
||||
- Add `build_pos_embed` and `build_layers` for BEiT ([1517](https://github.com/open-mmlab/mmsegmentation/pull/1517))
|
||||
- Add `with_cp` to mit and vit ([1431](https://github.com/open-mmlab/mmsegmentation/pull/1431))
|
||||
- Fix inconsistent dtype of `seg_label` in stdc decode ([1463](https://github.com/open-mmlab/mmsegmentation/pull/1463))
|
||||
- Delete random seed for training in `dist_train.sh` ([1519](https://github.com/open-mmlab/mmsegmentation/pull/1519))
|
||||
- Revise high `workers_per_gpus` in config file ([#1506](https://github.com/open-mmlab/mmsegmentation/pull/1506))
|
||||
- Add GPG keys and del mmcv version in Dockerfile ([1534](https://github.com/open-mmlab/mmsegmentation/pull/1534))
|
||||
- Update checkpoint for model in deeplabv3plus ([#1487](https://github.com/open-mmlab/mmsegmentation/pull/1487))
|
||||
- Add `DistSamplerSeedHook` to set epoch number to dataloader when runner is `EpochBasedRunner` ([1449](https://github.com/open-mmlab/mmsegmentation/pull/1449))
|
||||
- Provide URLs of Swin Transformer pretrained models ([1389](https://github.com/open-mmlab/mmsegmentation/pull/1389))
|
||||
- Updating Dockerfiles From Docker Directory and `get_started.md` to reach latest stable version of Python, PyTorch and MMCV ([1446](https://github.com/open-mmlab/mmsegmentation/pull/1446))
|
||||
|
||||
**Documentation**
|
||||
|
||||
- Add more clearly statement of CPU training/inference ([1518](https://github.com/open-mmlab/mmsegmentation/pull/1518))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @jiangyitong made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1431
|
||||
- @kahkeng made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1447
|
||||
- @Nourollah made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1446
|
||||
- @androbaza made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1452
|
||||
- @Yzichen made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1445
|
||||
- @whu-pzhang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1423
|
||||
- @panfeng-hover made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1417
|
||||
- @Johnson-Wang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1496
|
||||
- @jere357 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1460
|
||||
- @mfernezir made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1494
|
||||
- @donglixp made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1503
|
||||
- @YuanLiuuuuuu made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1307
|
||||
- @Dawn-bin made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1527
|
||||
|
||||
### V0.23.0 (4/1/2022)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support BEiT: BERT Pre-Training of Image Transformers
|
||||
- Support K-Net: Towards Unified Image Segmentation
|
||||
- Add `avg_non_ignore` of CELoss to support average loss over non-ignored elements
|
||||
- Support dataset initialization with file client
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support BEiT: BERT Pre-Training of Image Transformers ([#1404](https://github.com/open-mmlab/mmsegmentation/pull/1404))
|
||||
- Support K-Net: Towards Unified Image Segmentation ([#1289](https://github.com/open-mmlab/mmsegmentation/pull/1289))
|
||||
- Support dataset initialization with file client ([#1402](https://github.com/open-mmlab/mmsegmentation/pull/1402))
|
||||
- Add class name function for STARE datasets ([#1376](https://github.com/open-mmlab/mmsegmentation/pull/1376))
|
||||
- Support different seeds on different ranks when distributed training ([#1362](https://github.com/open-mmlab/mmsegmentation/pull/1362))
|
||||
- Add `nlc2nchw2nlc` and `nchw2nlc2nchw` to simplify tensor with different dimension operation ([#1249](https://github.com/open-mmlab/mmsegmentation/pull/1249))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Synchronize random seed for distributed sampler ([#1411](https://github.com/open-mmlab/mmsegmentation/pull/1411))
|
||||
- Add script and documentation for multi-machine distributed training ([#1383](https://github.com/open-mmlab/mmsegmentation/pull/1383))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Add `avg_non_ignore` of CELoss to support average loss over non-ignored elements ([#1409](https://github.com/open-mmlab/mmsegmentation/pull/1409))
|
||||
- Fix some wrong URLs of models or logs in `./configs` ([#1336](https://github.com/open-mmlab/mmsegmentation/pull/1433))
|
||||
- Add title and color theme arguments to plot function in `tools/confusion_matrix.py` ([#1401](https://github.com/open-mmlab/mmsegmentation/pull/1401))
|
||||
- Fix outdated link in Colab demo ([#1392](https://github.com/open-mmlab/mmsegmentation/pull/1392))
|
||||
- Fix typos ([#1424](https://github.com/open-mmlab/mmsegmentation/pull/1424), [#1405](https://github.com/open-mmlab/mmsegmentation/pull/1405), [#1371](https://github.com/open-mmlab/mmsegmentation/pull/1371), [#1366](https://github.com/open-mmlab/mmsegmentation/pull/1366), [#1363](https://github.com/open-mmlab/mmsegmentation/pull/1363))
|
||||
|
||||
**Documentation**
|
||||
|
||||
- Add FAQ document ([#1420](https://github.com/open-mmlab/mmsegmentation/pull/1420))
|
||||
- Fix the config name style description in official docs([#1414](https://github.com/open-mmlab/mmsegmentation/pull/1414))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @kinglintianxia made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1371
|
||||
- @CCODING04 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1376
|
||||
- @mob5566 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1401
|
||||
- @xiongnemo made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1392
|
||||
- @Xiangxu-0103 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1405
|
||||
|
||||
### V0.22.1 (3/9/2022)
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix the ZeroDivisionError that all pixels in one image is ignored. ([#1336](https://github.com/open-mmlab/mmsegmentation/pull/1336))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Provide URLs of STDC, Segmenter and Twins pretrained models ([#1272](https://github.com/open-mmlab/mmsegmentation/pull/1357))
|
||||
|
||||
### V0.22 (3/04/2022)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support ConvNeXt: A ConvNet for the 2020s. Please use the latest MMClassification (0.21.0) to try it out.
|
||||
- Support iSAID aerial Dataset.
|
||||
- Officially Support inference on Windows OS.
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support ConvNeXt: A ConvNet for the 2020s. ([#1216](https://github.com/open-mmlab/mmsegmentation/pull/1216))
|
||||
- Support iSAID aerial Dataset. ([#1115](https://github.com/open-mmlab/mmsegmentation/pull/1115)
|
||||
- Generating and plotting confusion matrix. ([#1301](https://github.com/open-mmlab/mmsegmentation/pull/1301))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Refactor 4 decoder heads (ASPP, FCN, PSP, UPer): Split forward function into `_forward_feature` and `cls_seg`. ([#1299](https://github.com/open-mmlab/mmsegmentation/pull/1299))
|
||||
- Add `min_size` arg in `Resize` to keep the shape after resize bigger than slide window. ([#1318](https://github.com/open-mmlab/mmsegmentation/pull/1318))
|
||||
- Revise pre-commit-hooks. ([#1315](https://github.com/open-mmlab/mmsegmentation/pull/1315))
|
||||
- Add win-ci. ([#1296](https://github.com/open-mmlab/mmsegmentation/pull/1296))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix `mlp_ratio` type in Swin Transformer. ([#1274](https://github.com/open-mmlab/mmsegmentation/pull/1274))
|
||||
- Fix path errors in `./demo` . ([#1269](https://github.com/open-mmlab/mmsegmentation/pull/1269))
|
||||
- Fix bug in conversion of potsdam. ([#1279](https://github.com/open-mmlab/mmsegmentation/pull/1279))
|
||||
- Make accuracy take into account `ignore_index`. ([#1259](https://github.com/open-mmlab/mmsegmentation/pull/1259))
|
||||
- Add Pytorch HardSwish assertion in unit test. ([#1294](https://github.com/open-mmlab/mmsegmentation/pull/1294))
|
||||
- Fix wrong palette value in vaihingen. ([#1292](https://github.com/open-mmlab/mmsegmentation/pull/1292))
|
||||
- Fix the bug that SETR cannot load pretrain. ([#1293](https://github.com/open-mmlab/mmsegmentation/pull/1293))
|
||||
- Update correct `In Collection` in metafile of each configs. ([#1239](https://github.com/open-mmlab/mmsegmentation/pull/1239))
|
||||
- Upload completed STDC models. ([#1332](https://github.com/open-mmlab/mmsegmentation/pull/1332))
|
||||
- Fix `DNLHead` exports onnx inference difference type Cast error. ([#1161](https://github.com/open-mmlab/mmsegmentation/pull/1332))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @JiaYanhao made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1269
|
||||
- @andife made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1281
|
||||
- @SBCV made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1279
|
||||
- @HJoonKwon made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1259
|
||||
- @Tsingularity made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1290
|
||||
- @Waterman0524 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1115
|
||||
- @MeowZheng made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1315
|
||||
- @linfangjian01 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1318
|
||||
|
||||
### V0.21.1 (2/9/2022)
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix typos in docs. ([#1263](https://github.com/open-mmlab/mmsegmentation/pull/1263))
|
||||
- Fix repeating log by `setup_multi_processes`. ([#1267](https://github.com/open-mmlab/mmsegmentation/pull/1267))
|
||||
- Upgrade isort in pre-commit hook. ([#1270](https://github.com/open-mmlab/mmsegmentation/pull/1270))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Use MMCV load_state_dict func in ViT/Swin. ([#1272](https://github.com/open-mmlab/mmsegmentation/pull/1272))
|
||||
- Add exception for PointRend for support CPU-only. ([#1271](https://github.com/open-mmlab/mmsegmentation/pull/1270))
|
||||
|
||||
### V0.21 (1/29/2022)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Officially Support CPUs training and inference, please use the latest MMCV (1.4.4) to try it out.
|
||||
- Support Segmenter: Transformer for Semantic Segmentation (ICCV'2021).
|
||||
- Support ISPRS Potsdam and Vaihingen Dataset.
|
||||
- Add Mosaic transform and `MultiImageMixDataset` class in `dataset_wrappers`.
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support Segmenter: Transformer for Semantic Segmentation (ICCV'2021) ([#955](https://github.com/open-mmlab/mmsegmentation/pull/955))
|
||||
- Support ISPRS Potsdam and Vaihingen Dataset ([#1097](https://github.com/open-mmlab/mmsegmentation/pull/1097), [#1171](https://github.com/open-mmlab/mmsegmentation/pull/1171))
|
||||
- Add segformer‘s benchmark on cityscapes ([#1155](https://github.com/open-mmlab/mmsegmentation/pull/1155))
|
||||
- Add auto resume ([#1172](https://github.com/open-mmlab/mmsegmentation/pull/1172))
|
||||
- Add Mosaic transform and `MultiImageMixDataset` class in `dataset_wrappers` ([#1093](https://github.com/open-mmlab/mmsegmentation/pull/1093), [#1105](https://github.com/open-mmlab/mmsegmentation/pull/1105))
|
||||
- Add log collector ([#1175](https://github.com/open-mmlab/mmsegmentation/pull/1175))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- New-style CPU training and inference ([#1251](https://github.com/open-mmlab/mmsegmentation/pull/1251))
|
||||
- Add UNet benchmark with multiple losses supervision ([#1143](https://github.com/open-mmlab/mmsegmentation/pull/1143))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix the model statistics in doc for readthedoc ([#1153](https://github.com/open-mmlab/mmsegmentation/pull/1153))
|
||||
- Set random seed for `palette` if not given ([#1152](https://github.com/open-mmlab/mmsegmentation/pull/1152))
|
||||
- Add `COCOStuffDataset` in `class_names.py` ([#1222](https://github.com/open-mmlab/mmsegmentation/pull/1222))
|
||||
- Fix bug in non-distributed multi-gpu training/testing ([#1247](https://github.com/open-mmlab/mmsegmentation/pull/1247))
|
||||
- Delete unnecessary lines of STDCHead ([#1231](https://github.com/open-mmlab/mmsegmentation/pull/1231))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @jbwang1997 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1152
|
||||
- @BeaverCC made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1206
|
||||
- @Echo-minn made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1214
|
||||
- @rstrudel made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/955
|
||||
|
||||
### V0.20.2 (12/15/2021)
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Revise --option to --options to avoid BC-breaking. ([#1140](https://github.com/open-mmlab/mmsegmentation/pull/1140))
|
||||
|
||||
### V0.20.1 (12/14/2021)
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Change options to cfg-options ([#1129](https://github.com/open-mmlab/mmsegmentation/pull/1129))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix `<!-- [ABSTRACT] -->` in metafile. ([#1127](https://github.com/open-mmlab/mmsegmentation/pull/1127))
|
||||
- Fix correct `num_classes` of HRNet in `LoveDA` dataset ([#1136](https://github.com/open-mmlab/mmsegmentation/pull/1136))
|
||||
|
||||
### V0.20 (12/10/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support Twins ([#989](https://github.com/open-mmlab/mmsegmentation/pull/989))
|
||||
- Support a real-time segmentation model STDC ([#995](https://github.com/open-mmlab/mmsegmentation/pull/995))
|
||||
- Support a widely-used segmentation model in lane detection ERFNet ([#960](https://github.com/open-mmlab/mmsegmentation/pull/960))
|
||||
- Support A Remote Sensing Land-Cover Dataset LoveDA ([#1028](https://github.com/open-mmlab/mmsegmentation/pull/1028))
|
||||
- Support focal loss ([#1024](https://github.com/open-mmlab/mmsegmentation/pull/1024))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support Twins ([#989](https://github.com/open-mmlab/mmsegmentation/pull/989))
|
||||
- Support a real-time segmentation model STDC ([#995](https://github.com/open-mmlab/mmsegmentation/pull/995))
|
||||
- Support a widely-used segmentation model in lane detection ERFNet ([#960](https://github.com/open-mmlab/mmsegmentation/pull/960))
|
||||
- Add SETR cityscapes benchmark ([#1087](https://github.com/open-mmlab/mmsegmentation/pull/1087))
|
||||
- Add BiSeNetV1 COCO-Stuff 164k benchmark ([#1019](https://github.com/open-mmlab/mmsegmentation/pull/1019))
|
||||
- Support focal loss ([#1024](https://github.com/open-mmlab/mmsegmentation/pull/1024))
|
||||
- Add Cutout transform ([#1022](https://github.com/open-mmlab/mmsegmentation/pull/1022))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Set a random seed when the user does not set a seed ([#1039](https://github.com/open-mmlab/mmsegmentation/pull/1039))
|
||||
- Add CircleCI setup ([#1086](https://github.com/open-mmlab/mmsegmentation/pull/1086))
|
||||
- Skip CI on ignoring given paths ([#1078](https://github.com/open-mmlab/mmsegmentation/pull/1078))
|
||||
- Add abstract and image for every paper ([#1060](https://github.com/open-mmlab/mmsegmentation/pull/1060))
|
||||
- Create a symbolic link on windows ([#1090](https://github.com/open-mmlab/mmsegmentation/pull/1090))
|
||||
- Support video demo using trained model ([#1014](https://github.com/open-mmlab/mmsegmentation/pull/1014))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix incorrectly loading init_cfg or pretrained models of several transformer models ([#999](https://github.com/open-mmlab/mmsegmentation/pull/999), [#1069](https://github.com/open-mmlab/mmsegmentation/pull/1069), [#1102](https://github.com/open-mmlab/mmsegmentation/pull/1102))
|
||||
- Fix EfficientMultiheadAttention in SegFormer ([#1037](https://github.com/open-mmlab/mmsegmentation/pull/1037))
|
||||
- Remove `fp16` folder in `configs` ([#1031](https://github.com/open-mmlab/mmsegmentation/pull/1031))
|
||||
- Fix several typos in .yml file (Dice Metric [#1041](https://github.com/open-mmlab/mmsegmentation/pull/1041), ADE20K dataset [#1120](https://github.com/open-mmlab/mmsegmentation/pull/1120), Training Memory (GB) [#1083](https://github.com/open-mmlab/mmsegmentation/pull/1083))
|
||||
- Fix test error when using `--show-dir` ([#1091](https://github.com/open-mmlab/mmsegmentation/pull/1091))
|
||||
- Fix dist training infinite waiting issue ([#1035](https://github.com/open-mmlab/mmsegmentation/pull/1035))
|
||||
- Change the upper version of mmcv to 1.5.0 ([#1096](https://github.com/open-mmlab/mmsegmentation/pull/1096))
|
||||
- Fix symlink failure on Windows ([#1038](https://github.com/open-mmlab/mmsegmentation/pull/1038))
|
||||
- Cancel previous runs that are not completed ([#1118](https://github.com/open-mmlab/mmsegmentation/pull/1118))
|
||||
- Unified links of readthedocs in docs ([#1119](https://github.com/open-mmlab/mmsegmentation/pull/1119))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @Junjue-Wang made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1028
|
||||
- @ddebby made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1066
|
||||
- @del-zhenwu made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1078
|
||||
- @KangBK0120 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1106
|
||||
- @zergzzlun made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1091
|
||||
- @fingertap made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1035
|
||||
- @irvingzhang0512 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1014
|
||||
- @littleSunlxy made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/989
|
||||
- @lkm2835
|
||||
- @RockeyCoss
|
||||
- @MengzhangLI
|
||||
- @Junjun2016
|
||||
- @xiexinch
|
||||
- @xvjiarui
|
||||
|
||||
### V0.19 (11/02/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support TIMMBackbone wrapper ([#998](https://github.com/open-mmlab/mmsegmentation/pull/998))
|
||||
- Support custom hook ([#428](https://github.com/open-mmlab/mmsegmentation/pull/428))
|
||||
- Add codespell pre-commit hook ([#920](https://github.com/open-mmlab/mmsegmentation/pull/920))
|
||||
- Add FastFCN benchmark on ADE20K ([#972](https://github.com/open-mmlab/mmsegmentation/pull/972))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support TIMMBackbone wrapper ([#998](https://github.com/open-mmlab/mmsegmentation/pull/998))
|
||||
- Support custom hook ([#428](https://github.com/open-mmlab/mmsegmentation/pull/428))
|
||||
- Add FastFCN benchmark on ADE20K ([#972](https://github.com/open-mmlab/mmsegmentation/pull/972))
|
||||
- Add codespell pre-commit hook and fix typos ([#920](https://github.com/open-mmlab/mmsegmentation/pull/920))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Make inputs & channels smaller in unittests ([#1004](https://github.com/open-mmlab/mmsegmentation/pull/1004))
|
||||
- Change `self.loss_decode` back to `dict` in Single Loss situation ([#1002](https://github.com/open-mmlab/mmsegmentation/pull/1002))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix typo in usage example ([#1003](https://github.com/open-mmlab/mmsegmentation/pull/1003))
|
||||
- Add contiguous after permutation in ViT ([#992](https://github.com/open-mmlab/mmsegmentation/pull/992))
|
||||
- Fix the invalid link ([#985](https://github.com/open-mmlab/mmsegmentation/pull/985))
|
||||
- Fix bug in CI with python 3.9 ([#994](https://github.com/open-mmlab/mmsegmentation/pull/994))
|
||||
- Fix bug when loading class name form file in custom dataset ([#923](https://github.com/open-mmlab/mmsegmentation/pull/923))
|
||||
|
||||
**Contributors**
|
||||
|
||||
- @ShoupingShan made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/923
|
||||
- @RockeyCoss made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/954
|
||||
- @HarborYuan made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/992
|
||||
- @lkm2835 made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/1003
|
||||
- @gszh made their first contribution in https://github.com/open-mmlab/mmsegmentation/pull/428
|
||||
- @VVsssssk
|
||||
- @MengzhangLI
|
||||
- @Junjun2016
|
||||
|
||||
### V0.18 (10/07/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support three real-time segmentation models (ICNet [#884](https://github.com/open-mmlab/mmsegmentation/pull/884), BiSeNetV1 [#851](https://github.com/open-mmlab/mmsegmentation/pull/851), and BiSeNetV2 [#804](https://github.com/open-mmlab/mmsegmentation/pull/804))
|
||||
- Support one efficient segmentation model (FastFCN [#885](https://github.com/open-mmlab/mmsegmentation/pull/885))
|
||||
- Support one efficient non-local/self-attention based segmentation model (ISANet [#70](https://github.com/open-mmlab/mmsegmentation/pull/70))
|
||||
- Support COCO-Stuff 10k and 164k datasets ([#625](https://github.com/open-mmlab/mmsegmentation/pull/625))
|
||||
- Support evaluate concated dataset separately ([#833](https://github.com/open-mmlab/mmsegmentation/pull/833))
|
||||
- Support loading GT for evaluation from multi-file backend ([#867](https://github.com/open-mmlab/mmsegmentation/pull/867))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support three real-time segmentation models (ICNet [#884](https://github.com/open-mmlab/mmsegmentation/pull/884), BiSeNetV1 [#851](https://github.com/open-mmlab/mmsegmentation/pull/851), and BiSeNetV2 [#804](https://github.com/open-mmlab/mmsegmentation/pull/804))
|
||||
- Support one efficient segmentation model (FastFCN [#885](https://github.com/open-mmlab/mmsegmentation/pull/885))
|
||||
- Support one efficient non-local/self-attention based segmentation model (ISANet [#70](https://github.com/open-mmlab/mmsegmentation/pull/70))
|
||||
- Support COCO-Stuff 10k and 164k datasets ([#625](https://github.com/open-mmlab/mmsegmentation/pull/625))
|
||||
- Support evaluate concated dataset separately ([#833](https://github.com/open-mmlab/mmsegmentation/pull/833))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Support loading GT for evaluation from multi-file backend ([#867](https://github.com/open-mmlab/mmsegmentation/pull/867))
|
||||
- Auto-convert SyncBN to BN when training on DP automatly([#772](https://github.com/open-mmlab/mmsegmentation/pull/772))
|
||||
- Refactor Swin-Transformer ([#800](https://github.com/open-mmlab/mmsegmentation/pull/800))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Update mmcv installation in dockerfile ([#860](https://github.com/open-mmlab/mmsegmentation/pull/860))
|
||||
- Fix number of iteration bug when resuming checkpoint in distributed train ([#866](https://github.com/open-mmlab/mmsegmentation/pull/866))
|
||||
- Fix parsing parse in val_step ([#906](https://github.com/open-mmlab/mmsegmentation/pull/906))
|
||||
|
||||
### V0.17 (09/01/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support SegFormer
|
||||
- Support DPT
|
||||
- Support Dark Zurich and Nighttime Driving datasets
|
||||
- Support progressive evaluation
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support SegFormer ([#599](https://github.com/open-mmlab/mmsegmentation/pull/599))
|
||||
- Support DPT ([#605](https://github.com/open-mmlab/mmsegmentation/pull/605))
|
||||
- Support Dark Zurich and Nighttime Driving datasets ([#815](https://github.com/open-mmlab/mmsegmentation/pull/815))
|
||||
- Support progressive evaluation ([#709](https://github.com/open-mmlab/mmsegmentation/pull/709))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Add multiscale_output interface and unittests for HRNet ([#830](https://github.com/open-mmlab/mmsegmentation/pull/830))
|
||||
- Support inherit cityscapes dataset ([#750](https://github.com/open-mmlab/mmsegmentation/pull/750))
|
||||
- Fix some typos in README.md ([#824](https://github.com/open-mmlab/mmsegmentation/pull/824))
|
||||
- Delete convert function and add instruction to ViT/Swin README.md ([#791](https://github.com/open-mmlab/mmsegmentation/pull/791))
|
||||
- Add vit/swin/mit convert weight scripts ([#783](https://github.com/open-mmlab/mmsegmentation/pull/783))
|
||||
- Add copyright files ([#796](https://github.com/open-mmlab/mmsegmentation/pull/796))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix invalid checkpoint link in inference_demo.ipynb ([#814](https://github.com/open-mmlab/mmsegmentation/pull/814))
|
||||
- Ensure that items in dataset have the same order across multi machine ([#780](https://github.com/open-mmlab/mmsegmentation/pull/780))
|
||||
- Fix the log error ([#766](https://github.com/open-mmlab/mmsegmentation/pull/766))
|
||||
|
||||
### V0.16 (08/04/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support PyTorch 1.9
|
||||
- Support SegFormer backbone MiT
|
||||
- Support md2yml pre-commit hook
|
||||
- Support frozen stage for HRNet
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support SegFormer backbone MiT ([#594](https://github.com/open-mmlab/mmsegmentation/pull/594))
|
||||
- Support md2yml pre-commit hook ([#732](https://github.com/open-mmlab/mmsegmentation/pull/732))
|
||||
- Support mim ([#717](https://github.com/open-mmlab/mmsegmentation/pull/717))
|
||||
- Add mmseg2torchserve tool ([#552](https://github.com/open-mmlab/mmsegmentation/pull/552))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Support hrnet frozen stage ([#743](https://github.com/open-mmlab/mmsegmentation/pull/743))
|
||||
- Add template of reimplementation questions ([#741](https://github.com/open-mmlab/mmsegmentation/pull/741))
|
||||
- Output pdf and epub formats for readthedocs ([#742](https://github.com/open-mmlab/mmsegmentation/pull/742))
|
||||
- Refine the docstring of ResNet ([#723](https://github.com/open-mmlab/mmsegmentation/pull/723))
|
||||
- Replace interpolate with resize ([#731](https://github.com/open-mmlab/mmsegmentation/pull/731))
|
||||
- Update resource limit ([#700](https://github.com/open-mmlab/mmsegmentation/pull/700))
|
||||
- Update config.md ([#678](https://github.com/open-mmlab/mmsegmentation/pull/678))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix ATTENTION registry ([#729](https://github.com/open-mmlab/mmsegmentation/pull/729))
|
||||
- Fix analyze log script ([#716](https://github.com/open-mmlab/mmsegmentation/pull/716))
|
||||
- Fix doc api display ([#725](https://github.com/open-mmlab/mmsegmentation/pull/725))
|
||||
- Fix patch_embed and pos_embed mismatch error ([#685](https://github.com/open-mmlab/mmsegmentation/pull/685))
|
||||
- Fix efficient test for multi-node ([#707](https://github.com/open-mmlab/mmsegmentation/pull/707))
|
||||
- Fix init_cfg in resnet backbone ([#697](https://github.com/open-mmlab/mmsegmentation/pull/697))
|
||||
- Fix efficient test bug ([#702](https://github.com/open-mmlab/mmsegmentation/pull/702))
|
||||
- Fix url error in config docs ([#680](https://github.com/open-mmlab/mmsegmentation/pull/680))
|
||||
- Fix mmcv installation ([#676](https://github.com/open-mmlab/mmsegmentation/pull/676))
|
||||
- Fix torch version ([#670](https://github.com/open-mmlab/mmsegmentation/pull/670))
|
||||
|
||||
**Contributors**
|
||||
|
||||
@sshuair @xiexinch @Junjun2016 @mmeendez8 @xvjiarui @sennnnn @puhsu @BIGWangYuDong @keke1u @daavoo
|
||||
|
||||
### V0.15 (07/04/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support ViT, SETR, and Swin-Transformer
|
||||
- Add Chinese documentation
|
||||
- Unified parameter initialization
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix typo and links ([#608](https://github.com/open-mmlab/mmsegmentation/pull/608))
|
||||
- Fix Dockerfile ([#607](https://github.com/open-mmlab/mmsegmentation/pull/607))
|
||||
- Fix ViT init ([#609](https://github.com/open-mmlab/mmsegmentation/pull/609))
|
||||
- Fix mmcv version compatible table ([#658](https://github.com/open-mmlab/mmsegmentation/pull/658))
|
||||
- Fix model links of DMNEt ([#660](https://github.com/open-mmlab/mmsegmentation/pull/660))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support loading DeiT weights ([#538](https://github.com/open-mmlab/mmsegmentation/pull/538))
|
||||
- Support SETR ([#531](https://github.com/open-mmlab/mmsegmentation/pull/531), [#635](https://github.com/open-mmlab/mmsegmentation/pull/635))
|
||||
- Add config and models for ViT backbone with UperHead ([#520](https://github.com/open-mmlab/mmsegmentation/pull/531), [#635](https://github.com/open-mmlab/mmsegmentation/pull/520))
|
||||
- Support Swin-Transformer ([#511](https://github.com/open-mmlab/mmsegmentation/pull/511))
|
||||
- Add higher accuracy FastSCNN ([#606](https://github.com/open-mmlab/mmsegmentation/pull/606))
|
||||
- Add Chinese documentation ([#666](https://github.com/open-mmlab/mmsegmentation/pull/666))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Unified parameter initialization ([#567](https://github.com/open-mmlab/mmsegmentation/pull/567))
|
||||
- Separate CUDA and CPU in github action CI ([#602](https://github.com/open-mmlab/mmsegmentation/pull/602))
|
||||
- Support persistent dataloader worker ([#646](https://github.com/open-mmlab/mmsegmentation/pull/646))
|
||||
- Update meta file fields ([#661](https://github.com/open-mmlab/mmsegmentation/pull/661), [#664](https://github.com/open-mmlab/mmsegmentation/pull/664))
|
||||
|
||||
### V0.14 (06/02/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support ONNX to TensorRT
|
||||
- Support MIM
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fix ONNX to TensorRT verify ([#547](https://github.com/open-mmlab/mmsegmentation/pull/547))
|
||||
- Fix save best for EvalHook ([#575](https://github.com/open-mmlab/mmsegmentation/pull/575))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support loading DeiT weights ([#538](https://github.com/open-mmlab/mmsegmentation/pull/538))
|
||||
- Support ONNX to TensorRT ([#542](https://github.com/open-mmlab/mmsegmentation/pull/542))
|
||||
- Support output results for ADE20k ([#544](https://github.com/open-mmlab/mmsegmentation/pull/544))
|
||||
- Support MIM ([#549](https://github.com/open-mmlab/mmsegmentation/pull/549))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Add option for ViT output shape ([#530](https://github.com/open-mmlab/mmsegmentation/pull/530))
|
||||
- Infer batch size using len(result) ([#532](https://github.com/open-mmlab/mmsegmentation/pull/532))
|
||||
- Add compatible table between MMSeg and MMCV ([#558](https://github.com/open-mmlab/mmsegmentation/pull/558))
|
||||
|
||||
### V0.13 (05/05/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support Pascal Context Class-59 dataset.
|
||||
- Support Visual Transformer Backbone.
|
||||
- Support mFscore metric.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed Colaboratory tutorial ([#451](https://github.com/open-mmlab/mmsegmentation/pull/451))
|
||||
- Fixed mIoU calculation range ([#471](https://github.com/open-mmlab/mmsegmentation/pull/471))
|
||||
- Fixed sem_fpn, unet README.md ([#492](https://github.com/open-mmlab/mmsegmentation/pull/492))
|
||||
- Fixed `num_classes` in FCN for Pascal Context 60-class dataset ([#488](https://github.com/open-mmlab/mmsegmentation/pull/488))
|
||||
- Fixed FP16 inference ([#497](https://github.com/open-mmlab/mmsegmentation/pull/497))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support dynamic export and visualize to pytorch2onnx ([#463](https://github.com/open-mmlab/mmsegmentation/pull/463))
|
||||
- Support export to torchscript ([#469](https://github.com/open-mmlab/mmsegmentation/pull/469), [#499](https://github.com/open-mmlab/mmsegmentation/pull/499))
|
||||
- Support Pascal Context Class-59 dataset ([#459](https://github.com/open-mmlab/mmsegmentation/pull/459))
|
||||
- Support Visual Transformer backbone ([#465](https://github.com/open-mmlab/mmsegmentation/pull/465))
|
||||
- Support UpSample Neck ([#512](https://github.com/open-mmlab/mmsegmentation/pull/512))
|
||||
- Support mFscore metric ([#509](https://github.com/open-mmlab/mmsegmentation/pull/509))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Add more CI for PyTorch ([#460](https://github.com/open-mmlab/mmsegmentation/pull/460))
|
||||
- Add print model graph args for tools/print_config.py ([#451](https://github.com/open-mmlab/mmsegmentation/pull/451))
|
||||
- Add cfg links in modelzoo README.md ([#468](https://github.com/open-mmlab/mmsegmentation/pull/469))
|
||||
- Add BaseSegmentor import to segmentors/__init__.py ([#495](https://github.com/open-mmlab/mmsegmentation/pull/495))
|
||||
- Add MMOCR, MMGeneration links ([#501](https://github.com/open-mmlab/mmsegmentation/pull/501), [#506](https://github.com/open-mmlab/mmsegmentation/pull/506))
|
||||
- Add Chinese QR code ([#506](https://github.com/open-mmlab/mmsegmentation/pull/506))
|
||||
- Use MMCV MODEL_REGISTRY ([#515](https://github.com/open-mmlab/mmsegmentation/pull/515))
|
||||
- Add ONNX testing tools ([#498](https://github.com/open-mmlab/mmsegmentation/pull/498))
|
||||
- Replace data_dict calling 'img' key to support MMDet3D ([#514](https://github.com/open-mmlab/mmsegmentation/pull/514))
|
||||
- Support reading class_weight from file in loss function ([#513](https://github.com/open-mmlab/mmsegmentation/pull/513))
|
||||
- Make tags as comment ([#505](https://github.com/open-mmlab/mmsegmentation/pull/505))
|
||||
- Use MMCV EvalHook ([#438](https://github.com/open-mmlab/mmsegmentation/pull/438))
|
||||
|
||||
### V0.12 (04/03/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support FCN-Dilate 6 model.
|
||||
- Support Dice Loss.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed PhotoMetricDistortion Doc ([#388](https://github.com/open-mmlab/mmsegmentation/pull/388))
|
||||
- Fixed install scripts ([#399](https://github.com/open-mmlab/mmsegmentation/pull/399))
|
||||
- Fixed Dice Loss multi-class ([#417](https://github.com/open-mmlab/mmsegmentation/pull/417))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support Dice Loss ([#396](https://github.com/open-mmlab/mmsegmentation/pull/396))
|
||||
- Add plot logs tool ([#426](https://github.com/open-mmlab/mmsegmentation/pull/426))
|
||||
- Add opacity option to show_result ([#425](https://github.com/open-mmlab/mmsegmentation/pull/425))
|
||||
- Speed up mIoU metric ([#430](https://github.com/open-mmlab/mmsegmentation/pull/430))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Refactor unittest file structure ([#440](https://github.com/open-mmlab/mmsegmentation/pull/440))
|
||||
- Fix typos in the repo ([#449](https://github.com/open-mmlab/mmsegmentation/pull/449))
|
||||
- Include class-level metrics in the log ([#445](https://github.com/open-mmlab/mmsegmentation/pull/445))
|
||||
|
||||
### V0.11 (02/02/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support memory efficient test, add more UNet models.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed TTA resize scale ([#334](https://github.com/open-mmlab/mmsegmentation/pull/334))
|
||||
- Fixed CI for pip 20.3 ([#307](https://github.com/open-mmlab/mmsegmentation/pull/307))
|
||||
- Fixed ADE20k test ([#359](https://github.com/open-mmlab/mmsegmentation/pull/359))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support memory efficient test ([#330](https://github.com/open-mmlab/mmsegmentation/pull/330))
|
||||
- Add more UNet benchmarks ([#324](https://github.com/open-mmlab/mmsegmentation/pull/324))
|
||||
- Support Lovasz Loss ([#351](https://github.com/open-mmlab/mmsegmentation/pull/351))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Move train_cfg/test_cfg inside model ([#341](https://github.com/open-mmlab/mmsegmentation/pull/341))
|
||||
|
||||
### V0.10 (01/01/2021)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support MobileNetV3, DMNet, APCNet. Add models of ResNet18V1b, ResNet18V1c, ResNet50V1b.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed CPU TTA ([#276](https://github.com/open-mmlab/mmsegmentation/pull/276))
|
||||
- Fixed CI for pip 20.3 ([#307](https://github.com/open-mmlab/mmsegmentation/pull/307))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Add ResNet18V1b, ResNet18V1c, ResNet50V1b, ResNet101V1b models ([#316](https://github.com/open-mmlab/mmsegmentation/pull/316))
|
||||
- Support MobileNetV3 ([#268](https://github.com/open-mmlab/mmsegmentation/pull/268))
|
||||
- Add 4 retinal vessel segmentation benchmark ([#315](https://github.com/open-mmlab/mmsegmentation/pull/315))
|
||||
- Support DMNet ([#313](https://github.com/open-mmlab/mmsegmentation/pull/313))
|
||||
- Support APCNet ([#299](https://github.com/open-mmlab/mmsegmentation/pull/299))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Refactor Documentation page ([#311](https://github.com/open-mmlab/mmsegmentation/pull/311))
|
||||
- Support resize data augmentation according to original image size ([#291](https://github.com/open-mmlab/mmsegmentation/pull/291))
|
||||
|
||||
### V0.9 (30/11/2020)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support 4 medical dataset, UNet and CGNet.
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support RandomRotate transform ([#215](https://github.com/open-mmlab/mmsegmentation/pull/215), [#260](https://github.com/open-mmlab/mmsegmentation/pull/260))
|
||||
- Support RGB2Gray transform ([#227](https://github.com/open-mmlab/mmsegmentation/pull/227))
|
||||
- Support Rerange transform ([#228](https://github.com/open-mmlab/mmsegmentation/pull/228))
|
||||
- Support ignore_index for BCE loss ([#210](https://github.com/open-mmlab/mmsegmentation/pull/210))
|
||||
- Add modelzoo statistics ([#263](https://github.com/open-mmlab/mmsegmentation/pull/263))
|
||||
- Support Dice evaluation metric ([#225](https://github.com/open-mmlab/mmsegmentation/pull/225))
|
||||
- Support Adjust Gamma transform ([#232](https://github.com/open-mmlab/mmsegmentation/pull/232))
|
||||
- Support CLAHE transform ([#229](https://github.com/open-mmlab/mmsegmentation/pull/229))
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed detail API link ([#267](https://github.com/open-mmlab/mmsegmentation/pull/267))
|
||||
|
||||
### V0.8 (03/11/2020)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support 4 medical dataset, UNet and CGNet.
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support customize runner ([#118](https://github.com/open-mmlab/mmsegmentation/pull/118))
|
||||
- Support UNet ([#161](https://github.com/open-mmlab/mmsegmentation/pull/162))
|
||||
- Support CHASE_DB1, DRIVE, STARE, HRD ([#203](https://github.com/open-mmlab/mmsegmentation/pull/203))
|
||||
- Support CGNet ([#223](https://github.com/open-mmlab/mmsegmentation/pull/223))
|
||||
|
||||
### V0.7 (07/10/2020)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support Pascal Context dataset and customizing class dataset.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed CPU inference ([#153](https://github.com/open-mmlab/mmsegmentation/pull/153))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Add DeepLab OS16 models ([#154](https://github.com/open-mmlab/mmsegmentation/pull/154))
|
||||
- Support Pascal Context dataset ([#133](https://github.com/open-mmlab/mmsegmentation/pull/133))
|
||||
- Support customizing dataset classes ([#71](https://github.com/open-mmlab/mmsegmentation/pull/71))
|
||||
- Support customizing dataset palette ([#157](https://github.com/open-mmlab/mmsegmentation/pull/157))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Support 4D tensor output in ONNX ([#150](https://github.com/open-mmlab/mmsegmentation/pull/150))
|
||||
- Remove redundancies in ONNX export ([#160](https://github.com/open-mmlab/mmsegmentation/pull/160))
|
||||
- Migrate to MMCV DepthwiseSeparableConv ([#158](https://github.com/open-mmlab/mmsegmentation/pull/158))
|
||||
- Migrate to MMCV collect_env ([#137](https://github.com/open-mmlab/mmsegmentation/pull/137))
|
||||
- Use img_prefix and seg_prefix for loading ([#153](https://github.com/open-mmlab/mmsegmentation/pull/153))
|
||||
|
||||
### V0.6 (10/09/2020)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support new methods i.e. MobileNetV2, EMANet, DNL, PointRend, Semantic FPN, Fast-SCNN, ResNeSt.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed sliding inference ONNX export ([#90](https://github.com/open-mmlab/mmsegmentation/pull/90))
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support MobileNet v2 ([#86](https://github.com/open-mmlab/mmsegmentation/pull/86))
|
||||
- Support EMANet ([#34](https://github.com/open-mmlab/mmsegmentation/pull/34))
|
||||
- Support DNL ([#37](https://github.com/open-mmlab/mmsegmentation/pull/37))
|
||||
- Support PointRend ([#109](https://github.com/open-mmlab/mmsegmentation/pull/109))
|
||||
- Support Semantic FPN ([#94](https://github.com/open-mmlab/mmsegmentation/pull/94))
|
||||
- Support Fast-SCNN ([#58](https://github.com/open-mmlab/mmsegmentation/pull/58))
|
||||
- Support ResNeSt backbone ([#47](https://github.com/open-mmlab/mmsegmentation/pull/47))
|
||||
- Support ONNX export (experimental) ([#12](https://github.com/open-mmlab/mmsegmentation/pull/12))
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Support Upsample in ONNX ([#100](https://github.com/open-mmlab/mmsegmentation/pull/100))
|
||||
- Support Windows install (experimental) ([#75](https://github.com/open-mmlab/mmsegmentation/pull/75))
|
||||
- Add more OCRNet results ([#20](https://github.com/open-mmlab/mmsegmentation/pull/20))
|
||||
- Add PyTorch 1.6 CI ([#64](https://github.com/open-mmlab/mmsegmentation/pull/64))
|
||||
- Get version and githash automatically ([#55](https://github.com/open-mmlab/mmsegmentation/pull/55))
|
||||
|
||||
### v0.5.1 (11/08/2020)
|
||||
|
||||
**Highlights**
|
||||
|
||||
- Support FP16 and more generalized OHEM
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
- Fixed Pascal VOC conversion script (#19)
|
||||
- Fixed OHEM weight assign bug (#54)
|
||||
- Fixed palette type when palette is not given (#27)
|
||||
|
||||
**New Features**
|
||||
|
||||
- Support FP16 (#21)
|
||||
- Generalized OHEM (#54)
|
||||
|
||||
**Improvements**
|
||||
|
||||
- Add load-from flag (#33)
|
||||
- Fixed training tricks doc about different learning rates of model (#26)
|
||||
132
Seg_All_In_One_MMSeg/docs/en/notes/faq.md
Normal file
132
Seg_All_In_One_MMSeg/docs/en/notes/faq.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# 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/dev-1.x/.github/ISSUE_TEMPLATE/error-report.md/) and make sure you fill in all required information in the template.
|
||||
|
||||
## Installation
|
||||
|
||||
The compatible MMSegmentation, MMCV and MMEngine versions are as below. Please install the correct versions of them to avoid installation issues.
|
||||
|
||||
| MMSegmentation version | MMCV version | MMEngine version | MMClassification (optional) version | MMDetection (optional) version |
|
||||
| :--------------------: | :----------------------------: | :---------------: | :---------------------------------: | :----------------------------: |
|
||||
| dev-1.x branch | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| main branch | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.2.2 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.2.1 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.2.0 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.1.2 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.1.1 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.1.0 | mmcv >= 2.0.0 | MMEngine >= 0.7.4 | mmpretrain>=1.0.0rc7 | mmdet >= 3.0.0 |
|
||||
| 1.0.0 | mmcv >= 2.0.0rc4 | MMEngine >= 0.7.1 | mmcls==1.0.0rc6 | mmdet >= 3.0.0 |
|
||||
| 1.0.0rc6 | mmcv >= 2.0.0rc4 | MMEngine >= 0.5.0 | mmcls>=1.0.0rc0 | mmdet >= 3.0.0rc6 |
|
||||
| 1.0.0rc5 | mmcv >= 2.0.0rc4 | MMEngine >= 0.2.0 | mmcls>=1.0.0rc0 | mmdet>=3.0.0rc6 |
|
||||
| 1.0.0rc4 | mmcv == 2.0.0rc3 | MMEngine >= 0.1.0 | mmcls>=1.0.0rc0 | mmdet>=3.0.0rc4, \<=3.0.0rc5 |
|
||||
| 1.0.0rc3 | mmcv == 2.0.0rc3 | MMEngine >= 0.1.0 | mmcls>=1.0.0rc0 | mmdet>=3.0.0rc4, \<=3.0.0rc5 |
|
||||
| 1.0.0rc2 | mmcv == 2.0.0rc3 | MMEngine >= 0.1.0 | mmcls>=1.0.0rc0 | mmdet>=3.0.0rc4, \<=3.0.0rc5 |
|
||||
| 1.0.0rc1 | mmcv >= 2.0.0rc1, \<=2.0.0rc3> | MMEngine >= 0.1.0 | mmcls>=1.0.0rc0 | Not required |
|
||||
| 1.0.0rc0 | mmcv >= 2.0.0rc1, \<=2.0.0rc3> | MMEngine >= 0.1.0 | mmcls>=1.0.0rc0 | Not required |
|
||||
|
||||
Notes:
|
||||
|
||||
- MMClassification and MMDetatction are optional for MMSegmentation. If you didn't install them, `ConvNeXt` (required MMClassification) and MaskFormer, Mask2Former (required MMDetection) cannot be used. We recommend to install them with source code. Please refer to [MMClasssication](https://github.com/open-mmlab/mmclassification) and [MMDetection](https://github.com/open-mmlab/mmdetection) for more details about their installation.
|
||||
|
||||
- To install MMSegmentation 0.x and master branch, please refer to [the faq 0.x document](https://mmsegmentation.readthedocs.io/en/latest/faq.html#installation) to check compatible versions of MMCV.
|
||||
|
||||
- If you have installed an incompatible version of mmcv, please run `pip uninstall mmcv` to uninstall the installed mmcv first. If you have previously installed mmcv-full (which exists in OpenMMLab 1.x), please run `pip uninstall mmcv-full` to uninstall it.
|
||||
|
||||
- If "No module named 'mmcv'" appears, please follow the steps below;
|
||||
|
||||
1. Use `pip uninstall mmcv` to uninstall the existing mmcv in the environment.
|
||||
2. Install the corresponding mmcv according to the [installation instructions](https://mmsegmentation.readthedocs.io/en/dev-1.x/get_started.html#best-practices).
|
||||
|
||||
## How to know the number of GPUs needed to train the model
|
||||
|
||||
- Infer from the name of the config file of the model. You can refer to the `Config Name Style` part of [Learn about Configs](../user_guides/1_config.md). For example, for config file with name `segformer_mit-b0_8xb1-160k_cityscapes-1024x1024.py`, `8xb1` means training the model corresponding to it needs 8 GPUs, and the batch size of each GPU is 1.
|
||||
- Infer from the log file. Open the log file of the model and search `nGPU` in the file. The number of figures following `nGPU` is the number of GPUs needed to train the model. For instance, searching for `nGPU` in the log file yields the record `nGPU 0,1,2,3,4,5,6,7`, which indicates that eight GPUs are needed to train the model.
|
||||
|
||||
## What does the auxiliary head mean
|
||||
|
||||
Briefly, it is a deep supervision trick to improve the accuracy. In the training phase, `decode_head` is for decoding semantic segmentation output, `auxiliary_head` is just adding an auxiliary loss, the segmentation result produced by it has no impact to your model's result, it just works in training. You may read this [paper](https://arxiv.org/pdf/1612.01105.pdf) for more information.
|
||||
|
||||
## How to output the segmentation mask image when running the test script
|
||||
|
||||
In the test script, we provide `--out` argument to control whether output the painted images. Users might run the following command:
|
||||
|
||||
```shell
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} --out ${OUTPUT_DIR}
|
||||
```
|
||||
|
||||
## How to handle binary segmentation task
|
||||
|
||||
MMSegmentation uses `num_classes` and `out_channels` to control output of last layer `self.conv_seg`. More details could be found [here](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/mmseg/models/decode_heads/decode_head.py).
|
||||
|
||||
`num_classes` should be the same as number of types of labels, in binary segmentation task, dataset only has two types of labels: foreground and background, so `num_classes=2`. `out_channels` controls the output channel of last layer of model, it usually equals to `num_classes`.
|
||||
But in binary segmentation task, there are two solutions:
|
||||
|
||||
- Set `out_channels=2`, using Cross Entropy Loss in training, using `F.softmax()` and `argmax()` to get prediction of each pixel in inference.
|
||||
|
||||
- Set `out_channels=1`, using Binary Cross Entropy Loss in training, using `F.sigmoid()` and `threshold` to get prediction of each pixel in inference. `threshold` is set 0.3 as default.
|
||||
|
||||
In summary, to implement binary segmentation methods users should modify below parameters in the `decode_head` and `auxiliary_head` configs. Here is a modification example of [pspnet_unet_s5-d16.py](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/_base_/models/pspnet_unet_s5-d16.py):
|
||||
|
||||
- (1) `num_classes=2`, `out_channels=2` and `use_sigmoid=False` in `CrossEntropyLoss`.
|
||||
|
||||
```python
|
||||
decode_head=dict(
|
||||
type='PSPHead',
|
||||
in_channels=64,
|
||||
in_index=4,
|
||||
num_classes=2,
|
||||
out_channels=2,
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)),
|
||||
auxiliary_head=dict(
|
||||
type='FCNHead',
|
||||
in_channels=128,
|
||||
in_index=3,
|
||||
num_classes=2,
|
||||
out_channels=2,
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)),
|
||||
```
|
||||
|
||||
- (2) `num_classes=2`, `out_channels=1` and `use_sigmoid=True` in `CrossEntropyLoss`.
|
||||
|
||||
```python
|
||||
decode_head=dict(
|
||||
type='PSPHead',
|
||||
in_channels=64,
|
||||
in_index=4,
|
||||
num_classes=2,
|
||||
out_channels=1,
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0)),
|
||||
auxiliary_head=dict(
|
||||
type='FCNHead',
|
||||
in_channels=128,
|
||||
in_index=3,
|
||||
num_classes=2,
|
||||
out_channels=1,
|
||||
loss_decode=dict(
|
||||
type='CrossEntropyLoss', use_sigmoid=True, loss_weight=0.4)),
|
||||
```
|
||||
|
||||
## Functionality of `reduce_zero_label`
|
||||
|
||||
The parameter type of `reduce_zero_label` in dataset is Boolean, which is default to False. It is used to ignore the dataset label 0. The specific method is to change label 0 to 255, and subtract 1 from the corresponding number of all the remaining labels. At the same time, set 255 as ignore index in the decode head, which means that it will not participate in the loss calculation.
|
||||
|
||||
Following is the specific implementation logic of `reduce_zero_label`:
|
||||
|
||||
```python
|
||||
if self.reduce_zero_label:
|
||||
# avoid using underflow conversion
|
||||
gt_semantic_seg[gt_semantic_seg == 0] = 255
|
||||
gt_semantic_seg = gt_semantic_seg - 1
|
||||
gt_semantic_seg[gt_semantic_seg == 254] = 255
|
||||
```
|
||||
|
||||
Whether your dataset needs to use `reduce_zero_label`, there are two types of situations:
|
||||
|
||||
- On [Potsdam](https://github.com/open-mmlab/mmsegmentation/blob/1.x/docs/en/user_guides/2_dataset_prepare.md#isprs-potsdam) dataset, there are six classes: 0-Impervious surfaces, 1-Building, 2-Low vegetation, 3-Tree, 4-Car, 5-Clutter/background. However, this dataset provides two types of RGB labels, one with black pixels at the edges of the images, and the other without. For labels with black edges, in [dataset_converters.py](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/tools/dataset_converters/potsdam.py), it converts the black edges to label 0, and the other labels are 1-Impervious surfaces, 2-Building, 3-Low vegetation, 4-Tree, 5-Car, 6-Clutter/background. Therefore, in the dataset config [potsdam.py](https://github.com/open-mmlab/mmsegmentation/blob/ff95416c3b5ce8d62b9289f743531398efce534f/mmseg/datasets/potsdam.py#L23) `reduce_zero_label=True`。 If you are using labels without black edges, then there are only class 0-5 in the mask label. At this point, you should use `reduce_zero_label=False`. `reduce_zero_label` usage needs to be considered with your actual situation.
|
||||
- On a dataset with class 0 as the background class, if you need to separate the background from the rest of your classes ultimately then you do not need to use `reduce_zero_label`, which in the dataset config settings should be `reduce_zero_label=False`
|
||||
|
||||
**Note:** Please confirm the number of original classes in the dataset. If there are only two classes, you should not use `reduce_zero_label` which is `reduce_zero_label=False`.
|
||||
85
Seg_All_In_One_MMSeg/docs/en/overview.md
Normal file
85
Seg_All_In_One_MMSeg/docs/en/overview.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Overview
|
||||
|
||||
This chapter introduces you to the framework of MMSegmentation, and the basic conception of semantic segmentation. It also provides links to detailed tutorials about MMSegmentation.
|
||||
|
||||
## What is semantic segmentation?
|
||||
|
||||
Semantic segmentation is the task of clustering parts of an image together that belong to the same object class.
|
||||
It is a form of pixel-level prediction because each pixel in an image is classified according to a category.
|
||||
Some example benchmarks for this task are [Cityscapes](https://www.cityscapes-dataset.com/benchmarks/), [PASCAL VOC](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/) and [ADE20K](https://groups.csail.mit.edu/vision/datasets/ADE20K/).
|
||||
Models are usually evaluated with the Mean Intersection-Over-Union (Mean IoU) and Pixel Accuracy metrics.
|
||||
|
||||
## What is MMSegmentation?
|
||||
|
||||
MMSegmentation is a toolbox that provides a framework for unified implementation and evaluation of semant
|
||||
ic segmentation methods,
|
||||
and contains high-quality implementations of popular semantic segmentation methods and datasets.
|
||||
|
||||
MMSeg consists of 7 main parts including apis, structures, datasets, models, engine, evaluation and visualization.
|
||||
|
||||
- **apis** provides high-level APIs for model inference.
|
||||
|
||||
- **structures** provides segmentation data structure `SegDataSample`.
|
||||
|
||||
- **datasets** supports various datasets for semantic segmentation.
|
||||
|
||||
- **transforms** contains a lot of useful data augmentation transforms.
|
||||
|
||||
- **models** is the most vital part for segmentors and contains different components of a segmentor.
|
||||
|
||||
- **segmentors** defines all of the segmentation model classes.
|
||||
- **data_preprocessors** works for preprocessing the input data of the model.
|
||||
- **backbones** contains various backbone networks that transform an image to feature maps.
|
||||
- **necks** contains various neck components that connect the backbone and heads.
|
||||
- **decode_heads** contains various head components that take feature map as input and predict segmentation results.
|
||||
- **losses** contains various loss functions.
|
||||
|
||||
- **engine** is a part for runtime components that extends function of [MMEngine](https://github.com/open-mmlab/mmengine).
|
||||
|
||||
- **optimizers** provides optimizers and optimizer wrappers.
|
||||
- **hooks** provides various hooks of the runner.
|
||||
|
||||
- **evaluation** provides different metrics for evaluating model performance.
|
||||
|
||||
- **visualization** is for visualizing segmentation results.
|
||||
|
||||
## How to use this documentation
|
||||
|
||||
Here is a detailed step-by-step guide to learn more about MMSegmentation:
|
||||
|
||||
1. For installation instructions, please see [get_started](getting_started.md).
|
||||
|
||||
2. For beginners, MMSegmentation is the best place to start the journey of semantic segmentation
|
||||
as there are many SOTA and classic segmentation [models](model_zoo.md),
|
||||
and it is easier to carry out a segmentation task by plugging together building blocks and convenient high-level apis.
|
||||
Refer to the tutorials below for the basic usage of MMSegmentation:
|
||||
|
||||
- [Config](user_guides/1_config.md)
|
||||
- [Dataset Preparation](user_guides/2_dataset_prepare.md)
|
||||
- [Inference](user_guides/3_inference.md)
|
||||
- [Train and Test](user_guides/4_train_test.md)
|
||||
|
||||
3. If you would like to learn about the fundamental classes and features that make MMSegmentation work,
|
||||
please refer to the tutorials below to dive deeper:
|
||||
|
||||
- [Data flow](advanced_guides/data_flow.md)
|
||||
- [Structures](advanced_guides/structures.md)
|
||||
- [Models](advanced_guides/models.md)
|
||||
- [Datasets](advanced_guides/datasets.md)
|
||||
- [Evaluation](advanced_guides/evaluation.md)
|
||||
|
||||
4. MMSegmentation also provide tutorials for customization and advanced research,
|
||||
please refer to the below guides to build your own segmentation project:
|
||||
|
||||
- [Add new models](advanced_guides/add_models.md)
|
||||
- [Add new datasets](advanced_guides/add_datasets.md)
|
||||
- [Add new transforms](advanced_guides/add_transforms.md)
|
||||
- [Customize runtime](advanced_guides/customize_runtime.md)
|
||||
|
||||
5. If you are more familiar with MMSegmentation v0.x, there is documentation about migration from MMSegmentation v0.x to v1.x
|
||||
|
||||
- [migration](migration/index.rst)
|
||||
|
||||
## References
|
||||
|
||||
- [Paper with code](https://paperswithcode.com/task/semantic-segmentation/codeless#task-home)
|
||||
67
Seg_All_In_One_MMSeg/docs/en/stat.py
Normal file
67
Seg_All_In_One_MMSeg/docs/en/stat.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import functools as func
|
||||
import glob
|
||||
import os.path as osp
|
||||
import re
|
||||
|
||||
import numpy as np
|
||||
|
||||
url_prefix = 'https://github.com/open-mmlab/mmsegmentation/blob/master/'
|
||||
|
||||
files = sorted(glob.glob('../../configs/*/README.md'))
|
||||
|
||||
stats = []
|
||||
titles = []
|
||||
num_ckpts = 0
|
||||
|
||||
for f in files:
|
||||
url = osp.dirname(f.replace('../../', url_prefix))
|
||||
|
||||
with open(f) as content_file:
|
||||
content = content_file.read()
|
||||
|
||||
title = content.split('\n')[0].replace('#', '').strip()
|
||||
ckpts = {
|
||||
x.lower().strip()
|
||||
for x in re.findall(r'https?://download.*\.pth', content)
|
||||
if 'mmsegmentation' in x
|
||||
}
|
||||
if len(ckpts) == 0:
|
||||
continue
|
||||
|
||||
_papertype = [
|
||||
x for x in re.findall(r'<!--\s*\[([A-Z]*?)\]\s*-->', content)
|
||||
]
|
||||
assert len(_papertype) > 0
|
||||
papertype = _papertype[0]
|
||||
|
||||
paper = {(papertype, title)}
|
||||
|
||||
titles.append(title)
|
||||
num_ckpts += len(ckpts)
|
||||
statsmsg = f"""
|
||||
\t* [{papertype}] [{title}]({url}) ({len(ckpts)} ckpts)
|
||||
"""
|
||||
stats.append((paper, ckpts, statsmsg))
|
||||
|
||||
allpapers = func.reduce(lambda a, b: a.union(b), [p for p, _, _ in stats])
|
||||
msglist = '\n'.join(x for _, _, x in stats)
|
||||
|
||||
papertypes, papercounts = np.unique([t for t, _ in allpapers],
|
||||
return_counts=True)
|
||||
countstr = '\n'.join(
|
||||
[f' - {t}: {c}' for t, c in zip(papertypes, papercounts)])
|
||||
|
||||
modelzoo = f"""
|
||||
# Model Zoo Statistics
|
||||
|
||||
* Number of papers: {len(set(titles))}
|
||||
{countstr}
|
||||
|
||||
* Number of checkpoints: {num_ckpts}
|
||||
{msglist}
|
||||
"""
|
||||
|
||||
with open('modelzoo_statistics.md', 'w') as f:
|
||||
f.write(modelzoo)
|
||||
3
Seg_All_In_One_MMSeg/docs/en/switch_language.md
Normal file
3
Seg_All_In_One_MMSeg/docs/en/switch_language.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## <a href='https://mmsegmentation.readthedocs.io/en/latest/'>English</a>
|
||||
|
||||
## <a href='https://mmsegmentation.readthedocs.io/zh_CN/latest/'>简体中文</a>
|
||||
588
Seg_All_In_One_MMSeg/docs/en/user_guides/1_config.md
Normal file
588
Seg_All_In_One_MMSeg/docs/en/user_guides/1_config.md
Normal file
@@ -0,0 +1,588 @@
|
||||
# Tutorial 1: Learn about Configs
|
||||
|
||||
We incorporate modular and inheritance design into our config system, which is convenient to conduct various experiments.
|
||||
If you wish to inspect the config file, you may run `python tools/misc/print_config.py /PATH/TO/CONFIG` to see the complete config.
|
||||
You may also pass `--cfg-options xxx.yyy=zzz` to see updated config.
|
||||
|
||||
## Config File Structure
|
||||
|
||||
There are 4 basic component types under `config/_base_`, datasets, models, schedules, default_runtime.
|
||||
Many methods could be easily constructed with one of each like DeepLabV3, PSPNet.
|
||||
The configs that are composed by components from `_base_` are called _primitive_.
|
||||
|
||||
For all configs under the same folder, it is recommended to have only **one** _primitive_ config. All other configs should inherit from the _primitive_ config. In this way, the maximum of inheritance level is 3.
|
||||
|
||||
For easy understanding, we recommend contributors to inherit from existing methods.
|
||||
For example, if some modification is made base on DeepLabV3, user may first inherit the basic DeepLabV3 structure by specifying `_base_ = ../deeplabv3/deeplabv3_r50-d8_4xb2-40k_cityscapes-512x1024.py`, then modify the necessary fields in the config files.
|
||||
|
||||
If you are building an entirely new method that does not share the structure with any of the existing methods, you may create a folder `xxxnet` under `configs`,
|
||||
|
||||
Please refer to [mmengine](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) for detailed documentation.
|
||||
|
||||
## Config Name Style
|
||||
|
||||
We follow the below style to name config files. Contributors are advised to follow the same style.
|
||||
|
||||
```text
|
||||
{algorithm name}_{model component names [component1]_[component2]_[...]}_{training settings}_{training dataset information}_{testing dataset information}
|
||||
```
|
||||
|
||||
The file name is divided to five parts. All parts and components are connected with `_` and words of each part or component should be connected with `-`.
|
||||
|
||||
- `{algorithm name}`: The name of the algorithm, such as `deeplabv3`, `pspnet`, etc.
|
||||
- `{model component names}`: Names of the components used in the algorithm such as backbone, head, etc. For example, `r50-d8` means using ResNet50 backbone and use output of backbone is 8 times downsampling as input.
|
||||
- `{training settings}`: Information of training settings such as batch size, augmentations, loss, learning rate scheduler, and epochs/iterations. For example: `4xb4-ce-linearlr-40K` means using 4-gpus x 4-images-per-gpu, CrossEntropy loss, Linear learning rate scheduler, and train 40K iterations.
|
||||
Some abbreviations:
|
||||
- `{gpu x batch_per_gpu}`: GPUs and samples per GPU. `bN` indicates N batch size per GPU. E.g. `8xb2` is the short term of 8-gpus x 2-images-per-gpu. And `4xb4` is used by default if not mentioned.
|
||||
- `{schedule}`: training schedule, options are `20k`, `40k`, etc. `20k` and `40k` means 20000 iterations and 40000 iterations respectively.
|
||||
- `{training dataset information}`: Training dataset names like `cityscapes`, `ade20k`, etc, and input resolutions. For example: `cityscapes-768x768` means training on `cityscapes` dataset and the input shape is `768x768`.
|
||||
- `{testing dataset information}` (optional): Testing dataset name for models trained on one dataset but tested on another. If not mentioned, it means the model was trained and tested on the same dataset type.
|
||||
|
||||
## An Example of PSPNet
|
||||
|
||||
To help the users have a basic idea of a complete config and the modules in a modern semantic segmentation system,
|
||||
we make brief comments on the config of PSPNet using ResNet50V1c as the following.
|
||||
For more detailed usage and the corresponding alternative for each module, please refer to the API documentation.
|
||||
|
||||
```python
|
||||
_base_ = [
|
||||
'../_base_/models/pspnet_r50-d8.py', '../_base_/datasets/cityscapes.py',
|
||||
'../_base_/default_runtime.py', '../_base_/schedules/schedule_40k.py'
|
||||
] # base config file which we build new config file on.
|
||||
crop_size = (512, 1024)
|
||||
data_preprocessor = dict(size=crop_size)
|
||||
model = dict(data_preprocessor=data_preprocessor)
|
||||
```
|
||||
|
||||
`_base_/models/pspnet_r50-d8.py` is a basic model cfg file for PSPNet using ResNet50V1c
|
||||
|
||||
```python
|
||||
# model settings
|
||||
norm_cfg = dict(type='SyncBN', requires_grad=True) # Segmentation usually uses SyncBN
|
||||
data_preprocessor = dict( # The config of data preprocessor, usually includes image normalization and augmentation.
|
||||
type='SegDataPreProcessor', # The type of data preprocessor.
|
||||
mean=[123.675, 116.28, 103.53], # Mean values used for normalizing the input images.
|
||||
std=[58.395, 57.12, 57.375], # Standard variance used for normalizing the input images.
|
||||
bgr_to_rgb=True, # Whether to convert image from BGR to RGB.
|
||||
pad_val=0, # Padding value of image.
|
||||
seg_pad_val=255) # Padding value of segmentation map.
|
||||
model = dict(
|
||||
type='EncoderDecoder', # Name of segmentor
|
||||
data_preprocessor=data_preprocessor,
|
||||
pretrained='open-mmlab://resnet50_v1c', # The ImageNet pretrained backbone to be loaded
|
||||
backbone=dict(
|
||||
type='ResNetV1c', # The type of backbone. Please refer to mmseg/models/backbones/resnet.py for details.
|
||||
depth=50, # Depth of backbone. Normally 50, 101 are used.
|
||||
num_stages=4, # Number of stages of backbone.
|
||||
out_indices=(0, 1, 2, 3), # The index of output feature maps produced in each stages.
|
||||
dilations=(1, 1, 2, 4), # The dilation rate of each layer.
|
||||
strides=(1, 2, 1, 1), # The stride of each layer.
|
||||
norm_cfg=norm_cfg, # The configuration of norm layer.
|
||||
norm_eval=False, # Whether to freeze the statistics in BN
|
||||
style='pytorch', # The style of backbone, 'pytorch' means that stride 2 layers are in 3x3 conv, 'caffe' means stride 2 layers are in 1x1 convs.
|
||||
contract_dilation=True), # When dilation > 1, whether contract first layer of dilation.
|
||||
decode_head=dict(
|
||||
type='PSPHead', # Type of decode head. Please refer to mmseg/models/decode_heads for available options.
|
||||
in_channels=2048, # Input channel of decode head.
|
||||
in_index=3, # The index of feature map to select.
|
||||
channels=512, # The intermediate channels of decode head.
|
||||
pool_scales=(1, 2, 3, 6), # The avg pooling scales of PSPHead. Please refer to paper for details.
|
||||
dropout_ratio=0.1, # The dropout ratio before final classification layer.
|
||||
num_classes=19, # Number of segmentation class. Usually 19 for cityscapes, 21 for VOC, 150 for ADE20k.
|
||||
norm_cfg=norm_cfg, # The configuration of norm layer.
|
||||
align_corners=False, # The align_corners argument for resize in decoding.
|
||||
loss_decode=dict( # Config of loss function for the decode_head.
|
||||
type='CrossEntropyLoss', # Type of loss used for segmentation.
|
||||
use_sigmoid=False, # Whether use sigmoid activation for segmentation.
|
||||
loss_weight=1.0)), # Loss weight of decode_head.
|
||||
auxiliary_head=dict(
|
||||
type='FCNHead', # Type of auxiliary head. Please refer to mmseg/models/decode_heads for available options.
|
||||
in_channels=1024, # Input channel of auxiliary head.
|
||||
in_index=2, # The index of feature map to select.
|
||||
channels=256, # The intermediate channels of decode head.
|
||||
num_convs=1, # Number of convs in FCNHead. It is usually 1 in auxiliary head.
|
||||
concat_input=False, # Whether concat output of convs with input before classification layer.
|
||||
dropout_ratio=0.1, # The dropout ratio before final classification layer.
|
||||
num_classes=19, # Number of segmentation class. Usually 19 for cityscapes, 21 for VOC, 150 for ADE20k.
|
||||
norm_cfg=norm_cfg, # The configuration of norm layer.
|
||||
align_corners=False, # The align_corners argument for resize in decoding.
|
||||
loss_decode=dict( # Config of loss function for the auxiliary_head.
|
||||
type='CrossEntropyLoss', # Type of loss used for segmentation.
|
||||
use_sigmoid=False, # Whether use sigmoid activation for segmentation.
|
||||
loss_weight=0.4)), # Loss weight of auxiliary_head.
|
||||
# model training and testing settings
|
||||
train_cfg=dict(), # train_cfg is just a place holder for now.
|
||||
test_cfg=dict(mode='whole')) # The test mode, options are 'whole' and 'slide'. 'whole': whole image fully-convolutional test. 'slide': sliding crop window on the image.
|
||||
```
|
||||
|
||||
`_base_/datasets/cityscapes.py` is the configuration file of the dataset
|
||||
|
||||
```python
|
||||
# dataset settings
|
||||
dataset_type = 'CityscapesDataset' # Dataset type, this will be used to define the dataset.
|
||||
data_root = 'data/cityscapes/' # Root path of data.
|
||||
crop_size = (512, 1024) # The crop size during training.
|
||||
train_pipeline = [ # Training pipeline.
|
||||
dict(type='LoadImageFromFile'), # First pipeline to load images from file path.
|
||||
dict(type='LoadAnnotations'), # Second pipeline to load annotations for current image.
|
||||
dict(type='RandomResize', # Augmentation pipeline that resize the images and their annotations.
|
||||
scale=(2048, 1024), # The scale of image.
|
||||
ratio_range=(0.5, 2.0), # The augmented scale range as ratio.
|
||||
keep_ratio=True), # Whether to keep the aspect ratio when resizing the image.
|
||||
dict(type='RandomCrop', # Augmentation pipeline that randomly crop a patch from current image.
|
||||
crop_size=crop_size, # The crop size of patch.
|
||||
cat_max_ratio=0.75), # The max area ratio that could be occupied by single category.
|
||||
dict(type='RandomFlip', # Augmentation pipeline that flip the images and their annotations
|
||||
prob=0.5), # The ratio or probability to flip
|
||||
dict(type='PhotoMetricDistortion'), # Augmentation pipeline that distort current image with several photo metric methods.
|
||||
dict(type='PackSegInputs') # Pack the inputs data for the semantic segmentation.
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='LoadImageFromFile'), # First pipeline to load images from file path
|
||||
dict(type='Resize', # Use resize augmentation
|
||||
scale=(2048, 1024), # Images scales for resizing.
|
||||
keep_ratio=True), # Whether to keep the aspect ratio when resizing the image.
|
||||
# add loading annotation after ``Resize`` because ground truth
|
||||
# does not need to do resize data transform
|
||||
dict(type='LoadAnnotations'), # Load annotations for semantic segmentation provided by dataset.
|
||||
dict(type='PackSegInputs') # Pack the inputs data for the semantic segmentation.
|
||||
]
|
||||
train_dataloader = dict( # Train dataloader config
|
||||
batch_size=2, # Batch size of a single GPU
|
||||
num_workers=2, # Worker to pre-fetch data for each single GPU
|
||||
persistent_workers=True, # Shut down the worker processes after an epoch end, which can accelerate training speed.
|
||||
sampler=dict(type='InfiniteSampler', shuffle=True), # Randomly shuffle during training.
|
||||
dataset=dict( # Train dataset config
|
||||
type=dataset_type, # Type of dataset, refer to mmseg/datasets/ for details.
|
||||
data_root=data_root, # The root of dataset.
|
||||
data_prefix=dict(
|
||||
img_path='leftImg8bit/train', seg_map_path='gtFine/train'), # Prefix for training data.
|
||||
pipeline=train_pipeline)) # Processing pipeline. This is passed by the train_pipeline created before.
|
||||
val_dataloader = dict(
|
||||
batch_size=1, # Batch size of a single GPU
|
||||
num_workers=4, # Worker to pre-fetch data for each single GPU
|
||||
persistent_workers=True, # Shut down the worker processes after an epoch end, which can accelerate testing speed.
|
||||
sampler=dict(type='DefaultSampler', shuffle=False), # Not shuffle during validation and testing.
|
||||
dataset=dict( # Test dataset config
|
||||
type=dataset_type, # Type of dataset, refer to mmseg/datasets/ for details.
|
||||
data_root=data_root, # The root of dataset.
|
||||
data_prefix=dict(
|
||||
img_path='leftImg8bit/val', seg_map_path='gtFine/val'), # Prefix for testing data.
|
||||
pipeline=test_pipeline)) # Processing pipeline. This is passed by the test_pipeline created before.
|
||||
test_dataloader = val_dataloader
|
||||
# The metric to measure the accuracy. Here, we use IoUMetric.
|
||||
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
|
||||
test_evaluator = val_evaluator
|
||||
```
|
||||
|
||||
`_base_/schedules/schedule_40k.py`
|
||||
|
||||
```python
|
||||
# optimizer
|
||||
optimizer = dict(type='SGD', # Type of optimizers, refer to https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/optimizer/default_constructor.py for more details
|
||||
lr=0.01, # Learning rate of optimizers, see detail usages of the parameters in the documentation of PyTorch
|
||||
momentum=0.9, # Momentum
|
||||
weight_decay=0.0005) # Weight decay of SGD
|
||||
optim_wrapper = dict(type='OptimWrapper', # Optimizer wrapper provides a common interface for updating parameters.
|
||||
optimizer=optimizer, # Optimizer used to update model parameters.
|
||||
clip_grad=None) # If ``clip_grad`` is not None, it will be the arguments of ``torch.nn.utils.clip_grad``.
|
||||
# learning policy
|
||||
param_scheduler = [
|
||||
dict(
|
||||
type='PolyLR', # The policy of scheduler, also support Step, CosineAnnealing, Cyclic, etc. Refer to details of supported LrUpdater from https://github.com/open-mmlab/mmengine/blob/main/mmengine/optim/scheduler/lr_scheduler.py
|
||||
eta_min=1e-4, # Minimum learning rate at the end of scheduling.
|
||||
power=0.9, # The power of polynomial decay.
|
||||
begin=0, # Step at which to start updating the parameters.
|
||||
end=40000, # Step at which to stop updating the parameters.
|
||||
by_epoch=False) # Whether count by epoch or not.
|
||||
]
|
||||
# training schedule for 40k iteration
|
||||
train_cfg = dict(type='IterBasedTrainLoop', max_iters=40000, val_interval=4000)
|
||||
val_cfg = dict(type='ValLoop')
|
||||
test_cfg = dict(type='TestLoop')
|
||||
# default hooks
|
||||
default_hooks = dict(
|
||||
timer=dict(type='IterTimerHook'), # Log the time spent during iteration.
|
||||
logger=dict(type='LoggerHook', interval=50, log_metric_by_epoch=False), # Collect and write logs from different components of ``Runner``.
|
||||
param_scheduler=dict(type='ParamSchedulerHook'), # update some hyper-parameters in optimizer, e.g., learning rate.
|
||||
checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=4000), # Save checkpoints periodically.
|
||||
sampler_seed=dict(type='DistSamplerSeedHook')) # Data-loading sampler for distributed training.
|
||||
```
|
||||
|
||||
in `_base_/default_runtime.py`
|
||||
|
||||
```python
|
||||
# Set the default scope of the registry to mmseg.
|
||||
default_scope = 'mmseg'
|
||||
# environment
|
||||
env_cfg = dict(
|
||||
cudnn_benchmark=True,
|
||||
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
|
||||
dist_cfg=dict(backend='nccl'),
|
||||
)
|
||||
log_level = 'INFO'
|
||||
log_processor = dict(by_epoch=False)
|
||||
load_from = None # Load checkpoint from file.
|
||||
resume = False # Whether to resume from existed model.
|
||||
```
|
||||
|
||||
These are all the configs for training and testing PSPNet, to load and parse them, we can use [Config](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) implemented in [MMEngine](https://github.com/open-mmlab/mmengine)
|
||||
|
||||
```python
|
||||
from mmengine.config import Config
|
||||
|
||||
cfg = Config.fromfile('configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py')
|
||||
print(cfg.train_dataloader)
|
||||
```
|
||||
|
||||
```shell
|
||||
{'batch_size': 2,
|
||||
'num_workers': 2,
|
||||
'persistent_workers': True,
|
||||
'sampler': {'type': 'InfiniteSampler', 'shuffle': True},
|
||||
'dataset': {'type': 'CityscapesDataset',
|
||||
'data_root': 'data/cityscapes/',
|
||||
'data_prefix': {'img_path': 'leftImg8bit/train',
|
||||
'seg_map_path': 'gtFine/train'},
|
||||
'pipeline': [{'type': 'LoadImageFromFile'},
|
||||
{'type': 'LoadAnnotations'},
|
||||
{'type': 'RandomResize',
|
||||
'scale': (2048, 1024),
|
||||
'ratio_range': (0.5, 2.0),
|
||||
'keep_ratio': True},
|
||||
{'type': 'RandomCrop', 'crop_size': (512, 1024), 'cat_max_ratio': 0.75},
|
||||
{'type': 'RandomFlip', 'prob': 0.5},
|
||||
{'type': 'PhotoMetricDistortion'},
|
||||
{'type': 'PackSegInputs'}]}}
|
||||
```
|
||||
|
||||
`cfg` is an instance of `mmengine.config.Config`, its interface is the same as a dict object and also allows access config values as attributes. See [config tutorial](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
## FAQ
|
||||
|
||||
### Ignore some fields in the base configs
|
||||
|
||||
Sometimes, you may set `_delete_=True` to ignore some of the fields in base configs.
|
||||
See [config tutorial](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for simple illustration.
|
||||
|
||||
In MMSegmentation, for example, if you would like to modify the backbone of PSPNet with the following config file `pspnet.py`:
|
||||
|
||||
```python
|
||||
norm_cfg = dict(type='SyncBN', requires_grad=True)
|
||||
model = dict(
|
||||
type='EncoderDecoder',
|
||||
pretrained='torchvision://resnet50',
|
||||
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)))
|
||||
```
|
||||
|
||||
Load and parse the config file `pspnet.py` in the code as follows:
|
||||
|
||||
```python
|
||||
from mmengine.config import Config
|
||||
|
||||
cfg = Config.fromfile('pspnet.py')
|
||||
print(cfg.model)
|
||||
```
|
||||
|
||||
```shell
|
||||
{'type': 'EncoderDecoder',
|
||||
'pretrained': 'torchvision://resnet50',
|
||||
'backbone': {'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': {'type': 'SyncBN', 'requires_grad': True},
|
||||
'norm_eval': False,
|
||||
'style': 'pytorch',
|
||||
'contract_dilation': True},
|
||||
'decode_head': {'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': {'type': 'SyncBN', 'requires_grad': True},
|
||||
'align_corners': False,
|
||||
'loss_decode': {'type': 'CrossEntropyLoss',
|
||||
'use_sigmoid': False,
|
||||
'loss_weight': 1.0}}}
|
||||
```
|
||||
|
||||
`ResNet` and `HRNet` use different keywords to construct, write a new config file `hrnet.py` as follows:
|
||||
|
||||
```python
|
||||
_base_ = 'pspnet.py'
|
||||
norm_cfg = dict(type='SyncBN', requires_grad=True)
|
||||
model = dict(
|
||||
pretrained='open-mmlab://msra/hrnetv2_w32',
|
||||
backbone=dict(
|
||||
_delete_=True,
|
||||
type='HRNet',
|
||||
norm_cfg=norm_cfg,
|
||||
extra=dict(
|
||||
stage1=dict(
|
||||
num_modules=1,
|
||||
num_branches=1,
|
||||
block='BOTTLENECK',
|
||||
num_blocks=(4, ),
|
||||
num_channels=(64, )),
|
||||
stage2=dict(
|
||||
num_modules=1,
|
||||
num_branches=2,
|
||||
block='BASIC',
|
||||
num_blocks=(4, 4),
|
||||
num_channels=(32, 64)),
|
||||
stage3=dict(
|
||||
num_modules=4,
|
||||
num_branches=3,
|
||||
block='BASIC',
|
||||
num_blocks=(4, 4, 4),
|
||||
num_channels=(32, 64, 128)),
|
||||
stage4=dict(
|
||||
num_modules=3,
|
||||
num_branches=4,
|
||||
block='BASIC',
|
||||
num_blocks=(4, 4, 4, 4),
|
||||
num_channels=(32, 64, 128, 256)))))
|
||||
```
|
||||
|
||||
Load and parse the config file `hrnet.py` in the code as follows:
|
||||
|
||||
```python
|
||||
from mmengine.config import Config
|
||||
cfg = Config.fromfile('hrnet.py')
|
||||
print(cfg.model)
|
||||
```
|
||||
|
||||
```shell
|
||||
{'type': 'EncoderDecoder',
|
||||
'pretrained': 'open-mmlab://msra/hrnetv2_w32',
|
||||
'backbone': {'type': 'HRNet',
|
||||
'norm_cfg': {'type': 'SyncBN', 'requires_grad': True},
|
||||
'extra': {'stage1': {'num_modules': 1,
|
||||
'num_branches': 1,
|
||||
'block': 'BOTTLENECK',
|
||||
'num_blocks': (4,),
|
||||
'num_channels': (64,)},
|
||||
'stage2': {'num_modules': 1,
|
||||
'num_branches': 2,
|
||||
'block': 'BASIC',
|
||||
'num_blocks': (4, 4),
|
||||
'num_channels': (32, 64)},
|
||||
'stage3': {'num_modules': 4,
|
||||
'num_branches': 3,
|
||||
'block': 'BASIC',
|
||||
'num_blocks': (4, 4, 4),
|
||||
'num_channels': (32, 64, 128)},
|
||||
'stage4': {'num_modules': 3,
|
||||
'num_branches': 4,
|
||||
'block': 'BASIC',
|
||||
'num_blocks': (4, 4, 4, 4),
|
||||
'num_channels': (32, 64, 128, 256)}}},
|
||||
'decode_head': {'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': {'type': 'SyncBN', 'requires_grad': True},
|
||||
'align_corners': False,
|
||||
'loss_decode': {'type': 'CrossEntropyLoss',
|
||||
'use_sigmoid': False,
|
||||
'loss_weight': 1.0}}}
|
||||
```
|
||||
|
||||
The `_delete_=True` would replace all old keys in `backbone` field with new keys.
|
||||
|
||||
### Use intermediate variables in configs
|
||||
|
||||
Some intermediate variables are used in the configs files, like `train_pipeline`/`test_pipeline` in datasets.
|
||||
It's worth noting that when modifying intermediate variables in the children configs, user need to pass the intermediate variables into corresponding fields again.
|
||||
For example, we would like to change multi scale strategy to train/test a PSPNet. `train_pipeline`/`test_pipeline` are intermediate variable we would like to modify.
|
||||
|
||||
```python
|
||||
_base_ = '../pspnet/pspnet_r50-d8_4xb4-40k_cityscpaes-512x1024.py'
|
||||
crop_size = (512, 1024)
|
||||
img_norm_cfg = dict(
|
||||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
|
||||
train_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='RandomResize',
|
||||
img_scale=(2048, 1024),
|
||||
ratio_range=(1., 2.),
|
||||
keep_ration=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='PackSegInputs'),
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='Resize',
|
||||
scale=(2048, 1024),
|
||||
keep_ratio=True),
|
||||
dict(type='LoadAnnotations'),
|
||||
dict(type='PackSegInputs')
|
||||
]
|
||||
train_dataset=dict(
|
||||
type=dataset_type,
|
||||
data_root=data_root,
|
||||
data_prefix=dict(
|
||||
img_path='leftImg8bit/train', seg_map_path='gtFine/train'),
|
||||
pipeline=train_pipeline)
|
||||
test_dataset=dict(
|
||||
type=dataset_type,
|
||||
data_root=data_root,
|
||||
data_prefix=dict(
|
||||
img_path='leftImg8bit/val', seg_map_path='gtFine/val'),
|
||||
pipeline=test_pipeline)
|
||||
train_dataloader = dict(dataset=train_dataset)
|
||||
val_dataloader = dict(dataset=test_dataset)
|
||||
test_dataloader = val_dataloader
|
||||
```
|
||||
|
||||
We first define the new `train_pipeline`/`test_pipeline` and pass them into `dataset`.
|
||||
|
||||
Similarly, if we would like to switch from `SyncBN` to `BN` or `MMSyncBN`, we need to substitute every `norm_cfg` in the config.
|
||||
|
||||
```python
|
||||
_base_ = '../pspnet/pspnet_r50-d8_4xb4-40k_cityscpaes-512x1024.py'
|
||||
norm_cfg = dict(type='BN', requires_grad=True)
|
||||
model = dict(
|
||||
backbone=dict(norm_cfg=norm_cfg),
|
||||
decode_head=dict(norm_cfg=norm_cfg),
|
||||
auxiliary_head=dict(norm_cfg=norm_cfg))
|
||||
```
|
||||
|
||||
## Modify config through script arguments
|
||||
|
||||
In the [training script](https://github.com/open-mmlab/mmsegmentation/blob/1.x/tools/train.py) and the [testing script](https://github.com/open-mmlab/mmsegmentation/blob/1.x/tools/test.py), we support the script argument `--cfg-options`, it may help users override some settings in the used config, the key-value pair in `xxx=yyy` format will be merged into config file.
|
||||
|
||||
For example, this is a simplified script `demo_script.py`:
|
||||
|
||||
```python
|
||||
import argparse
|
||||
|
||||
from mmengine.config import Config, DictAction
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Script Example')
|
||||
parser.add_argument('config', help='train config file path')
|
||||
parser.add_argument(
|
||||
'--cfg-options',
|
||||
nargs='+',
|
||||
action=DictAction,
|
||||
help='override some settings in the used config, the key-value pair '
|
||||
'in xxx=yyy format will be merged into config file. If the value to '
|
||||
'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
|
||||
'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
|
||||
'Note that the quotation marks are necessary and that no white space '
|
||||
'is allowed.')
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
cfg = Config.fromfile(args.config)
|
||||
if args.cfg_options is not None:
|
||||
cfg.merge_from_dict(args.cfg_options)
|
||||
|
||||
print(cfg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
|
||||
An example config file `demo_config.py` as follows:
|
||||
|
||||
```python
|
||||
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_eval=False,
|
||||
style='pytorch',
|
||||
contract_dilation=True)
|
||||
```
|
||||
|
||||
Run `demo_script.py`:
|
||||
|
||||
```shell
|
||||
python demo_script.py demo_config.py
|
||||
```
|
||||
|
||||
```shell
|
||||
Config (path: demo_config.py): {'backbone': {'type': 'ResNetV1c', 'depth': 50, 'num_stages': 4, 'out_indices': (0, 1, 2, 3), 'dilations': (1, 1, 2, 4), 'strides': (1, 2, 1, 1), 'norm_eval': False, 'style': 'pytorch', 'contract_dilation': True}}
|
||||
```
|
||||
|
||||
Modify config through script arguments:
|
||||
|
||||
```shell
|
||||
python demo_script.py demo_config.py --cfg-options backbone.depth=101
|
||||
```
|
||||
|
||||
```shell
|
||||
Config (path: demo_config.py): {'backbone': {'type': 'ResNetV1c', 'depth': 101, 'num_stages': 4, 'out_indices': (0, 1, 2, 3), 'dilations': (1, 1, 2, 4), 'strides': (1, 2, 1, 1), 'norm_eval': False, 'style': 'pytorch', 'contract_dilation': True}}
|
||||
```
|
||||
|
||||
- Update values of list/tuples.
|
||||
|
||||
If the value to be updated is a list or a tuple. For example, the config file `demo_config.py` sets `strides=(1, 2, 1, 1)` in `backbone`.
|
||||
If you want to change this key, you may specify in two ways:
|
||||
|
||||
1. `--cfg-options backbone.strides="(1, 1, 1, 1)"`. Note that the quotation mark " is necessary to support list/tuple data types.
|
||||
|
||||
```shell
|
||||
python demo_script.py demo_config.py --cfg-options backbone.strides="(1, 1, 1, 1)"
|
||||
```
|
||||
|
||||
```shell
|
||||
Config (path: demo_config.py): {'backbone': {'type': 'ResNetV1c', 'depth': 50, 'num_stages': 4, 'out_indices': (0, 1, 2, 3), 'dilations': (1, 1, 2, 4), 'strides': (1, 1, 1, 1), 'norm_eval': False, 'style': 'pytorch', 'contract_dilation': True}}
|
||||
```
|
||||
|
||||
2. `--cfg-options backbone.strides=1,1,1,1`. Note that **NO** white space is allowed in the specified value.
|
||||
In addition, if the original type is tuple, it will be automatically converted to list after this way.
|
||||
|
||||
```shell
|
||||
python demo_script.py demo_config.py --cfg-options backbone.strides=1,1,1,1
|
||||
```
|
||||
|
||||
```shell
|
||||
Config (path: demo_config.py): {'backbone': {'type': 'ResNetV1c', 'depth': 50, 'num_stages': 4, 'out_indices': (0, 1, 2, 3), 'dilations': (1, 1, 2, 4), 'strides': [1, 1, 1, 1], 'norm_eval': False, 'style': 'pytorch', 'contract_dilation': True}}
|
||||
```
|
||||
|
||||
```{note}
|
||||
This modification method only supports modifying configuration items of string, int, float, boolean, None, list and tuple types.
|
||||
More specifically, for list and tuple types, the elements inside them must also be one of the above seven types.
|
||||
```
|
||||
806
Seg_All_In_One_MMSeg/docs/en/user_guides/2_dataset_prepare.md
Normal file
806
Seg_All_In_One_MMSeg/docs/en/user_guides/2_dataset_prepare.md
Normal file
@@ -0,0 +1,806 @@
|
||||
# Tutorial 2: Prepare datasets
|
||||
|
||||
It is recommended to symlink the dataset root to `$MMSEGMENTATION/data`.
|
||||
If your folder structure is different, you may need to change the corresponding paths in config files.
|
||||
For users in China, we also recommend you get the dsdl dataset from our opensource platform [OpenDataLab](https://opendatalab.com/), for better download and use experience,here is an example: [DSDLReadme](../../../configs/dsdl/README.md), welcome to try.
|
||||
|
||||
```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
|
||||
│ ├── coco_stuff10k
|
||||
│ │ ├── images
|
||||
│ │ │ ├── train2014
|
||||
│ │ │ ├── test2014
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── train2014
|
||||
│ │ │ ├── test2014
|
||||
│ │ ├── imagesLists
|
||||
│ │ │ ├── train.txt
|
||||
│ │ │ ├── test.txt
|
||||
│ │ │ ├── all.txt
|
||||
│ ├── coco_stuff164k
|
||||
│ │ ├── images
|
||||
│ │ │ ├── train2017
|
||||
│ │ │ ├── val2017
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── train2017
|
||||
│ │ │ ├── val2017
|
||||
│ ├── 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
|
||||
│ ├── mapillary
|
||||
│ │ ├── training
|
||||
│ │ │ ├── images
|
||||
│ │ │ ├── v1.2
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ └── panoptic
|
||||
│ │ │ ├── v2.0
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ ├── panoptic
|
||||
| │ │ │ └── polygons
|
||||
│ │ ├── validation
|
||||
│ │ │ ├── images
|
||||
| │ │ ├── v1.2
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ └── panoptic
|
||||
│ │ │ ├── v2.0
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ ├── panoptic
|
||||
| │ │ │ └── polygons
|
||||
│ ├── bdd100k
|
||||
│ │ ├── images
|
||||
│ │ │ └── 10k
|
||||
| │ │ │ ├── test
|
||||
| │ │ │ ├── train
|
||||
| │ │ │ └── val
|
||||
│ │ └── labels
|
||||
│ │ │ └── sem_seg
|
||||
| │ │ │ ├── colormaps
|
||||
| │ │ │ │ ├──train
|
||||
| │ │ │ │ └──val
|
||||
| │ │ │ ├── masks
|
||||
| │ │ │ │ ├──train
|
||||
| │ │ │ │ └──val
|
||||
| │ │ │ ├── polygons
|
||||
| │ │ │ │ ├──sem_seg_train.json
|
||||
| │ │ │ │ └──sem_seg_val.json
|
||||
| │ │ │ └── rles
|
||||
| │ │ │ │ ├──sem_seg_train.json
|
||||
| │ │ │ │ └──sem_seg_val.json
|
||||
│ ├── nyu
|
||||
│ │ ├── images
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── test
|
||||
│ ├── HSIDrive20
|
||||
│ │ ├── images
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── train
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
```
|
||||
|
||||
## Download dataset via MIM
|
||||
|
||||
By using [OpenXLab](https://openxlab.org.cn/datasets), you can obtain free formatted datasets in various fields. Through the search function of the platform, you may address the dataset they look for quickly and easily. Using the formatted datasets from the platform, you can efficiently conduct tasks across datasets.
|
||||
|
||||
If you use MIM to download, make sure that the version is greater than v0.3.8. You can use the following command to update, install, login and download the dataset:
|
||||
|
||||
```shell
|
||||
# upgrade your MIM
|
||||
pip install -U openmim
|
||||
|
||||
# install OpenXLab CLI tools
|
||||
pip install -U openxlab
|
||||
# log in OpenXLab
|
||||
openxlab login
|
||||
|
||||
# download ADE20K by MIM
|
||||
mim download mmsegmentation --dataset ade20k
|
||||
```
|
||||
|
||||
## Cityscapes
|
||||
|
||||
The data could be found [here](https://www.cityscapes-dataset.com/downloads/) after registration.
|
||||
|
||||
By convention, `**labelTrainIds.png` are used for cityscapes training.
|
||||
We provided a [script](https://github.com/open-mmlab/mmsegmentation/blob/1.x/tools/dataset_converters/cityscapes.py) based on [cityscapesscripts](https://github.com/mcordts/cityscapesScripts)to generate `**labelTrainIds.png`.
|
||||
|
||||
```shell
|
||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||
python tools/dataset_converters/cityscapes.py data/cityscapes --nproc 8
|
||||
```
|
||||
|
||||
## Pascal VOC
|
||||
|
||||
Pascal VOC 2012 could be downloaded from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar).
|
||||
Beside, most recent works on Pascal VOC dataset usually exploit extra augmentation data, which could be found [here](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz).
|
||||
|
||||
If you would like to use augmented VOC dataset, please run following command to convert augmentation annotations into proper format.
|
||||
|
||||
```shell
|
||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||
python tools/dataset_converters/voc_aug.py data/VOCdevkit data/VOCdevkit/VOCaug --nproc 8
|
||||
```
|
||||
|
||||
Please refer to [concat dataset](../advanced_guides/add_datasets.md#concatenate-dataset) and [voc_aug config example](../../../configs/_base_/datasets/pascal_voc12_aug.py) for details about how to concatenate them and train them together.
|
||||
|
||||
## ADE20K
|
||||
|
||||
The training and validation set of ADE20K could be download from this [link](http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip).
|
||||
We may also download test set from [here](http://data.csail.mit.edu/places/ADEchallenge/release_test.zip).
|
||||
|
||||
## Pascal Context
|
||||
|
||||
The training and validation set of Pascal Context could be download from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar). You may also download test set from [here](http://host.robots.ox.ac.uk:8080/eval/downloads/VOC2010test.tar) after registration.
|
||||
|
||||
To split the training and validation set from original dataset, you may download trainval_merged.json from [here](https://codalabuser.blob.core.windows.net/public/trainval_merged.json).
|
||||
|
||||
If you would like to use Pascal Context dataset, please install [Detail](https://github.com/zhanghang1989/detail-api) and then run the following command to convert annotations into proper format.
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/pascal_context.py data/VOCdevkit data/VOCdevkit/VOC2010/trainval_merged.json
|
||||
```
|
||||
|
||||
## COCO Stuff 10k
|
||||
|
||||
The data could be downloaded [here](http://calvin.inf.ed.ac.uk/wp-content/uploads/data/cocostuffdataset/cocostuff-10k-v1.1.zip) by wget.
|
||||
|
||||
For COCO Stuff 10k dataset, please run the following commands to download and convert the dataset.
|
||||
|
||||
```shell
|
||||
# download
|
||||
mkdir coco_stuff10k && cd coco_stuff10k
|
||||
wget http://calvin.inf.ed.ac.uk/wp-content/uploads/data/cocostuffdataset/cocostuff-10k-v1.1.zip
|
||||
|
||||
# unzip
|
||||
unzip cocostuff-10k-v1.1.zip
|
||||
|
||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||
python tools/dataset_converters/coco_stuff10k.py /path/to/coco_stuff10k --nproc 8
|
||||
```
|
||||
|
||||
By convention, mask labels in `/path/to/coco_stuff164k/annotations/*2014/*_labelTrainIds.png` are used for COCO Stuff 10k training and testing.
|
||||
|
||||
## COCO Stuff 164k
|
||||
|
||||
For COCO Stuff 164k dataset, please run the following commands to download and convert the augmented dataset.
|
||||
|
||||
```shell
|
||||
# download
|
||||
mkdir coco_stuff164k && cd coco_stuff164k
|
||||
wget http://images.cocodataset.org/zips/train2017.zip
|
||||
wget http://images.cocodataset.org/zips/val2017.zip
|
||||
wget http://calvin.inf.ed.ac.uk/wp-content/uploads/data/cocostuffdataset/stuffthingmaps_trainval2017.zip
|
||||
|
||||
# unzip
|
||||
unzip train2017.zip -d images/
|
||||
unzip val2017.zip -d images/
|
||||
unzip stuffthingmaps_trainval2017.zip -d annotations/
|
||||
|
||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||
python tools/dataset_converters/coco_stuff164k.py /path/to/coco_stuff164k --nproc 8
|
||||
```
|
||||
|
||||
By convention, mask labels in `/path/to/coco_stuff164k/annotations/*2017/*_labelTrainIds.png` are used for COCO Stuff 164k training and testing.
|
||||
|
||||
The details of this dataset could be found at [here](https://github.com/nightrome/cocostuff#downloads).
|
||||
|
||||
## CHASE DB1
|
||||
|
||||
The training and validation set of CHASE DB1 could be download from [here](https://staffnet.kingston.ac.uk/~ku15565/CHASE_DB1/assets/CHASEDB1.zip).
|
||||
|
||||
To convert CHASE DB1 dataset to MMSegmentation format, you should run the following command:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/chase_db1.py /path/to/CHASEDB1.zip
|
||||
```
|
||||
|
||||
The script will make directory structure automatically.
|
||||
|
||||
## DRIVE
|
||||
|
||||
The training and validation set of DRIVE could be download from [here](https://drive.grand-challenge.org/). Before that, you should register an account. Currently '1st_manual' is not provided officially.
|
||||
|
||||
To convert DRIVE dataset to MMSegmentation format, you should run the following command:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/drive.py /path/to/training.zip /path/to/test.zip
|
||||
```
|
||||
|
||||
The script will make directory structure automatically.
|
||||
|
||||
## HRF
|
||||
|
||||
First, download [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) and [diabetic_retinopathy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy_manualsegm.zip).
|
||||
|
||||
To convert HRF dataset to MMSegmentation format, you should run the following command:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/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
|
||||
```
|
||||
|
||||
The script will make directory structure automatically.
|
||||
|
||||
## STARE
|
||||
|
||||
First, download [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) and [labels-vk.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-vk.tar).
|
||||
|
||||
To convert STARE dataset to MMSegmentation format, you should run the following command:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/stare.py /path/to/stare-images.tar /path/to/labels-ah.tar /path/to/labels-vk.tar
|
||||
```
|
||||
|
||||
The script will make directory structure automatically.
|
||||
|
||||
## Dark Zurich
|
||||
|
||||
Since we only support test models on this dataset, you may only download [the validation set](https://data.vision.ee.ethz.ch/csakarid/shared/GCMA_UIoU/Dark_Zurich_val_anon.zip).
|
||||
|
||||
## Nighttime Driving
|
||||
|
||||
Since we only support test models on this dataset, you may only download [the test set](http://data.vision.ee.ethz.ch/daid/NighttimeDriving/NighttimeDrivingTest.zip).
|
||||
|
||||
## LoveDA
|
||||
|
||||
The data could be downloaded from Google Drive [here](https://drive.google.com/drive/folders/1ibYV0qwn4yuuh068Rnc-w4tPi0U0c-ti?usp=sharing).
|
||||
|
||||
Or it can be downloaded from [zenodo](https://zenodo.org/record/5706578#.YZvN7SYRXdF), you should run the following command:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
For LoveDA dataset, please run the following command to re-organize the dataset.
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/loveda.py /path/to/loveDA
|
||||
```
|
||||
|
||||
Using trained model to predict test set of LoveDA and submit it to server can be found [here](https://codalab.lisn.upsaclay.fr/competitions/421).
|
||||
|
||||
More details about LoveDA can be found [here](https://github.com/Junjue-Wang/LoveDA).
|
||||
|
||||
## ISPRS Potsdam
|
||||
|
||||
The [Potsdam](https://www.isprs.org/education/benchmarks/UrbanSemLab/2d-sem-label-potsdam.aspx) dataset is for urban semantic segmentation used in the 2D Semantic Labeling Contest - Potsdam.
|
||||
|
||||
The dataset can be requested at the challenge [homepage](https://www.isprs.org/education/benchmarks/UrbanSemLab/default.aspx).
|
||||
Or download on [BaiduNetdisk](https://pan.baidu.com/s/1K-cLVZnd1X7d8c26FQ-nGg?pwd=mseg),password:mseg, [Google Drive](https://drive.google.com/drive/folders/1w3EJuyUGet6_qmLwGAWZ9vw5ogeG0zLz?usp=sharing) and [OpenDataLab](https://opendatalab.com/ISPRS_Potsdam/download).
|
||||
The '2_Ortho_RGB.zip' and '5_Labels_all_noBoundary.zip' are required.
|
||||
|
||||
For Potsdam dataset, please run the following command to re-organize the dataset.
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/potsdam.py /path/to/potsdam
|
||||
```
|
||||
|
||||
In our default setting, it will generate 3456 images for training and 2016 images for validation.
|
||||
|
||||
## ISPRS Vaihingen
|
||||
|
||||
The [Vaihingen](https://www2.isprs.org/commissions/comm2/wg4/benchmark/2d-sem-label-vaihingen/) dataset is for urban semantic segmentation used in the 2D Semantic Labeling Contest - Vaihingen.
|
||||
|
||||
The dataset can be requested at the challenge [homepage](https://www2.isprs.org/commissions/comm2/wg4/benchmark/data-request-form/).
|
||||
Or [BaiduNetdisk](https://pan.baidu.com/s/109D3WLrLafsuYtLeerLiiA?pwd=mseg),password:mseg, [Google Drive](https://drive.google.com/drive/folders/1w3NhvLVA2myVZqOn2pbiDXngNC7NTP_t?usp=sharing).
|
||||
The 'ISPRS_semantic_labeling_Vaihingen.zip' and 'ISPRS_semantic_labeling_Vaihingen_ground_truth_eroded_COMPLETE.zip' are required.
|
||||
|
||||
For Vaihingen dataset, please run the following command to re-organize the dataset.
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/vaihingen.py /path/to/vaihingen
|
||||
```
|
||||
|
||||
In our default setting (`clip_size`=512, `stride_size`=256), it will generate 344 images for training and 398 images for validation.
|
||||
|
||||
## iSAID
|
||||
|
||||
The data images could be download from [DOTA-v1.0](https://captain-whu.github.io/DOTA/dataset.html) (train/val/test)
|
||||
|
||||
The data annotations could be download from [iSAID](https://captain-whu.github.io/iSAID/dataset.html) (train/val)
|
||||
|
||||
The dataset is a Large-scale Dataset for Instance Segmentation (also have semantic segmentation) in Aerial Images.
|
||||
|
||||
You may need to follow the following structure for dataset preparation after downloading iSAID dataset.
|
||||
|
||||
```none
|
||||
├── data
|
||||
│ ├── 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/dataset_converters/isaid.py /path/to/iSAID
|
||||
```
|
||||
|
||||
In our default setting (`patch_width`=896, `patch_height`=896, `overlap_area`=384), it will generate 33978 images for training and 11644 images for validation.
|
||||
|
||||
## LIP(Look Into Person) dataset
|
||||
|
||||
This dataset could be download from [this page](https://lip.sysuhcp.com/overview.php).
|
||||
|
||||
Please run the following commands to unzip dataset.
|
||||
|
||||
```shell
|
||||
unzip LIP.zip
|
||||
cd LIP
|
||||
unzip TrainVal_images.zip
|
||||
unzip TrainVal_parsing_annotations.zip
|
||||
cd TrainVal_parsing_annotations
|
||||
unzip TrainVal_parsing_annotations.zip
|
||||
mv train_segmentations ../
|
||||
mv val_segmentations ../
|
||||
cd ..
|
||||
```
|
||||
|
||||
The contents of LIP datasets include:
|
||||
|
||||
```none
|
||||
├── data
|
||||
│ ├── LIP
|
||||
│ │ ├── train_images
|
||||
│ │ │ ├── 1000_1234574.jpg
|
||||
│ │ │ ├── ...
|
||||
│ │ ├── train_segmentations
|
||||
│ │ │ ├── 1000_1234574.png
|
||||
│ │ │ ├── ...
|
||||
│ │ ├── val_images
|
||||
│ │ │ ├── 100034_483681.jpg
|
||||
│ │ │ ├── ...
|
||||
│ │ ├── val_segmentations
|
||||
│ │ │ ├── 100034_483681.png
|
||||
│ │ │ ├── ...
|
||||
```
|
||||
|
||||
## Synapse dataset
|
||||
|
||||
This dataset could be download from [this page](https://www.synapse.org/#!Synapse:syn3193805/wiki/).
|
||||
|
||||
To follow the data preparation setting of [TransUNet](https://arxiv.org/abs/2102.04306), which splits original training set (30 scans) into new training (18 scans) and validation set (12 scans). Please run the following command to prepare the dataset.
|
||||
|
||||
```shell
|
||||
unzip RawData.zip
|
||||
cd ./RawData/Training
|
||||
```
|
||||
|
||||
Then create `train.txt` and `val.txt` to split dataset.
|
||||
|
||||
According to TransUnet, the following is the data set division.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
The contents of synapse datasets include:
|
||||
|
||||
```none
|
||||
├── Training
|
||||
│ ├── img
|
||||
│ │ ├── img0001.nii.gz
|
||||
│ │ ├── img0002.nii.gz
|
||||
│ │ ├── ...
|
||||
│ ├── label
|
||||
│ │ ├── label0001.nii.gz
|
||||
│ │ ├── label0002.nii.gz
|
||||
│ │ ├── ...
|
||||
│ ├── train.txt
|
||||
│ ├── val.txt
|
||||
```
|
||||
|
||||
Then, use this command to convert synapse dataset.
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/synapse.py --dataset-path /path/to/synapse
|
||||
```
|
||||
|
||||
Noted that MMSegmentation default evaluation metric (such as mean dice value) is calculated on 2D slice image, which is not comparable to results of 3D scan in some paper such as [TransUNet](https://arxiv.org/abs/2102.04306).
|
||||
|
||||
## REFUGE
|
||||
|
||||
Register in [REFUGE Challenge](https://refuge.grand-challenge.org) and download [REFUGE dataset](https://refuge.grand-challenge.org/REFUGE2Download).
|
||||
|
||||
Then, unzip `REFUGE2.zip` and the contents of original datasets include:
|
||||
|
||||
```none
|
||||
├── REFUGE2
|
||||
│ ├── REFUGE2
|
||||
│ │ ├── Annotation-Training400.zip
|
||||
│ │ ├── REFUGE-Test400.zip
|
||||
│ │ ├── REFUGE-Test-GT.zip
|
||||
│ │ ├── REFUGE-Training400.zip
|
||||
│ │ ├── REFUGE-Validation400.zip
|
||||
│ │ ├── REFUGE-Validation400-GT.zip
|
||||
│ ├── __MACOSX
|
||||
```
|
||||
|
||||
Please run the following command to convert REFUGE dataset:
|
||||
|
||||
```shell
|
||||
python tools/convert_datasets/refuge.py --raw_data_root=/path/to/refuge/REFUGE2/REFUGE2
|
||||
```
|
||||
|
||||
The script will make directory structure below:
|
||||
|
||||
```none
|
||||
│ ├── REFUGE
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
```
|
||||
|
||||
It includes 400 images for training, 400 images for validation and 400 images for testing which is the same as REFUGE 2018 dataset.
|
||||
|
||||
## Mapillary Vistas Datasets
|
||||
|
||||
- The dataset could be download [here](https://www.mapillary.com/dataset/vistas) after registration.
|
||||
|
||||
- Mapillary Vistas Dataset use 8-bit with color-palette to store labels. No conversion operation is required.
|
||||
|
||||
- Assumption you have put the dataset zip file in `mmsegmentation/data/mapillary`
|
||||
|
||||
- Please run the following commands to unzip dataset.
|
||||
|
||||
```bash
|
||||
cd data/mapillary
|
||||
unzip An-ZjB1Zm61yAZG0ozTymz8I8NqI4x0MrYrh26dq7kPgfu8vf9ImrdaOAVOFYbJ2pNAgUnVGBmbue9lTgdBOb5BbKXIpFs0fpYWqACbrQDChAA2fdX0zS9PcHu7fY8c-FOvyBVxPNYNFQuM.zip
|
||||
```
|
||||
|
||||
- After unzip, you will get Mapillary Vistas Dataset like this structure. Semantic segmentation mask labels in `labels` folder.
|
||||
|
||||
```none
|
||||
mmsegmentation
|
||||
├── mmseg
|
||||
├── tools
|
||||
├── configs
|
||||
├── data
|
||||
│ ├── mapillary
|
||||
│ │ ├── training
|
||||
│ │ │ ├── images
|
||||
│ │ │ ├── v1.2
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ └── panoptic
|
||||
│ │ │ ├── v2.0
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ ├── panoptic
|
||||
| │ │ │ └── polygons
|
||||
│ │ ├── validation
|
||||
│ │ │ ├── images
|
||||
| │ │ ├── v1.2
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ └── panoptic
|
||||
│ │ │ ├── v2.0
|
||||
| │ │ │ ├── instances
|
||||
| │ │ │ ├── labels
|
||||
| │ │ │ ├── panoptic
|
||||
| │ │ │ └── polygons
|
||||
```
|
||||
|
||||
- You could set Datasets version with `MapillaryDataset_v1` and `MapillaryDataset_v2` in your configs.
|
||||
View the Mapillary Vistas Datasets config file here [V1.2](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/_base_/datasets/mapillary_v1.py) and [V2.0](https://github.com/open-mmlab/mmsegmentation/blob/main/configs/_base_/datasets/mapillary_v2.py)
|
||||
|
||||
## LEVIR-CD
|
||||
|
||||
[LEVIR-CD](https://justchenhao.github.io/LEVIR/) Large-scale Remote Sensing Change Detection Dataset for Building.
|
||||
|
||||
Download the dataset from [here](https://justchenhao.github.io/LEVIR/).
|
||||
|
||||
The supplement version of the dataset can be requested on the [homepage](https://github.com/S2Looking/Dataset)
|
||||
|
||||
Please download the supplement version of the dataset, then unzip `LEVIR-CD+.zip`, the contents of original datasets include:
|
||||
|
||||
```none
|
||||
│ ├── LEVIR-CD+
|
||||
│ │ ├── train
|
||||
│ │ │ ├── A
|
||||
│ │ │ ├── B
|
||||
│ │ │ ├── label
|
||||
│ │ ├── test
|
||||
│ │ │ ├── A
|
||||
│ │ │ ├── B
|
||||
│ │ │ ├── label
|
||||
```
|
||||
|
||||
For LEVIR-CD dataset, please run the following command to crop images without overlap:
|
||||
|
||||
```shell
|
||||
python tools/dataset_converters/levircd.py --dataset-path /path/to/LEVIR-CD+ --out_dir /path/to/LEVIR-CD
|
||||
```
|
||||
|
||||
The size of cropped image is 256x256, which is consistent with the original paper.
|
||||
|
||||
## BDD100K
|
||||
|
||||
- You could download BDD100k datasets from [here](https://bdd-data.berkeley.edu/) after registration.
|
||||
|
||||
- You can download images and masks by clicking `10K Images` button and `Segmentation` button.
|
||||
|
||||
- After download, unzip by the following instructions:
|
||||
|
||||
```bash
|
||||
unzip ~/bdd100k_images_10k.zip -d ~/mmsegmentation/data/
|
||||
unzip ~/bdd100k_sem_seg_labels_trainval.zip -d ~/mmsegmentation/data/
|
||||
```
|
||||
|
||||
- And get
|
||||
|
||||
```none
|
||||
mmsegmentation
|
||||
├── mmseg
|
||||
├── tools
|
||||
├── configs
|
||||
├── data
|
||||
│ ├── bdd100k
|
||||
│ │ ├── images
|
||||
│ │ │ └── 10k
|
||||
| │ │ │ ├── test
|
||||
| │ │ │ ├── train
|
||||
| │ │ │ └── val
|
||||
│ │ └── labels
|
||||
│ │ │ └── sem_seg
|
||||
| │ │ │ ├── colormaps
|
||||
| │ │ │ │ ├──train
|
||||
| │ │ │ │ └──val
|
||||
| │ │ │ ├── masks
|
||||
| │ │ │ │ ├──train
|
||||
| │ │ │ │ └──val
|
||||
| │ │ │ ├── polygons
|
||||
| │ │ │ │ ├──sem_seg_train.json
|
||||
| │ │ │ │ └──sem_seg_val.json
|
||||
| │ │ │ └── rles
|
||||
| │ │ │ │ ├──sem_seg_train.json
|
||||
| │ │ │ │ └──sem_seg_val.json
|
||||
```
|
||||
|
||||
## NYU
|
||||
|
||||
- To access the NYU dataset, you can download it from [this link](https://drive.google.com/file/d/1wC-io-14RCIL4XTUrQLk6lBqU2AexLVp/view?usp=share_link)
|
||||
|
||||
- Once the download is complete, you can utilize the [tools/dataset_converters/nyu.py](/tools/dataset_converters/nyu.py) script to extract and organize the data into the required format. Run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
python tools/dataset_converters/nyu.py nyu.zip
|
||||
```
|
||||
|
||||
## HSI Drive 2.0
|
||||
|
||||
- You could download HSI Drive 2.0 dataset from [here](https://ipaccess.ehu.eus/HSI-Drive/#download) after just sending an email to gded@ehu.eus with the subject "download HSI-Drive". You will receive a password to uncompress the files.
|
||||
|
||||
- After download, unzip by the following instructions:
|
||||
|
||||
```bash
|
||||
7z x -p"password" ./HSI_Drive_v2_0_Phyton.zip
|
||||
|
||||
mv ./HSIDrive20 path_to_mmsegmentation/data
|
||||
mv ./HSI_Drive_v2_0_release_notes_Python_version.md path_to_mmsegmentation/data
|
||||
mv ./image_numbering.pdf path_to_mmsegmentation/data
|
||||
```
|
||||
|
||||
- After unzip, you get
|
||||
|
||||
```none
|
||||
mmsegmentation
|
||||
├── mmseg
|
||||
├── tools
|
||||
├── configs
|
||||
├── data
|
||||
│ ├── HSIDrive20
|
||||
│ │ ├── images
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── annotations
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── images_MF
|
||||
│ │ │ ├── training
|
||||
│ │ │ ├── validation
|
||||
│ │ │ ├── test
|
||||
│ │ ├── RGB
|
||||
│ │ ├── training_filenames.txt
|
||||
│ │ ├── validation_filenames.txt
|
||||
│ │ ├── test_filenames.txt
|
||||
│ ├── HSI_Drive_v2_0_release_notes_Python_version.md
|
||||
│ ├── image_numbering.pdf
|
||||
```
|
||||
244
Seg_All_In_One_MMSeg/docs/en/user_guides/3_inference.md
Normal file
244
Seg_All_In_One_MMSeg/docs/en/user_guides/3_inference.md
Normal file
@@ -0,0 +1,244 @@
|
||||
# Tutorial 3: Inference with existing models
|
||||
|
||||
MMSegmentation provides pre-trained models for semantic segmentation in [Model Zoo](../model_zoo.md), and supports multiple standard datasets, including Cityscapes, ADE20K, etc.
|
||||
This note will show how to use existing models to inference on given images.
|
||||
As for how to test existing models on standard datasets, please see this [guide](./4_train_test.md)
|
||||
|
||||
MMSegmentation provides several interfaces for users to easily use pre-trained models for inference.
|
||||
|
||||
- [Tutorial 3: Inference with existing models](#tutorial-3-inference-with-existing-models)
|
||||
- [Inferencer](#inferencer)
|
||||
- [Basic Usage](#basic-usage)
|
||||
- [Initialization](#initialization)
|
||||
- [Visualize prediction](#visualize-prediction)
|
||||
- [List model](#list-model)
|
||||
- [Inference API](#inference-api)
|
||||
- [mmseg.apis.init_model](#mmsegapisinit_model)
|
||||
- [mmseg.apis.inference_model](#mmsegapisinference_model)
|
||||
- [mmseg.apis.show_result_pyplot](#mmsegapisshow_result_pyplot)
|
||||
|
||||
## Inferencer
|
||||
|
||||
We provide the most **convenient** way to use the model in MMSegmentation `MMSegInferencer`. You can get segmentation mask for an image with only 3 lines of code.
|
||||
|
||||
### Basic Usage
|
||||
|
||||
The following example shows how to use `MMSegInferencer` to perform inference on a single image.
|
||||
|
||||
```
|
||||
>>> from mmseg.apis import MMSegInferencer
|
||||
>>> # Load models into memory
|
||||
>>> inferencer = MMSegInferencer(model='deeplabv3plus_r18-d8_4xb2-80k_cityscapes-512x1024')
|
||||
>>> # Inference
|
||||
>>> inferencer('demo/demo.png', show=True)
|
||||
```
|
||||
|
||||
The visualization result should look like:
|
||||
|
||||
<div align="center">
|
||||
<img src='https://user-images.githubusercontent.com/76149310/221507927-ae01e3a7-016f-4425-b966-7b19cbbe494e.png' />
|
||||
</div>
|
||||
|
||||
Moreover, you can use `MMSegInferencer` to process a list of images:
|
||||
|
||||
```
|
||||
# Input a list of images
|
||||
>>> images = [image1, image2, ...] # image1 can be a file path or a np.ndarray
|
||||
>>> inferencer(images, show=True, wait_time=0.5) # wait_time is delay time, and 0 means forever
|
||||
|
||||
# Or input image directory
|
||||
>>> images = $IMAGESDIR
|
||||
>>> inferencer(images, show=True, wait_time=0.5)
|
||||
|
||||
# Save visualized rendering color maps and predicted results
|
||||
# out_dir is the directory to save the output results, img_out_dir and pred_out_dir are subdirectories of out_dir
|
||||
# to save visualized rendering color maps and predicted results
|
||||
>>> inferencer(images, out_dir='outputs', img_out_dir='vis', pred_out_dir='pred')
|
||||
```
|
||||
|
||||
There is a optional parameter of inferencer, `return_datasamples`, whose default value is False, and return value of inferencer is a `dict` type by default, including 2 keys 'visualization' and 'predictions'.
|
||||
If `return_datasamples=True` inferencer will return [`SegDataSample`](../advanced_guides/structures.md), or list of it.
|
||||
|
||||
```
|
||||
result = inferencer('demo/demo.png')
|
||||
# result is a `dict` including 2 keys 'visualization' and 'predictions'
|
||||
# 'visualization' includes color segmentation map
|
||||
print(result['visualization'].shape)
|
||||
# (512, 683, 3)
|
||||
|
||||
# 'predictions' includes segmentation mask with label indice
|
||||
print(result['predictions'].shape)
|
||||
# (512, 683)
|
||||
|
||||
result = inferencer('demo/demo.png', return_datasamples=True)
|
||||
print(type(result))
|
||||
# <class 'mmseg.structures.seg_data_sample.SegDataSample'>
|
||||
|
||||
# Input a list of images
|
||||
results = inferencer(images)
|
||||
# The output is list
|
||||
print(type(results['visualization']), results['visualization'][0].shape)
|
||||
# <class 'list'> (512, 683, 3)
|
||||
print(type(results['predictions']), results['predictions'][0].shape)
|
||||
# <class 'list'> (512, 683)
|
||||
|
||||
results = inferencer(images, return_datasamples=True)
|
||||
# <class 'list'>
|
||||
print(type(results[0]))
|
||||
# <class 'mmseg.structures.seg_data_sample.SegDataSample'>
|
||||
```
|
||||
|
||||
### Initialization
|
||||
|
||||
`MMSegInferencer` must be initialized from a `model`, which can be a model name or a `Config` even a path of config file.
|
||||
The model names can be found in models' metafile (configs/xxx/metafile.yaml), like one model name of maskformer is `maskformer_r50-d32_8xb2-160k_ade20k-512x512`, and if input model name and the weights of the model will be download automatically. Below are other input parameters:
|
||||
|
||||
- weights (str, optional) - Path to the checkpoint. If it is not specified and model is a model name of metafile, the weights will be loaded from metafile. Defaults to None.
|
||||
- classes (list, optional) - Input classes for result rendering, as the prediction of segmentation model is a segment map with label indices, `classes` is a list which includes items responding to the label indices. If classes is not defined, visualizer will take `cityscapes` classes by default. Defaults to None.
|
||||
- palette (list, optional) - Input palette for result rendering, which is a list of colors responding to the classes. If the palette is not defined, the visualizer will take the palette of `cityscapes` by default. Defaults to None.
|
||||
- dataset_name (str, optional) - [Dataset name or alias](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/utils/class_names.py#L302-L317), visualizer will use the meta information of the dataset i.e. classes and palette, but the `classes` and `palette` have higher priority. Defaults to None.
|
||||
- device (str, optional) - Device to run inference. If None, the available device will be automatically used. Defaults to None.
|
||||
- scope (str, optional) - The scope of the model. Defaults to 'mmseg'.
|
||||
|
||||
### Visualize prediction
|
||||
|
||||
`MMSegInferencer` supports 4 parameters for visualize prediction, you can use them when call initialized inferencer:
|
||||
|
||||
- show (bool) - Whether to display the image in a popup window. Defaults to False.
|
||||
- wait_time (float) - The interval of show (s). Defaults to 0.
|
||||
- img_out_dir (str) - Subdirectory of `out_dir`, used to save rendering color segmentation mask, so `out_dir` must be defined if you would like to save predicted mask. Defaults to 'vis'.
|
||||
- opacity (int, float) - The transparency of segmentation mask. Defaults to 0.8.
|
||||
|
||||
The examples of these parameters is in [Basic Usage](#basic-usage)
|
||||
|
||||
### List model
|
||||
|
||||
There is a very easy to list all model names in MMSegmentation
|
||||
|
||||
```
|
||||
>>> from mmseg.apis import MMSegInferencer
|
||||
# models is a list of model names, and them will print automatically
|
||||
>>> models = MMSegInferencer.list_models('mmseg')
|
||||
```
|
||||
|
||||
## Inference API
|
||||
|
||||
### mmseg.apis.init_model
|
||||
|
||||
Initialize a segmentor from config file.
|
||||
|
||||
Parameters:
|
||||
|
||||
- config (str, `Path`, or `mmengine.Config`) - Config file path or the config object.
|
||||
- checkpoint (str, optional) - Checkpoint path. If left as None, the model will not load any weights.
|
||||
- device (str, optional) - CPU/CUDA device option. Default 'cuda:0'.
|
||||
- cfg_options (dict, optional) - Options to override some settings in the used config.
|
||||
|
||||
Returns:
|
||||
|
||||
- nn.Module: The constructed segmentor.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
from mmseg.apis import init_model
|
||||
|
||||
config_path = 'configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
checkpoint_path = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
|
||||
# initialize model without checkpoint
|
||||
model = init_model(config_path)
|
||||
|
||||
# init model and load checkpoint
|
||||
model = init_model(config_path, checkpoint_path)
|
||||
|
||||
# init model and load checkpoint on CPU
|
||||
model = init_model(config_path, checkpoint_path, 'cpu')
|
||||
```
|
||||
|
||||
### mmseg.apis.inference_model
|
||||
|
||||
Inference image(s) with the segmentor.
|
||||
|
||||
Parameters:
|
||||
|
||||
- model (nn.Module) - The loaded segmentor
|
||||
- imgs (str, np.ndarray, or list\[str/np.ndarray\]) - Either image files or loaded images
|
||||
|
||||
Returns:
|
||||
|
||||
- `SegDataSample` or list\[`SegDataSample`\]: If imgs is a list or tuple, the same length list type results will be returned, otherwise return the segmentation results directly.
|
||||
|
||||
**Note:** [SegDataSample](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/structures/seg_data_sample.py) is a data structure interface of MMSegmentation, it is used as interfaces between different components. `SegDataSample` implement the abstract data element `mmengine.structures.BaseDataElement`, please refer to data element [documentation](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/data_element.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
The attributes in `SegDataSample` are divided into several parts:
|
||||
|
||||
- `gt_sem_seg` (`PixelData`) - Ground truth of semantic segmentation.
|
||||
- `pred_sem_seg` (`PixelData`) - Prediction of semantic segmentation.
|
||||
- `seg_logits` (`PixelData`) - Predicted logits of semantic segmentation.
|
||||
|
||||
**Note** [PixelData](https://github.com/open-mmlab/mmengine/blob/main/mmengine/structures/pixel_data.py) is the data structure for pixel-level annotations or predictions, please refer to PixelData [documentation](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/data_element.html) in [MMEngine](https://github.com/open-mmlab/mmengine) for more information.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
from mmseg.apis import init_model, inference_model
|
||||
|
||||
config_path = 'configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
checkpoint_path = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
img_path = 'demo/demo.png'
|
||||
|
||||
|
||||
model = init_model(config_path, checkpoint_path)
|
||||
result = inference_model(model, img_path)
|
||||
```
|
||||
|
||||
### mmseg.apis.show_result_pyplot
|
||||
|
||||
Visualize the segmentation results on the image.
|
||||
|
||||
Parameters:
|
||||
|
||||
- model (nn.Module) - The loaded segmentor.
|
||||
- img (str or np.ndarray) - Image filename or loaded image.
|
||||
- result (`SegDataSample`) - The prediction SegDataSample result.
|
||||
- opacity (float) - Opacity of painted segmentation map. Default `0.5`, must be in `(0, 1]` range.
|
||||
- title (str) - The title of pyplot figure. Default is ''.
|
||||
- draw_gt (bool) - Whether to draw GT SegDataSample. Default to `True`.
|
||||
- draw_pred (draws_pred) - Whether to draw Prediction SegDataSample. Default to `True`.
|
||||
- wait_time (float) - The interval of show (s), 0 is the special value that means "forever". Default to `0`.
|
||||
- show (bool) - Whether to display the drawn image. Default to `True`.
|
||||
- save_dir (str, optional) - Save file dir for all storage backends. If it is `None`, the backend storage will not save any data.
|
||||
- out_file (str, optional) - Path to output file. Default to `None`.
|
||||
|
||||
Returns:
|
||||
|
||||
- np.ndarray: the drawn image which channel is RGB.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
from mmseg.apis import init_model, inference_model, show_result_pyplot
|
||||
|
||||
config_path = 'configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py'
|
||||
checkpoint_path = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||
img_path = 'demo/demo.png'
|
||||
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_model(config_path, checkpoint_path, device='cuda:0')
|
||||
|
||||
# inference on given image
|
||||
result = inference_model(model, img_path)
|
||||
|
||||
# display the segmentation result
|
||||
vis_image = show_result_pyplot(model, img_path, result)
|
||||
|
||||
# save the visualization result, the output image would be found at the path `work_dirs/result.png`
|
||||
vis_iamge = show_result_pyplot(model, img_path, result, out_file='work_dirs/result.png')
|
||||
|
||||
# Modify the time of displaying images, note that 0 is the special value that means "forever"
|
||||
vis_image = show_result_pyplot(model, img_path, result, wait_time=5)
|
||||
```
|
||||
|
||||
**Note:** If your current device doesn't have graphical user interface, it is recommended that setting `show` to `False` and specify the `out_file` or `save_dir` to save the results. If you would like to display the result on a window, no special settings are required.
|
||||
315
Seg_All_In_One_MMSeg/docs/en/user_guides/4_train_test.md
Normal file
315
Seg_All_In_One_MMSeg/docs/en/user_guides/4_train_test.md
Normal file
@@ -0,0 +1,315 @@
|
||||
# Tutorial 4: Train and test with existing models
|
||||
|
||||
MMSegmentation supports training and testing models on a variety of devices, which are described below for single-GPU, distributed, and cluster training and testing, respectively. Through this tutorial, you will learn how to train and test using the scripts provided by MMSegmentation.
|
||||
|
||||
## Training and testing on a single GPU
|
||||
|
||||
### Training on a single GPU
|
||||
|
||||
We provide `tools/train.py` to launch training jobs on a single GPU.
|
||||
The basic usage is as follows.
|
||||
|
||||
```shell
|
||||
python tools/train.py ${CONFIG_FILE} [optional arguments]
|
||||
```
|
||||
|
||||
This tool accepts several optional arguments, including:
|
||||
|
||||
- `--work-dir ${WORK_DIR}`: Override the working directory.
|
||||
- `--amp`: Use auto mixed precision training.
|
||||
- `--resume`: Resume from the latest checkpoint in the work_dir automatically.
|
||||
- `--cfg-options ${OVERRIDE_CONFIGS}`: Override some settings in the used config, and the key-value pair in xxx=yyy format will be merged into the config file.
|
||||
For example, '--cfg-option model.encoder.in_channels=6'. Please see this [guide](./1_config.md#Modify-config-through-script-arguments) for more details.
|
||||
|
||||
Below are the optional arguments for the multi-gpu test:
|
||||
|
||||
- `--launcher`: Items for distributed job initialization launcher. Allowed choices are `none`, `pytorch`, `slurm`, `mpi`. Especially, if set to none, it will test in a non-distributed mode.
|
||||
- `--local_rank`: ID for local rank. If not specified, it will be set to 0.
|
||||
|
||||
**Note:** Difference between the argument `--resume` and the field `load_from` in the config file:
|
||||
|
||||
`--resume` only determines whether to resume from the latest checkpoint in the work_dir. It is usually used for resuming the training process that is interrupted accidentally.
|
||||
|
||||
`load_from` will specify the checkpoint to be loaded and the training iteration starts from 0. It is usually used for fine-tuning.
|
||||
|
||||
If you would like to resume training from a specific checkpoint, you can use:
|
||||
|
||||
```python
|
||||
python tools/train.py ${CONFIG_FILE} --resume --cfg-options load_from=${CHECKPOINT}
|
||||
```
|
||||
|
||||
**Training on CPU**: The process of training on the CPU is consistent with single GPU training if a machine does not have GPU. If it has GPUs but not wanting to use them, we just need to disable GPUs before the training process.
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=-1
|
||||
```
|
||||
|
||||
And then run the script [above](#training-on-a-single-gpu).
|
||||
|
||||
### Testing on a single GPU
|
||||
|
||||
We provide `tools/test.py` to launch training jobs on a single GPU.
|
||||
The basic usage is as follows.
|
||||
|
||||
```shell
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [optional arguments]
|
||||
```
|
||||
|
||||
This tool accepts several optional arguments, including:
|
||||
|
||||
- `--work-dir`: If specified, results will be saved in this directory. If not specified, the results will be automatically saved to `work_dirs/{CONFIG_NAME}`.
|
||||
- `--show`: Show prediction results at runtime, available when `--show-dir` is not specified.
|
||||
- `--show-dir`: Directory where painted images will be saved. If specified, the visualized segmentation mask will be saved to the `work_dir/timestamp/show_dir`.
|
||||
- `--wait-time`: The interval of show (s), which takes effect when `--show` is activated. Default to 2.
|
||||
- `--cfg-options`: If specified, the key-value pair in xxx=yyy format will be merged into the config file.
|
||||
- `--tta`: Test time augmentation option.
|
||||
|
||||
**Testing on CPU**: The process of testing on the CPU is consistent with single GPU testing if a machine does not have GPU. If it has GPUs but not wanting to use them, we just need to disable GPUs before the training process.
|
||||
|
||||
```shell
|
||||
export CUDA_VISIBLE_DEVICES=-1
|
||||
```
|
||||
|
||||
then run the script [above](#testing-on-a-single-gpu).
|
||||
|
||||
## Training and testing on multiple GPUs and multiple machines
|
||||
|
||||
### Training on multiple GPUs
|
||||
|
||||
OpenMMLab2.0 implements **distributed** training with `MMDistributedDataParallel`.
|
||||
We provide `tools/dist_train.sh` to launch training on multiple GPUs.
|
||||
|
||||
The basic usage is as follows:
|
||||
|
||||
```shell
|
||||
sh tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [optional arguments]
|
||||
```
|
||||
|
||||
Optional arguments remain the same as stated [above](#training-on-a-single-gpu) and have additional arguments to specify the number of GPUs.
|
||||
|
||||
An example:
|
||||
|
||||
```shell
|
||||
# checkpoints and logs saved in WORK_DIR=work_dirs/pspnet_r50-d8_4xb4-80k_ade20k-512x512/
|
||||
# If work_dir is not set, it will be generated automatically.
|
||||
sh tools/dist_train.sh configs/pspnet/pspnet_r50-d8_4xb4-80k_ade20k-512x512.py 8 --work-dir work_dirs/pspnet_r50-d8_4xb4-80k_ade20k-512x512
|
||||
```
|
||||
|
||||
**Note**: During training, checkpoints and logs are saved in the same folder structure as the config file under `work_dirs/`. A custom work directory is not recommended since evaluation scripts infer work directories from the config file name. If you want to save your weights somewhere else, please use a symlink, for example:
|
||||
|
||||
```shell
|
||||
ln -s ${YOUR_WORK_DIRS} ${MMSEG}/work_dirs
|
||||
```
|
||||
|
||||
### Testing on multiple GPUs
|
||||
|
||||
We provide `tools/dist_test.sh` to launch testing on multiple GPUs.
|
||||
The basic usage is as follows.
|
||||
|
||||
```shell
|
||||
sh tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [optional arguments]
|
||||
```
|
||||
|
||||
Optional arguments remain the same as stated [above](#testing-on-a-single-gpu) and have additional arguments to specify the number of GPUs.
|
||||
|
||||
An example:
|
||||
|
||||
```shell
|
||||
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py \
|
||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth 4
|
||||
```
|
||||
|
||||
### Launch multiple jobs on a single machine
|
||||
|
||||
If you launch multiple jobs on a single machine, e.g., 2 jobs of 4-GPU training on a machine with 8 GPUs, you need to specify different ports (29500 by default) for each job to avoid communication conflict. Otherwise, there will be an error message saying `RuntimeError: Address already in use`.
|
||||
If you use `dist_train.sh` to launch training jobs, you can set the port in commands with the environment variable `PORT`.
|
||||
|
||||
```shell
|
||||
CUDA_VISIBLE_DEVICES=0,1,2,3 PORT=29500 sh tools/dist_train.sh ${CONFIG_FILE} 4
|
||||
CUDA_VISIBLE_DEVICES=4,5,6,7 PORT=29501 sh tools/dist_train.sh ${CONFIG_FILE} 4
|
||||
```
|
||||
|
||||
### Training with multiple machines
|
||||
|
||||
MMSegmentation relies on `torch.distributed` package for distributed training.
|
||||
Thus, as a basic usage, one can launch distributed training via PyTorch's [launch utility](https://pytorch.org/docs/stable/distributed.html#launch-utility).
|
||||
|
||||
If you launch with multiple machines simply connected with ethernet, you can simply run the following commands:
|
||||
On the first machine:
|
||||
|
||||
```shell
|
||||
NNODES=2 NODE_RANK=0 PORT=${MASTER_PORT} MASTER_ADDR=${MASTER_ADDR} sh tools/dist_train.sh ${CONFIG_FILE} ${GPUS}
|
||||
```
|
||||
|
||||
On the second machine:
|
||||
|
||||
```shell
|
||||
NNODES=2 NODE_RANK=1 PORT=${MASTER_PORT} MASTER_ADDR=${MASTER_ADDR} sh tools/dist_train.sh ${CONFIG_FILE} ${GPUS}
|
||||
```
|
||||
|
||||
Usually, it is slow if you do not have high-speed networking like InfiniBand.
|
||||
|
||||
## Manage jobs with Slurm
|
||||
|
||||
[Slurm](https://slurm.schedmd.com/) is a good job scheduling system for computing clusters.
|
||||
|
||||
### Training on a cluster with Slurm
|
||||
|
||||
On a cluster managed by Slurm, you can use `slurm_train.sh` to spawn training jobs. It supports both single-node and multi-node training.
|
||||
|
||||
The basic usage is as follows:
|
||||
|
||||
```shell
|
||||
[GPUS=${GPUS}] sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} [optional arguments]
|
||||
```
|
||||
|
||||
Below is an example of using 4 GPUs to train PSPNet on a Slurm partition named _dev_, and set the work-dir to some shared file systems.
|
||||
|
||||
```shell
|
||||
GPUS=4 sh tools/slurm_train.sh dev pspnet configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py --work-dir work_dir/pspnet
|
||||
```
|
||||
|
||||
You can check [the source code](../../../tools/slurm_train.sh) to review full arguments and environment variables.
|
||||
|
||||
### Testing on a cluster with Slurm
|
||||
|
||||
Similar to the training task, MMSegmentation provides `slurm_test.sh` to launch testing jobs.
|
||||
|
||||
The basic usage is as follows:
|
||||
|
||||
```shell
|
||||
[GPUS=${GPUS}] sh tools/slurm_test.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} ${CHECKPOINT_FILE} [optional arguments]
|
||||
```
|
||||
|
||||
You can check [the source code](../../../tools/slurm_test.sh) to review full arguments and environment variables.
|
||||
|
||||
**Note:** When using Slurm, the port option needs to be set in one of the following ways:
|
||||
|
||||
1. Set the port through `--cfg-options`. This is more recommended since it does not change the original configs.
|
||||
|
||||
```shell
|
||||
GPUS=4 GPUS_PER_NODE=4 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR} --cfg-options env_cfg.dist_cfg.port=29500
|
||||
GPUS=4 GPUS_PER_NODE=4 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR} --cfg-options env_cfg.dist_cfg.port=29501
|
||||
```
|
||||
|
||||
2. Modify the config files to set different communication ports.
|
||||
In `config1.py`:
|
||||
|
||||
```python
|
||||
enf_cfg = dict(dist_cfg=dict(backend='nccl', port=29500))
|
||||
```
|
||||
|
||||
In `config2.py`:
|
||||
|
||||
```python
|
||||
enf_cfg = dict(dist_cfg=dict(backend='nccl', port=29501))
|
||||
```
|
||||
|
||||
Then you can launch two jobs with config1.py and config2.py.
|
||||
|
||||
```shell
|
||||
CUDA_VISIBLE_DEVICES=0,1,2,3 GPUS=4 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR}
|
||||
CUDA_VISIBLE_DEVICES=4,5,6,7 GPUS=4 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR}
|
||||
```
|
||||
|
||||
3. Set the port in the command using the environment variable 'MASTER_PORT':
|
||||
|
||||
```shell
|
||||
CUDA_VISIBLE_DEVICES=0,1,2,3 GPUS=4 MASTER_PORT=29500 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR}
|
||||
CUDA_VISIBLE_DEVICES=4,5,6,7 GPUS=4 MASTER_PORT=29501 sh tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR}
|
||||
```
|
||||
|
||||
## Testing and saving segment files
|
||||
|
||||
### Basic Usage
|
||||
|
||||
When you want to save the results, you can use `--out` to specify the output directory.
|
||||
|
||||
```shell
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} --out ${OUTPUT_DIR}
|
||||
```
|
||||
|
||||
Here is an example to save the predicted results from model `fcn_r50-d8_4xb4-80k_ade20k-512x512` on ADE20k validatation dataset.
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/fcn/fcn_r50-d8_4xb4-80k_ade20k-512x512.py ckpt/fcn_r50-d8_512x512_80k_ade20k_20200614_144016-f8ac5082.pth --out work_dirs/format_results
|
||||
```
|
||||
|
||||
You also can modify the config file to define `output_dir`. We also take
|
||||
`fcn_r50-d8_4xb4-80k_ade20k-512x512` as example just add
|
||||
`test_evaluator` in `configs/fcn/fcn_r50-d8_4xb4-80k_ade20k-512x512.py`
|
||||
|
||||
```python
|
||||
test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'], output_dir='work_dirs/format_results')
|
||||
```
|
||||
|
||||
then run command without `--out`:
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/fcn/fcn_r50-d8_4xb4-80k_ade20k-512x512.py ckpt/fcn_r50-d8_512x512_80k_ade20k_20200614_144016-f8ac5082.pth
|
||||
```
|
||||
|
||||
If you would like to only save the predicted results without evaluation as annotation is not released by the official dataset, you can set `format_only=True` and modify `test_dataloader`.
|
||||
As there is no annotation in dataset, we remove `dict(type='LoadAnnotations')` from `test_dataloader` Here is the example configuration:
|
||||
|
||||
```python
|
||||
test_evaluator = dict(
|
||||
type='IoUMetric',
|
||||
iou_metrics=['mIoU'],
|
||||
format_only=True,
|
||||
output_dir='work_dirs/format_results')
|
||||
test_dataloader = dict(
|
||||
batch_size=1,
|
||||
num_workers=4,
|
||||
persistent_workers=True,
|
||||
sampler=dict(type='DefaultSampler', shuffle=False),
|
||||
dataset=dict(
|
||||
type = 'ADE20KDataset'
|
||||
data_root='data/ade/release_test',
|
||||
data_prefix=dict(img_path='testing'),
|
||||
# we don't load annotation in test transform pipeline.
|
||||
pipeline=[
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='Resize', scale=(2048, 512), keep_ratio=True),
|
||||
dict(type='PackSegInputs')
|
||||
]))
|
||||
```
|
||||
|
||||
then run test command:
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/fcn/fcn_r50-d8_4xb4-80k_ade20k-512x512.py ckpt/fcn_r50-d8_512x512_80k_ade20k_20200614_144016-f8ac5082.pth
|
||||
```
|
||||
|
||||
### Testing Cityscape dataset and save predicted segment files
|
||||
|
||||
We recommend `CityscapesMetric` which is the wrapper of Cityscapes'sdk, when you want to
|
||||
save the predicted results of Cityscape test dataset to submit them in [Cityscape test server](https://www.cityscapes-dataset.com/submit/). Here is the example configuration:
|
||||
|
||||
```python
|
||||
test_evaluator = dict(
|
||||
type='CityscapesMetric',
|
||||
format_only=True,
|
||||
keep_results=True,
|
||||
output_dir='work_dirs/format_results')
|
||||
test_dataloader = dict(
|
||||
batch_size=1,
|
||||
num_workers=4,
|
||||
persistent_workers=True,
|
||||
sampler=dict(type='DefaultSampler', shuffle=False),
|
||||
dataset=dict(
|
||||
type='CityscapesDataset',
|
||||
data_root='data/cityscapes/',
|
||||
data_prefix=dict(img_path='leftImg8bit/test'),
|
||||
pipeline=[
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='Resize', scale=(2048, 1024), keep_ratio=True),
|
||||
dict(type='PackSegInputs')
|
||||
]))
|
||||
```
|
||||
|
||||
then run test command, for example:
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/fcn/fcn_r18-d8_4xb2-80k_cityscapes-512x1024.py ckpt/fcn_r18-d8_512x1024_80k_cityscapes_20201225_021327-6c50f8b4.pth
|
||||
```
|
||||
255
Seg_All_In_One_MMSeg/docs/en/user_guides/5_deployment.md
Normal file
255
Seg_All_In_One_MMSeg/docs/en/user_guides/5_deployment.md
Normal file
@@ -0,0 +1,255 @@
|
||||
# Tutorial 5: Model Deployment
|
||||
|
||||
# MMSegmentation Model Deployment
|
||||
|
||||
- [Tutorial 5: Model Deployment](#tutorial-5-model-deployment)
|
||||
- [MMSegmentation Model Deployment](#mmsegmentation-model-deployment)
|
||||
- [Installation](#installation)
|
||||
- [Install mmseg](#install-mmseg)
|
||||
- [Install mmdeploy](#install-mmdeploy)
|
||||
- [Convert model](#convert-model)
|
||||
- [Model specification](#model-specification)
|
||||
- [Model inference](#model-inference)
|
||||
- [Backend model inference](#backend-model-inference)
|
||||
- [SDK model inference](#sdk-model-inference)
|
||||
- [Supported models](#supported-models)
|
||||
- [Note](#note)
|
||||
|
||||
______________________________________________________________________
|
||||
|
||||
[MMSegmentation](https://github.com/open-mmlab/mmsegmentation/tree/main), also known as `mmseg`, is an open source semantic segmentation toolbox based on Pytorch. It's a part of the [OpenMMLab](<(https://openmmlab.com/)>) object.
|
||||
|
||||
## Installation
|
||||
|
||||
### Install mmseg
|
||||
|
||||
Please follow the [Installation Guide](https://mmsegmentation.readthedocs.io/en/latest/get_started.html).
|
||||
|
||||
### Install mmdeploy
|
||||
|
||||
`mmdeploy` can be installed as follows:
|
||||
|
||||
**Option 1:** Install precompiled package
|
||||
|
||||
Please follow the [Installation overview](https://mmdeploy.readthedocs.io/zh_CN/latest/get_started.html#mmdeploy)
|
||||
|
||||
**Option 2:** Automatic Installation script
|
||||
|
||||
If the deployment platform is **Ubuntu 18.04 +**, please follow the [scription installation](../01-how-to-build/build_from_script.md) to install.
|
||||
For example, the following commands describe how to install mmdeploy and inference engine-`ONNX Runtime`.
|
||||
|
||||
```shell
|
||||
git clone --recursive -b main https://github.com/open-mmlab/mmdeploy.git
|
||||
cd mmdeploy
|
||||
python3 tools/scripts/build_ubuntu_x64_ort.py $(nproc)
|
||||
export PYTHONPATH=$(pwd)/build/lib:$PYTHONPATH
|
||||
export LD_LIBRARY_PATH=$(pwd)/../mmdeploy-dep/onnxruntime-linux-x64-1.8.1/lib/:$LD_LIBRARY_PATH
|
||||
```
|
||||
|
||||
**NOTE**:
|
||||
|
||||
- Add `$(pwd)/build/lib` to `PYTHONPATH`, can loading mmdeploy SDK python package `mmdeploy_runtime`. See [SDK model inference](#SDK-model-inference) for more information.
|
||||
- With [ONNX Runtime model inference](#Backend-model-inference), need to load custom operator library and add ONNX Runtime Library's PATH to `LD_LIBRARY_PATH`.
|
||||
|
||||
**Option 3:** Install with mim
|
||||
|
||||
1. Use mim to install mmcv
|
||||
|
||||
```shell
|
||||
pip install -U openmim
|
||||
mim install "mmcv>=2.0.0rc2"
|
||||
```
|
||||
|
||||
2. Install mmdeploy
|
||||
|
||||
```shell
|
||||
git clone https://github.com/open-mmlab/mmdeploy.git
|
||||
cd mmdeploy
|
||||
mim install -e .
|
||||
```
|
||||
|
||||
**Option 4:** Build MMDeploy from source
|
||||
|
||||
If the first three methods aren't suitable, please [Build MMDeploy from source](<(../01-how-to-build/build_from_source.md)>)
|
||||
|
||||
## Convert model
|
||||
|
||||
[tools/deploy.py](https://github.com/open-mmlab/mmdeploy/tree/main/tools/deploy.py) can convert mmseg Model to backend model conveniently. See [this](https://github.com/open-mmlab/mmdeploy/tree/main/docs/en/02-how-to-run/convert_model.md#usage) for detailed information.
|
||||
|
||||
Then convert `unet` to onnx model as follows:
|
||||
|
||||
```shell
|
||||
cd mmdeploy
|
||||
|
||||
# download unet model from mmseg model zoo
|
||||
mim download mmsegmentation --config unet-s5-d16_fcn_4xb4-160k_cityscapes-512x1024 --dest .
|
||||
|
||||
# convert mmseg model to onnxruntime model with dynamic shape
|
||||
python tools/deploy.py \
|
||||
configs/mmseg/segmentation_onnxruntime_dynamic.py \
|
||||
unet-s5-d16_fcn_4xb4-160k_cityscapes-512x1024.py \
|
||||
fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes_20211210_145204-6860854e.pth \
|
||||
demo/resources/cityscapes.png \
|
||||
--work-dir mmdeploy_models/mmseg/ort \
|
||||
--device cpu \
|
||||
--show \
|
||||
--dump-info
|
||||
```
|
||||
|
||||
It is crucial to specify the correct deployment config during model conversion. MMDeploy has already provided builtin deployment config [files](https://github.com/open-mmlab/mmdeploy/tree/main/configs/mmseg) of all supported backends for mmsegmentation, under which the config file path follows the pattern:
|
||||
|
||||
```
|
||||
segmentation_{backend}-{precision}_{static | dynamic}_{shape}.py
|
||||
```
|
||||
|
||||
- **{backend}:** inference backend, such as onnxruntime, tensorrt, pplnn, ncnn, openvino, coreml etc.
|
||||
- **{precision}:** fp16, int8. When it's empty, it means fp32
|
||||
- **{static | dynamic}:** static shape or dynamic shape
|
||||
- **{shape}:** input shape or shape range of a model
|
||||
|
||||
Therefore, in the above example, you can also convert `unet` to tensorrt-fp16 model by `segmentation_tensorrt-fp16_dynamic-512x1024-2048x2048.py`.
|
||||
|
||||
```{tip}
|
||||
When converting mmsegmentation models to tensorrt models, --device should be set to "cuda"
|
||||
```
|
||||
|
||||
## Model specification
|
||||
|
||||
Before moving on to model inference chapter, let's know more about the converted model structure which is very important for model inference.
|
||||
|
||||
The converted model locates in the working directory like `mmdeploy_models/mmseg/ort` in the previous example. It includes:
|
||||
|
||||
```
|
||||
mmdeploy_models/mmseg/ort
|
||||
├── deploy.json
|
||||
├── detail.json
|
||||
├── end2end.onnx
|
||||
└── pipeline.json
|
||||
```
|
||||
|
||||
in which,
|
||||
|
||||
- **end2end.onnx**: backend model which can be inferred by ONNX Runtime
|
||||
- ***xxx*.json**: the necessary information for mmdeploy SDK
|
||||
|
||||
The whole package **mmdeploy_models/mmseg/ort** is defined as **mmdeploy SDK model**, i.e., **mmdeploy SDK model** includes both backend model and inference meta information.
|
||||
|
||||
## Model inference
|
||||
|
||||
### Backend model inference
|
||||
|
||||
Take the previous converted `end2end.onnx` model as an example, you can use the following code to inference the model and visualize the results:
|
||||
|
||||
```python
|
||||
from mmdeploy.apis.utils import build_task_processor
|
||||
from mmdeploy.utils import get_input_shape, load_config
|
||||
import torch
|
||||
|
||||
deploy_cfg = 'configs/mmseg/segmentation_onnxruntime_dynamic.py'
|
||||
model_cfg = './unet-s5-d16_fcn_4xb4-160k_cityscapes-512x1024.py'
|
||||
device = 'cpu'
|
||||
backend_model = ['./mmdeploy_models/mmseg/ort/end2end.onnx']
|
||||
image = './demo/resources/cityscapes.png'
|
||||
|
||||
# read deploy_cfg and model_cfg
|
||||
deploy_cfg, model_cfg = load_config(deploy_cfg, model_cfg)
|
||||
|
||||
# build task and backend model
|
||||
task_processor = build_task_processor(model_cfg, deploy_cfg, device)
|
||||
model = task_processor.build_backend_model(backend_model)
|
||||
|
||||
# process input image
|
||||
input_shape = get_input_shape(deploy_cfg)
|
||||
model_inputs, _ = task_processor.create_input(image, input_shape)
|
||||
|
||||
# do model inference
|
||||
with torch.no_grad():
|
||||
result = model.test_step(model_inputs)
|
||||
|
||||
# visualize results
|
||||
task_processor.visualize(
|
||||
image=image,
|
||||
model=model,
|
||||
result=result[0],
|
||||
window_name='visualize',
|
||||
output_file='./output_segmentation.png')
|
||||
```
|
||||
|
||||
### SDK model inference
|
||||
|
||||
You can also perform SDK model inference like following:
|
||||
|
||||
```python
|
||||
from mmdeploy_runtime import Segmentor
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread('./demo/resources/cityscapes.png')
|
||||
|
||||
# create a classifier
|
||||
segmentor = Segmentor(model_path='./mmdeploy_models/mmseg/ort', device_name='cpu', device_id=0)
|
||||
# perform inference
|
||||
seg = segmentor(img)
|
||||
|
||||
# visualize inference result
|
||||
## random a palette with size 256x3
|
||||
palette = np.random.randint(0, 256, size=(256, 3))
|
||||
color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
|
||||
for label, color in enumerate(palette):
|
||||
color_seg[seg == label, :] = color
|
||||
# convert to BGR
|
||||
color_seg = color_seg[..., ::-1]
|
||||
img = img * 0.5 + color_seg * 0.5
|
||||
img = img.astype(np.uint8)
|
||||
cv2.imwrite('output_segmentation.png', img)
|
||||
```
|
||||
|
||||
Besides python API, mmdeploy SDK also provides other FFI (Foreign Function Interface), such as C, C++, C#, Java and so on. You can learn their usage from [demo](https://github.com/open-mmlab/mmdeploy/tree/main/demo)
|
||||
|
||||
## Supported models
|
||||
|
||||
| Model | TorchScript | OnnxRuntime | TensorRT | ncnn | PPLNN | OpenVino |
|
||||
| :-------------------------------------------------------------------------------------------------------- | :---------: | :---------: | :------: | :--: | :---: | :------: |
|
||||
| [FCN](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/fcn) | Y | Y | Y | Y | Y | Y |
|
||||
| [PSPNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/pspnet)[\*](#static_shape) | Y | Y | Y | Y | Y | Y |
|
||||
| [DeepLabV3](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/deeplabv3) | Y | Y | Y | Y | Y | Y |
|
||||
| [DeepLabV3+](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/deeplabv3plus) | Y | Y | Y | Y | Y | Y |
|
||||
| [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/fastscnn)[\*](#static_shape) | Y | Y | Y | N | Y | Y |
|
||||
| [UNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/unet) | Y | Y | Y | Y | Y | Y |
|
||||
| [ANN](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/ann)[\*](#static_shape) | Y | Y | Y | N | N | N |
|
||||
| [APCNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/apcnet) | Y | Y | Y | Y | N | N |
|
||||
| [BiSeNetV1](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/bisenetv1) | Y | Y | Y | Y | N | Y |
|
||||
| [BiSeNetV2](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/bisenetv2) | Y | Y | Y | Y | N | Y |
|
||||
| [CGNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/cgnet) | Y | Y | Y | Y | N | Y |
|
||||
| [DMNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/dmnet) | ? | Y | N | N | N | N |
|
||||
| [DNLNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/dnlnet) | ? | Y | Y | Y | N | Y |
|
||||
| [EMANet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/emanet) | Y | Y | Y | N | N | Y |
|
||||
| [EncNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/encnet) | Y | Y | Y | N | N | Y |
|
||||
| [ERFNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/erfnet) | Y | Y | Y | Y | N | Y |
|
||||
| [FastFCN](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/fastfcn) | Y | Y | Y | Y | N | Y |
|
||||
| [GCNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/gcnet) | Y | Y | Y | N | N | N |
|
||||
| [ICNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/icnet)[\*](#static_shape) | Y | Y | Y | N | N | Y |
|
||||
| [ISANet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/isanet)[\*](#static_shape) | N | Y | Y | N | N | Y |
|
||||
| [NonLocal Net](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/nonlocal_net) | ? | Y | Y | Y | N | Y |
|
||||
| [OCRNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/ocrnet) | Y | Y | Y | Y | N | Y |
|
||||
| [PointRend](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/point_rend)[\*](#static_shape) | Y | Y | Y | N | N | N |
|
||||
| [Semantic FPN](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/sem_fpn) | Y | Y | Y | Y | N | Y |
|
||||
| [STDC](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/stdc) | Y | Y | Y | Y | N | Y |
|
||||
| [UPerNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/upernet)[\*](#static_shape) | N | Y | Y | N | N | N |
|
||||
| [DANet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/danet) | ? | Y | Y | N | N | Y |
|
||||
| [Segmenter](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/segmenter)[\*](#static_shape) | N | Y | Y | Y | N | Y |
|
||||
| [SegFormer](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/segformer)[\*](#static_shape) | ? | Y | Y | N | N | Y |
|
||||
| [SETR](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/setr) | ? | Y | N | N | N | Y |
|
||||
| [CCNet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/ccnet) | ? | N | N | N | N | N |
|
||||
| [PSANet](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/psanet) | ? | N | N | N | N | N |
|
||||
| [DPT](https://github.com/open-mmlab/mmsegmentation/tree/main/configs/dpt) | ? | N | N | N | N | N |
|
||||
|
||||
## Note
|
||||
|
||||
- All mmseg models only support the 'whole' inference mode.
|
||||
|
||||
- <i id=“static_shape”>PSPNet,Fast-SCNN</i> only supports static input, because most inference framework's [nn.AdaptiveAvgPool2d](https://github.com/open-mmlab/mmsegmentation/blob/0c87f7a0c9099844eff8e90fa3db5b0d0ca02fee/mmseg/models/decode_heads/psp_head.py#L38) don't support dynamic input。
|
||||
|
||||
- For models that only support static shapes, should use the static shape deployment config file, such as `configs/mmseg/segmentation_tensorrt_static-1024x2048.py`
|
||||
|
||||
- To deploy models to generate probabilistic feature maps, please add `codebase_config = dict(with_argmax=False)` to deployment config file.
|
||||
21
Seg_All_In_One_MMSeg/docs/en/user_guides/index.rst
Normal file
21
Seg_All_In_One_MMSeg/docs/en/user_guides/index.rst
Normal file
@@ -0,0 +1,21 @@
|
||||
Train & Test
|
||||
**************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
1_config.md
|
||||
2_dataset_prepare.md
|
||||
3_inference.md
|
||||
4_train_test.md
|
||||
|
||||
Useful Tools
|
||||
*************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
visualization.md
|
||||
useful_tools.md
|
||||
deployment.md
|
||||
visualization_feature_map.md
|
||||
245
Seg_All_In_One_MMSeg/docs/en/user_guides/useful_tools.md
Normal file
245
Seg_All_In_One_MMSeg/docs/en/user_guides/useful_tools.md
Normal file
@@ -0,0 +1,245 @@
|
||||
# \[WIP\] Useful Tools
|
||||
|
||||
Apart from training/testing scripts, We provide lots of useful tools under the
|
||||
`tools/` directory.
|
||||
|
||||
## Analysis Tools
|
||||
|
||||
### Plot training logs
|
||||
|
||||
`tools/analyze_logs.py` plots loss/mIoU curves given a training log file. `pip install seaborn` first to install the dependency.
|
||||
|
||||
```shell
|
||||
python tools/analysis_tools/analyze_logs.py xxx.json [--keys ${KEYS}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]
|
||||
```
|
||||
|
||||
Examples:
|
||||
|
||||
- Plot the mIoU, mAcc, aAcc metrics.
|
||||
|
||||
```shell
|
||||
python tools/analysis_tools/analyze_logs.py log.json --keys mIoU mAcc aAcc --legend mIoU mAcc aAcc
|
||||
```
|
||||
|
||||
- Plot loss metric.
|
||||
|
||||
```shell
|
||||
python tools/analysis_tools/analyze_logs.py log.json --keys loss --legend loss
|
||||
```
|
||||
|
||||
### Confusion Matrix (experimental)
|
||||
|
||||
In order to generate and plot a `nxn` confusion matrix where `n` is the number of classes, you can follow the steps:
|
||||
|
||||
#### 1.Generate a prediction result in pkl format using `test.py`
|
||||
|
||||
```shell
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--out ${PATH_TO_RESULT_FILE}]
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```shell
|
||||
python tools/test.py \
|
||||
configs/fcn/fcn_r50-d8_4xb2-40k_cityscapes-512x1024.py \
|
||||
checkpoint/fcn_r50-d8_512x1024_40k_cityscapes_20200604_192608-efe53f0d.pth \
|
||||
--out result/pred_result.pkl
|
||||
```
|
||||
|
||||
#### 2. Use `confusion_matrix.py` to generate and plot a confusion matrix
|
||||
|
||||
```shell
|
||||
python tools/confusion_matrix.py ${CONFIG_FILE} ${PATH_TO_RESULT_FILE} ${SAVE_DIR} --show
|
||||
```
|
||||
|
||||
Description of arguments:
|
||||
|
||||
- `config`: Path to the test config file.
|
||||
- `prediction_path`: Path to the prediction .pkl result.
|
||||
- `save_dir`: Directory where confusion matrix will be saved.
|
||||
- `--show`: Enable result visualize.
|
||||
- `--color-theme`: Theme of the matrix color map.
|
||||
- `--cfg_options`: Custom options to replace the config file.
|
||||
|
||||
Example:
|
||||
|
||||
```shell
|
||||
python tools/confusion_matrix.py \
|
||||
configs/fcn/fcn_r50-d8_512x1024_40k_cityscapes.py \
|
||||
result/pred_result.pkl \
|
||||
result/confusion_matrix \
|
||||
--show
|
||||
```
|
||||
|
||||
### Get the FLOPs and params (experimental)
|
||||
|
||||
We provide a script adapted from [flops-counter.pytorch](https://github.com/sovrasov/flops-counter.pytorch) to compute the FLOPs and params of a given model.
|
||||
|
||||
```shell
|
||||
python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]
|
||||
```
|
||||
|
||||
You will get the result like this.
|
||||
|
||||
```none
|
||||
==============================
|
||||
Input shape: (3, 2048, 1024)
|
||||
Flops: 1429.68 GMac
|
||||
Params: 48.98 M
|
||||
==============================
|
||||
```
|
||||
|
||||
:::{note}
|
||||
This tool is still experimental and we do not guarantee that the number is correct. You may well use the result for simple comparisons, but double check it before you adopt it in technical reports or papers.
|
||||
:::
|
||||
|
||||
(1) FLOPs are related to the input shape while parameters are not. The default input shape is (1, 3, 1280, 800).
|
||||
(2) Some operators are not counted into FLOPs like GN and custom operators.
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### Publish a model
|
||||
|
||||
Before you upload a model to AWS, you may want to
|
||||
(1) convert model weights to CPU tensors, (2) delete the optimizer states and
|
||||
(3) compute the hash of the checkpoint file and append the hash id to the filename.
|
||||
|
||||
```shell
|
||||
python tools/misc/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}
|
||||
```
|
||||
|
||||
E.g.,
|
||||
|
||||
```shell
|
||||
python tools/publish_model.py work_dirs/pspnet/latest.pth psp_r50_512x1024_40k_cityscapes.pth
|
||||
```
|
||||
|
||||
The final output filename will be `psp_r50_512x1024_40k_cityscapes-{hash id}.pth`.
|
||||
|
||||
### Print the entire config
|
||||
|
||||
`tools/misc/print_config.py` prints the whole config verbatim, expanding all its
|
||||
imports.
|
||||
|
||||
```shell
|
||||
python tools/misc/print_config.py \
|
||||
${CONFIG} \
|
||||
--graph \
|
||||
--cfg-options ${OPTIONS [OPTIONS...]} \
|
||||
```
|
||||
|
||||
Description of arguments:
|
||||
|
||||
- `config` : The path of a pytorch model config file.
|
||||
- `--graph` : Determines whether to print the models graph.
|
||||
- `--cfg-options`: Custom options to replace the config file.
|
||||
|
||||
## Model conversion
|
||||
|
||||
`tools/model_converters/` provide several scripts to convert pretrain models released by other repos to MMSegmentation style.
|
||||
|
||||
### ViT Swin MiT Transformer Models
|
||||
|
||||
- ViT
|
||||
|
||||
`tools/model_converters/vit2mmseg.py` convert keys in timm pretrained vit models to MMSegmentation style.
|
||||
|
||||
```shell
|
||||
python tools/model_converters/vit2mmseg.py ${SRC} ${DST}
|
||||
```
|
||||
|
||||
- Swin
|
||||
|
||||
`tools/model_converters/swin2mmseg.py` convert keys in official pretrained swin models to MMSegmentation style.
|
||||
|
||||
```shell
|
||||
python tools/model_converters/swin2mmseg.py ${SRC} ${DST}
|
||||
```
|
||||
|
||||
- SegFormer
|
||||
|
||||
`tools/model_converters/mit2mmseg.py` convert keys in official pretrained mit models to MMSegmentation style.
|
||||
|
||||
```shell
|
||||
python tools/model_converters/mit2mmseg.py ${SRC} ${DST}
|
||||
```
|
||||
|
||||
## Model Serving
|
||||
|
||||
In order to serve an `MMSegmentation` model with [`TorchServe`](https://pytorch.org/serve/), you can follow the steps:
|
||||
|
||||
### 1. Convert model from MMSegmentation to TorchServe
|
||||
|
||||
```shell
|
||||
python tools/torchserve/mmseg2torchserve.py ${CONFIG_FILE} ${CHECKPOINT_FILE} \
|
||||
--output-folder ${MODEL_STORE} \
|
||||
--model-name ${MODEL_NAME}
|
||||
```
|
||||
|
||||
:::{note}
|
||||
${MODEL_STORE} needs to be an absolute path to a folder.
|
||||
:::
|
||||
|
||||
### 2. Build `mmseg-serve` docker image
|
||||
|
||||
```shell
|
||||
docker build -t mmseg-serve:latest docker/serve/
|
||||
```
|
||||
|
||||
### 3. Run `mmseg-serve`
|
||||
|
||||
Check the official docs for [running TorchServe with docker](https://github.com/pytorch/serve/blob/master/docker/README.md#running-torchserve-in-a-production-docker-environment).
|
||||
|
||||
In order to run in GPU, you need to install [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). You can omit the `--gpus` argument in order to run in CPU.
|
||||
|
||||
Example:
|
||||
|
||||
```shell
|
||||
docker run --rm \
|
||||
--cpus 8 \
|
||||
--gpus device=0 \
|
||||
-p8080:8080 -p8081:8081 -p8082:8082 \
|
||||
--mount type=bind,source=$MODEL_STORE,target=/home/model-server/model-store \
|
||||
mmseg-serve:latest
|
||||
```
|
||||
|
||||
[Read the docs](https://github.com/pytorch/serve/blob/072f5d088cce9bb64b2a18af065886c9b01b317b/docs/rest_api.md) about the Inference (8080), Management (8081) and Metrics (8082) APIs
|
||||
|
||||
### 4. Test deployment
|
||||
|
||||
```shell
|
||||
curl -O https://raw.githubusercontent.com/open-mmlab/mmsegmentation/master/resources/3dogs.jpg
|
||||
curl http://127.0.0.1:8080/predictions/${MODEL_NAME} -T 3dogs.jpg -o 3dogs_mask.png
|
||||
```
|
||||
|
||||
The response will be a ".png" mask.
|
||||
|
||||
You can visualize the output as follows:
|
||||
|
||||
```python
|
||||
import matplotlib.pyplot as plt
|
||||
import mmcv
|
||||
plt.imshow(mmcv.imread("3dogs_mask.png", "grayscale"))
|
||||
plt.show()
|
||||
```
|
||||
|
||||
You should see something similar to:
|
||||
|
||||

|
||||
|
||||
And you can use `test_torchserve.py` to compare result of torchserve and pytorch, and visualize them.
|
||||
|
||||
```shell
|
||||
python tools/torchserve/test_torchserve.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} ${MODEL_NAME}
|
||||
[--inference-addr ${INFERENCE_ADDR}] [--result-image ${RESULT_IMAGE}] [--device ${DEVICE}]
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```shell
|
||||
python tools/torchserve/test_torchserve.py \
|
||||
demo/demo.png \
|
||||
configs/fcn/fcn_r50-d8_512x1024_40k_cityscapes.py \
|
||||
checkpoint/fcn_r50-d8_512x1024_40k_cityscapes_20200604_192608-efe53f0d.pth \
|
||||
fcn
|
||||
```
|
||||
174
Seg_All_In_One_MMSeg/docs/en/user_guides/visualization.md
Normal file
174
Seg_All_In_One_MMSeg/docs/en/user_guides/visualization.md
Normal file
@@ -0,0 +1,174 @@
|
||||
# Visualization
|
||||
|
||||
MMSegmentation 1.x provides convenient ways for monitoring training status or visualizing data and model predictions.
|
||||
|
||||
## Training status Monitor
|
||||
|
||||
MMSegmentation 1.x uses TensorBoard to monitor training status.
|
||||
|
||||
### TensorBoard Configuration
|
||||
|
||||
Install TensorBoard following [official instructions](https://www.tensorflow.org/install) e.g.
|
||||
|
||||
```shell
|
||||
pip install tensorboardX
|
||||
pip install future tensorboard
|
||||
```
|
||||
|
||||
Add `TensorboardVisBackend` in `vis_backend` of `visualizer` in `default_runtime.py` config file:
|
||||
|
||||
```python
|
||||
vis_backends = [dict(type='LocalVisBackend'),
|
||||
dict(type='TensorboardVisBackend')]
|
||||
visualizer = dict(
|
||||
type='SegLocalVisualizer', vis_backends=vis_backends, name='visualizer')
|
||||
```
|
||||
|
||||
### Examining scalars in TensorBoard
|
||||
|
||||
Launch training experiment e.g.
|
||||
|
||||
```shell
|
||||
python tools/train.py configs/pspnet/pspnet_r50-d8_4xb4-80k_ade20k-512x512.py --work-dir work_dir/test_visual
|
||||
```
|
||||
|
||||
Find the `vis_data` path of `work_dir` after starting training, for example, the vis_data path of this particular test is as follows:
|
||||
|
||||
```shell
|
||||
work_dirs/test_visual/20220810_115248/vis_data
|
||||
```
|
||||
|
||||
The scalar file in vis_data path includes learning rate, losses and data_time etc, also record metrics results and you can refer [logging tutorial](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/logging.html) in MMEngine to log custom data. The tensorboard visualization results are executed with the following command:
|
||||
|
||||
```shell
|
||||
tensorboard --logdir work_dirs/test_visual/20220810_115248/vis_data
|
||||
```
|
||||
|
||||
## Data and Results visualization
|
||||
|
||||
### Visualizer Data Samples during Model Testing or Validation
|
||||
|
||||
MMSegmentation provides `SegVisualizationHook` which is a [hook](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/hook.md) working to visualize ground truth and prediction of segmentation during model testing and evaluation. Its configuration is in `default_hooks`, please see [Runner tutorial](https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/runner.md) for more details.
|
||||
|
||||
For example, In `_base_/schedules/schedule_20k.py`, modify the `SegVisualizationHook` configuration, set `draw` to `True` to enable the storage of network inference results, `interval` indicates the sampling interval of the prediction results, and when set to 1, each inference result of the network will be saved. `interval` is set to 50 by default:
|
||||
|
||||
```python
|
||||
default_hooks = dict(
|
||||
timer=dict(type='IterTimerHook'),
|
||||
logger=dict(type='LoggerHook', interval=50, log_metric_by_epoch=False),
|
||||
param_scheduler=dict(type='ParamSchedulerHook'),
|
||||
checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=2000),
|
||||
sampler_seed=dict(type='DistSamplerSeedHook'),
|
||||
visualization=dict(type='SegVisualizationHook', draw=True, interval=1))
|
||||
|
||||
```
|
||||
|
||||
After launch training experiment, visualization results will be stored in the local folder in validation loop,
|
||||
or when launch evaluation a model on one dataset, the prediction results will be store in the local.
|
||||
The stored results of the local visualization are kept in `vis_image` under `$WORK_DIRS/vis_data`, e.g.:
|
||||
|
||||
```shell
|
||||
work_dirs/test_visual/20220810_115248/vis_data/vis_image
|
||||
```
|
||||
|
||||
In addition, if `TensorboardVisBackend` is add in `vis_backends`, like [above](#tensorboard-configuration),
|
||||
we can also run the following command to view them in TensorBoard:
|
||||
|
||||
```shell
|
||||
tensorboard --logdir work_dirs/test_visual/20220810_115248/vis_data
|
||||
```
|
||||
|
||||
### Visualize a Single Data Sample
|
||||
|
||||
If you want to visualize a single data sample, we suggest to use `SegLocalVisualizer`.
|
||||
|
||||
`SegLocalVisualizer` is child class inherits from `Visualizer` in MMEngine and works for MMSegmentation visualization, for more details about `Visualizer` please refer to [visualization tutorial](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/visualization.md) in MMEngine.
|
||||
|
||||
Here is an example about `SegLocalVisualizer`, first you may download example data below by following commands:
|
||||
|
||||
<div align=center>
|
||||
<img src="https://user-images.githubusercontent.com/24582831/189833109-eddad58f-f777-4fc0-b98a-6bd429143b06.png" width="70%"/>
|
||||
</div>
|
||||
|
||||
```shell
|
||||
wget https://user-images.githubusercontent.com/24582831/189833109-eddad58f-f777-4fc0-b98a-6bd429143b06.png --output-document aachen_000000_000019_leftImg8bit.png
|
||||
wget https://user-images.githubusercontent.com/24582831/189833143-15f60f8a-4d1e-4cbb-a6e7-5e2233869fac.png --output-document aachen_000000_000019_gtFine_labelTrainIds.png
|
||||
```
|
||||
|
||||
Then you can find their local path and use the scripts below to visualize:
|
||||
|
||||
```python
|
||||
import mmcv
|
||||
import os.path as osp
|
||||
import torch
|
||||
# `PixelData` is data structure for pixel-level annotations or predictions defined in MMEngine.
|
||||
# Please refer to below tutorial file of data structures in MMEngine:
|
||||
# https://github.com/open-mmlab/mmengine/tree/main/docs/en/advanced_tutorials/data_element.md
|
||||
|
||||
from mmengine.structures import PixelData
|
||||
|
||||
# `SegDataSample` is data structure interface between different components
|
||||
# defined in MMSegmentation, it includes ground truth, prediction and
|
||||
# predicted logits of semantic segmentation.
|
||||
# Please refer to below tutorial file of `SegDataSample` for more details:
|
||||
# https://github.com/open-mmlab/mmsegmentation/blob/1.x/docs/en/advanced_guides/structures.md
|
||||
|
||||
from mmseg.structures import SegDataSample
|
||||
from mmseg.visualization import SegLocalVisualizer
|
||||
|
||||
out_file = 'out_file_cityscapes'
|
||||
save_dir = './work_dirs'
|
||||
|
||||
image = mmcv.imread(
|
||||
osp.join(
|
||||
osp.dirname(__file__),
|
||||
'./aachen_000000_000019_leftImg8bit.png'
|
||||
),
|
||||
'color')
|
||||
sem_seg = mmcv.imread(
|
||||
osp.join(
|
||||
osp.dirname(__file__),
|
||||
'./aachen_000000_000019_gtFine_labelTrainIds.png' # noqa
|
||||
),
|
||||
'unchanged')
|
||||
sem_seg = torch.from_numpy(sem_seg)
|
||||
gt_sem_seg_data = dict(data=sem_seg)
|
||||
gt_sem_seg = PixelData(**gt_sem_seg_data)
|
||||
data_sample = SegDataSample()
|
||||
data_sample.gt_sem_seg = gt_sem_seg
|
||||
|
||||
seg_local_visualizer = SegLocalVisualizer(
|
||||
vis_backends=[dict(type='LocalVisBackend')],
|
||||
save_dir=save_dir)
|
||||
|
||||
# The meta information of dataset usually includes `classes` for class names and
|
||||
# `palette` for visualization color of each foreground.
|
||||
# All class names and palettes are defined in the file:
|
||||
# https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/utils/class_names.py
|
||||
|
||||
seg_local_visualizer.dataset_meta = dict(
|
||||
classes=('road', 'sidewalk', 'building', 'wall', 'fence',
|
||||
'pole', 'traffic light', 'traffic sign',
|
||||
'vegetation', 'terrain', 'sky', 'person', 'rider',
|
||||
'car', 'truck', 'bus', 'train', 'motorcycle',
|
||||
'bicycle'),
|
||||
palette=[[128, 64, 128], [244, 35, 232], [70, 70, 70],
|
||||
[102, 102, 156], [190, 153, 153], [153, 153, 153],
|
||||
[250, 170, 30], [220, 220, 0], [107, 142, 35],
|
||||
[152, 251, 152], [70, 130, 180], [220, 20, 60],
|
||||
[255, 0, 0], [0, 0, 142], [0, 0, 70],
|
||||
[0, 60, 100], [0, 80, 100], [0, 0, 230],
|
||||
[119, 11, 32]])
|
||||
# When `show=True`, the results would be shown directly,
|
||||
# else if `show=False`, the results would be saved in local directory folder.
|
||||
seg_local_visualizer.add_datasample(out_file, image,
|
||||
data_sample, show=False)
|
||||
```
|
||||
|
||||
Then the visualization result of image with its corresponding ground truth could be found in `./work_dirs/vis_data/vis_image/` whose name is `out_file_cityscapes_0.png`:
|
||||
|
||||
<div align=center>
|
||||
<img src="https://user-images.githubusercontent.com/24582831/189835713-c0534054-4bfa-4b75-9254-0afbeb5ff02e.png" width="70%"/>
|
||||
</div>
|
||||
|
||||
If you would like to know more visualization usage, you can refer to [visualization tutorial](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/visualization.html) in MMEngine.
|
||||
@@ -0,0 +1,201 @@
|
||||
# Wandb Feature Map Visualization
|
||||
|
||||
MMSegmentation 1.x provides backend support for Weights & Biases to facilitate visualization and management of project code results.
|
||||
|
||||
## Wandb Configuration
|
||||
|
||||
Install Weights & Biases following [official instructions](https://docs.wandb.ai/quickstart) e.g.
|
||||
|
||||
```shell
|
||||
pip install wandb
|
||||
wandb login
|
||||
```
|
||||
|
||||
Add `WandbVisBackend` in `vis_backend` of `visualizer` in `default_runtime.py` config file:
|
||||
|
||||
```python
|
||||
vis_backends=[dict(type='LocalVisBackend'),
|
||||
dict(type='TensorboardVisBackend'),
|
||||
dict(type='WandbVisBackend')]
|
||||
```
|
||||
|
||||
## Examining feature map visualization in Wandb
|
||||
|
||||
`SegLocalVisualizer` is child class inherits from `Visualizer` in MMEngine and works for MMSegmentation visualization, for more details about `Visualizer` please refer to [visualization tutorial](https://github.com/open-mmlab/mmengine/blob/main/docs/en/advanced_tutorials/visualization.md) in MMEngine.
|
||||
|
||||
Here is an example about `SegLocalVisualizer`, first you may download example data below by following commands:
|
||||
|
||||
<div align=center>
|
||||
<img src="https://user-images.githubusercontent.com/24582831/189833109-eddad58f-f777-4fc0-b98a-6bd429143b06.png" width="70%"/>
|
||||
</div>
|
||||
|
||||
```shell
|
||||
wget https://user-images.githubusercontent.com/24582831/189833109-eddad58f-f777-4fc0-b98a-6bd429143b06.png --output-document aachen_000000_000019_leftImg8bit.png
|
||||
wget https://user-images.githubusercontent.com/24582831/189833143-15f60f8a-4d1e-4cbb-a6e7-5e2233869fac.png --output-document aachen_000000_000019_gtFine_labelTrainIds.png
|
||||
|
||||
wget https://download.openmmlab.com/mmsegmentation/v0.5/ann/ann_r50-d8_512x1024_40k_cityscapes/ann_r50-d8_512x1024_40k_cityscapes_20200605_095211-049fc292.pth
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
from argparse import ArgumentParser
|
||||
from typing import Type
|
||||
|
||||
import mmcv
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from mmengine.model import revert_sync_batchnorm
|
||||
from mmengine.structures import PixelData
|
||||
from mmseg.apis import inference_model, init_model
|
||||
from mmseg.structures import SegDataSample
|
||||
from mmseg.utils import register_all_modules
|
||||
from mmseg.visualization import SegLocalVisualizer
|
||||
|
||||
|
||||
class Recorder:
|
||||
"""record the forward output feature map and save to data_buffer."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.data_buffer = list()
|
||||
|
||||
def __enter__(self, ):
|
||||
self._data_buffer = list()
|
||||
|
||||
def record_data_hook(self, model: nn.Module, input: Type, output: Type):
|
||||
self.data_buffer.append(output)
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
def visualize(args, model, recorder, result):
|
||||
seg_visualizer = SegLocalVisualizer(
|
||||
vis_backends=[dict(type='WandbVisBackend')],
|
||||
save_dir='temp_dir',
|
||||
alpha=0.5)
|
||||
seg_visualizer.dataset_meta = dict(
|
||||
classes=model.dataset_meta['classes'],
|
||||
palette=model.dataset_meta['palette'])
|
||||
|
||||
image = mmcv.imread(args.img, 'color')
|
||||
|
||||
seg_visualizer.add_datasample(
|
||||
name='predict',
|
||||
image=image,
|
||||
data_sample=result,
|
||||
draw_gt=False,
|
||||
draw_pred=True,
|
||||
wait_time=0,
|
||||
out_file=None,
|
||||
show=False)
|
||||
|
||||
# add feature map to wandb visualizer
|
||||
for i in range(len(recorder.data_buffer)):
|
||||
feature = recorder.data_buffer[i][0] # remove the batch
|
||||
drawn_img = seg_visualizer.draw_featmap(
|
||||
feature, image, channel_reduction='select_max')
|
||||
seg_visualizer.add_image(f'feature_map{i}', drawn_img)
|
||||
|
||||
if args.gt_mask:
|
||||
sem_seg = mmcv.imread(args.gt_mask, 'unchanged')
|
||||
sem_seg = torch.from_numpy(sem_seg)
|
||||
gt_mask = dict(data=sem_seg)
|
||||
gt_mask = PixelData(**gt_mask)
|
||||
data_sample = SegDataSample()
|
||||
data_sample.gt_sem_seg = gt_mask
|
||||
|
||||
seg_visualizer.add_datasample(
|
||||
name='gt_mask',
|
||||
image=image,
|
||||
data_sample=data_sample,
|
||||
draw_gt=True,
|
||||
draw_pred=False,
|
||||
wait_time=0,
|
||||
out_file=None,
|
||||
show=False)
|
||||
|
||||
seg_visualizer.add_image('image', image)
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(
|
||||
description='Draw the Feature Map During Inference')
|
||||
parser.add_argument('img', help='Image file')
|
||||
parser.add_argument('config', help='Config file')
|
||||
parser.add_argument('checkpoint', help='Checkpoint file')
|
||||
parser.add_argument('--gt_mask', default=None, help='Path of gt mask file')
|
||||
parser.add_argument('--out-file', default=None, help='Path to output file')
|
||||
parser.add_argument(
|
||||
'--device', default='cuda:0', help='Device used for inference')
|
||||
parser.add_argument(
|
||||
'--opacity',
|
||||
type=float,
|
||||
default=0.5,
|
||||
help='Opacity of painted segmentation map. In (0, 1] range.')
|
||||
parser.add_argument(
|
||||
'--title', default='result', help='The image identifier.')
|
||||
args = parser.parse_args()
|
||||
|
||||
register_all_modules()
|
||||
|
||||
# build the model from a config file and a checkpoint file
|
||||
model = init_model(args.config, args.checkpoint, device=args.device)
|
||||
if args.device == 'cpu':
|
||||
model = revert_sync_batchnorm(model)
|
||||
|
||||
# show all named module in the model and use it in source list below
|
||||
for name, module in model.named_modules():
|
||||
print(name)
|
||||
|
||||
source = [
|
||||
'decode_head.fusion.stages.0.query_project.activate',
|
||||
'decode_head.context.stages.0.key_project.activate',
|
||||
'decode_head.context.bottleneck.activate'
|
||||
]
|
||||
source = dict.fromkeys(source)
|
||||
|
||||
count = 0
|
||||
recorder = Recorder()
|
||||
# registry the forward hook
|
||||
for name, module in model.named_modules():
|
||||
if name in source:
|
||||
count += 1
|
||||
module.register_forward_hook(recorder.record_data_hook)
|
||||
if count == len(source):
|
||||
break
|
||||
|
||||
with recorder:
|
||||
# test a single image, and record feature map to data_buffer
|
||||
result = inference_model(model, args.img)
|
||||
|
||||
visualize(args, model, recorder, result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
```
|
||||
|
||||
Save the above code as feature_map_visual.py and execute the following code in terminal
|
||||
|
||||
```shell
|
||||
python feature_map_visual.py ${image} ${config} ${checkpoint} [optional args]
|
||||
```
|
||||
|
||||
e.g
|
||||
|
||||
```shell
|
||||
python feature_map_visual.py \
|
||||
aachen_000000_000019_leftImg8bit.png \
|
||||
configs/ann/ann_r50-d8_4xb2-40k_cityscapes-512x1024.py \
|
||||
ann_r50-d8_512x1024_40k_cityscapes_20200605_095211-049fc292.pth \
|
||||
--gt_mask aachen_000000_000019_gtFine_labelTrainIds.png
|
||||
```
|
||||
|
||||
The visualized image result and its corresponding feature map will appear in the wandb account.
|
||||
|
||||
<div align=center>
|
||||
<img src="https://user-images.githubusercontent.com/76149310/217520321-647f5bf9-eef2-446d-a9e8-5ca7b621d500.png">
|
||||
</div>
|
||||
Reference in New Issue
Block a user