Skip to content

Commit b9fbf54

Browse files
authored
Add Component Doc (PaddlePaddle#686)
1 parent bc7cfcd commit b9fbf54

File tree

3 files changed

+277
-54
lines changed

3 files changed

+277
-54
lines changed

configs/unet_plusplus/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
使用unet++在cityscapes上训练160k个iter,单卡batch_size为1,共4卡,学习率设为0.005,最终miou为0.5109。
2-
需要重新训练。
1+
# A Nested U-Net Architecture for Medical Image Segmentation
2+
3+
## Reference
4+
5+
> Zhou, Zongwei, Md Mahfuzur Rahman Siddiquee, Nima Tajbakhsh, and Jianming Liang. "Unet++: A nested u-net architecture for medical image segmentation." In Deep Learning in Medical Image Analysis and Multimodal Learning for Clinical Decision Support, pp. 3-11. Springer, Cham, 2018.

docs/add_new_model.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Add New Components
22

3+
PaddleSeg provides five types of extensible components, i.e. MODELS, LOSSES, TRANSFORMS, BACKBONES, DATASETS.
4+
35
## A New Model
46

57
If you intent to design a customized model, e.g, NewNet in newnet.py:
@@ -18,7 +20,7 @@ class NewNet(nn.Layer):
1820

1921
**Step 1**: Put newnet.py under paddleseg/models/.
2022

21-
**Step 2**: Add @manager.MODELS.add_component above your model class, where the manager is a commpent container, inclduing MODELS, BACKBONES, DATASETS, TRANSFORMS, LOSSES.
23+
**Step 2**: Add @manager.MODELS.add_component above your model class, where the manager is a component container, inclduing MODELS, BACKBONES, DATASETS, TRANSFORMS, LOSSES.
2224

2325
**Step 3**: Import your class in paddleseg/models/\_\_init\_\_.py, like this:
2426
```python
@@ -42,3 +44,141 @@ loss:
4244
- type: CrossEntropyLoss
4345
coef: [1, 0.4]
4446
```
47+
48+
## A New Loss
49+
50+
If you intent to implement a new loss, e.g. NewLoss in new_loss.py.
51+
52+
```python
53+
import paddle.nn as nn
54+
from paddleseg.cvlibs import manager
55+
56+
@manager.LOSSES.add_component
57+
class NewLoss(nn.Layer):
58+
def __init__(self, param1, ignore_index=255):
59+
pass
60+
def forward(self, x):
61+
pass
62+
```
63+
64+
**Step 1**: Put new_loss.py under paddleseg/models/losses.
65+
66+
**Step 2**: Add @manager.LOSSES.add_component above your loss class.
67+
68+
**Step 3**: Import your class in paddleseg/models/losses/\_\_init\_\_.py, like this:
69+
```python
70+
from .new_loss import NewLoss
71+
```
72+
73+
**Step 4**: Specify the loss name in a yaml file:
74+
75+
```python
76+
loss:
77+
types:
78+
- type: NewLoss
79+
param1: ...
80+
coef: [1]
81+
```
82+
83+
## A New Transform
84+
85+
If you intent to implement a new transform (data augmentation), e.g. NewTrans.
86+
87+
```python
88+
89+
@manager.TRANSFORMS.add_component
90+
class NewTrans(nn.Layer):
91+
def __init__(self, param1):
92+
pass
93+
def __call__(self, im, label=None):
94+
95+
...
96+
97+
if label is None:
98+
return (im, )
99+
else:
100+
return (im, label)
101+
```
102+
103+
**Step 1**: Define the NewTrans class in paddleseg/transforms/transforms.py.
104+
105+
**Step 2**: Add @manager.TRANSFORMS.add_component above your transform class. That's all.
106+
107+
**Step 3**: Specify the transform name in a yaml file:
108+
109+
```python
110+
train_dataset:
111+
transforms:
112+
- type: NewTrans
113+
param1: ...
114+
```
115+
Note: For better readability,please implement detailed transformation functions in paddleseg/transforms/functional.py.
116+
117+
## A New Backbone
118+
119+
If you intent to add a new backbone network, e.g. NewBackbone in new_backbone.py.
120+
121+
```python
122+
import paddle.nn as nn
123+
from paddleseg.cvlibs import manager
124+
125+
@manager.BACKBONES.add_component
126+
class NewBackbone(nn.Layer):
127+
def __init__(self, param1):
128+
pass
129+
def forward(self, x):
130+
pass
131+
```
132+
133+
**Step 1**: Put new_backbone.py under paddleseg/models/backbones.
134+
135+
**Step 2**: Add @manager.BACKBONES.add_component above your backbone class.
136+
137+
**Step 3**: Import your class in paddleseg/models/backbones/\_\_init\_\_.py, like this:
138+
```python
139+
from .new_backbone import NewBackbone
140+
```
141+
142+
**Step 4**: Specify the backbone name in a yaml file:
143+
144+
```python
145+
model:
146+
backbone:
147+
type: NewBackbone
148+
param1: ...
149+
```
150+
151+
## A New Dataset
152+
153+
If you intent to add a new dataset, e.g. NewData in new_data.py.
154+
155+
```python
156+
from paddleseg..dataset import Dataset
157+
from paddleseg.cvlibs import manager
158+
159+
@manager.DATASETS.add_component
160+
class NewData(Dataset):
161+
def __init__(self,
162+
dataset_root=None,
163+
transforms=None,
164+
mode='train'):
165+
pass
166+
```
167+
168+
**Step 1**: Put new_data.py under paddleseg/datasets.
169+
170+
**Step 2**: Add @manager.DATASETS.add_component above your dataset class.
171+
172+
**Step 3**: Import your class in paddleseg/datasets/\_\_init\_\_.py, like this:
173+
```python
174+
from .new_data import NewData
175+
```
176+
177+
**Step 4**: Specify the backbone name in a yaml file:
178+
179+
```python
180+
train_dataset:
181+
type: NewData
182+
dataset_root: ...
183+
mode: train
184+
```

0 commit comments

Comments
 (0)