You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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.
Copy file name to clipboardExpand all lines: docs/add_new_model.md
+141-1Lines changed: 141 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Add New Components
2
2
3
+
PaddleSeg provides five types of extensible components, i.e. MODELS, LOSSES, TRANSFORMS, BACKBONES, DATASETS.
4
+
3
5
## A New Model
4
6
5
7
If you intent to design a customized model, e.g, NewNet in newnet.py:
@@ -18,7 +20,7 @@ class NewNet(nn.Layer):
18
20
19
21
**Step 1**: Put newnet.py under paddleseg/models/.
20
22
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.
22
24
23
25
**Step 3**: Import your class in paddleseg/models/\_\_init\_\_.py, like this:
24
26
```python
@@ -42,3 +44,141 @@ loss:
42
44
-type: CrossEntropyLoss
43
45
coef: [1, 0.4]
44
46
```
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
+
classNewLoss(nn.Layer):
58
+
def__init__(self, param1, ignore_index=255):
59
+
pass
60
+
defforward(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
+
classNewTrans(nn.Layer):
91
+
def__init__(self, param1):
92
+
pass
93
+
def__call__(self, im, label=None):
94
+
95
+
...
96
+
97
+
if label isNone:
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
+
classNewBackbone(nn.Layer):
127
+
def__init__(self, param1):
128
+
pass
129
+
defforward(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
+
classNewData(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:
0 commit comments