mirror of
https://github.com/open-mmlab/mmsegmentation.git
synced 2025-06-03 22:03:48 +08:00
[Refactor] Add transform tutorial for dev-1.x (#1985)
* transform tutorial * fix
This commit is contained in:
parent
adec7f2d65
commit
cc240ce551
37
docs/en/advanced_guides/add_transform.md
Normal file
37
docs/en/advanced_guides/add_transform.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Adding New Data Transforms
|
||||||
|
|
||||||
|
1. Write a new pipeline in any file, e.g., `my_pipeline.py`. It takes a dict as input and return a dict.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from mmseg.datasets import TRANSFORMS
|
||||||
|
@TRANSFORMS.register_module()
|
||||||
|
class MyTransform:
|
||||||
|
def __call__(self, results):
|
||||||
|
results['dummy'] = True
|
||||||
|
return results
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Import the new class.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from .my_pipeline import MyTransform
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Use it in config files.
|
||||||
|
|
||||||
|
```python
|
||||||
|
crop_size = (512, 1024)
|
||||||
|
train_pipeline = [
|
||||||
|
dict(type='LoadImageFromFile'),
|
||||||
|
dict(type='LoadAnnotations'),
|
||||||
|
dict(type='RandomResize',
|
||||||
|
scale=(2048, 1024),
|
||||||
|
ratio_range=(0.5, 2.0),
|
||||||
|
keep_ratio=True),
|
||||||
|
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
|
||||||
|
dict(type='RandomFlip', flip_ratio=0.5),
|
||||||
|
dict(type='PhotoMetricDistortion'),
|
||||||
|
dict(type='MyTransform'),
|
||||||
|
dict(type='PackSegInputs'),
|
||||||
|
]
|
||||||
|
```
|
@ -87,41 +87,3 @@ Before pipelines, the information we can directly obtain from the datasets are i
|
|||||||
|
|
||||||
- add: inputs, data_sample
|
- add: inputs, data_sample
|
||||||
- remove: keys specified by `meta_keys` (merged into the metainfo of data_sample), all other keys
|
- remove: keys specified by `meta_keys` (merged into the metainfo of data_sample), all other keys
|
||||||
|
|
||||||
## Extend and use custom pipelines
|
|
||||||
|
|
||||||
1. Write a new pipeline in any file, e.g., `my_pipeline.py`. It takes a dict as input and return a dict.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from mmseg.datasets import PIPELINES
|
|
||||||
@PIPELINES.register_module()
|
|
||||||
class MyTransform:
|
|
||||||
def __call__(self, results):
|
|
||||||
results['dummy'] = True
|
|
||||||
return results
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Import the new class.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from .my_pipeline import MyTransform
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Use it in config files.
|
|
||||||
|
|
||||||
```python
|
|
||||||
crop_size = (512, 1024)
|
|
||||||
train_pipeline = [
|
|
||||||
dict(type='LoadImageFromFile'),
|
|
||||||
dict(type='LoadAnnotations'),
|
|
||||||
dict(type='RandomResize',
|
|
||||||
scale=(2048, 1024),
|
|
||||||
ratio_range=(0.5, 2.0),
|
|
||||||
keep_ratio=True),
|
|
||||||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
|
|
||||||
dict(type='RandomFlip', flip_ratio=0.5),
|
|
||||||
dict(type='PhotoMetricDistortion'),
|
|
||||||
dict(type='MyTransform'),
|
|
||||||
dict(type='PackSegInputs'),
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user