Skip to content

Commit 12ca7e3

Browse files
authored
【Hackathon 5th No.68】轻量语义分割网络PIDNet (#3548)
* Add PIDNet
1 parent 56c6827 commit 12ca7e3

14 files changed

+1238
-7
lines changed

configs/pidnet/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# PIDNet: A Real-time Semantic Segmentation Network Inspired from PID Controller
2+
3+
## Reference
4+
5+
> Xu, Jiacong, Zixiang Xiong, and Shankar P. Bhattacharyya. "PIDNet: A Real-Time Semantic Segmentation Network Inspired by PID Controllers." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2023.
6+
7+
## Performance
8+
9+
### Cityscapes
10+
11+
| Model | Backbone | Resolution | Training Iters | mIoU | mIoU (flip) | mIoU (ms+flip) | Links |
12+
|-|-|-|-|-|-|-|-|
13+
|PIDNet|PIDNet-Small |1024x1024|120000|78.48%|79.02%|79.68%|[model](https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_small_cityscapes_1024x1024_120k/model.pdparams) \| [log](https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_small_cityscapes_1024x1024_120k/pidnet_small.log) \| [vdl](https://paddlepaddle.org.cn/paddle/visualdl/service/app?id=57dda9c34cd06a4b2996118df03583c9)|
14+
|PIDNet|PIDNet_Medium|1024x1024|120000| | | |
15+
|PIDNet|PIDNet-Large |1024x1024|120000| | | |
16+
17+
18+
#### official weight
19+
20+
| Model | Backbone | Resolution | Training Iters | mIoU | mIoU (flip) | mIoU (ms+flip) | Links |
21+
|-|-|-|-|-|-|-|-|
22+
|PIDNet|PIDNet-Small |1024x1024|120000|78.74%|79.53%|80.28%|[model](https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_small_2xb6-120k_1024x1024-cityscapes.pdparams)|
23+
|PIDNet|PIDNet_Medium|1024x1024|120000|80.22%|81.07%|81.50%|[model](https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_medium_2xb6-120k_1024x1024-cityscapes.pdparams)|
24+
|PIDNet|PIDNet-Large |1024x1024|120000|80.89%|81.41%|81.92%|[model](https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_large_2xb6-120k_1024x1024-cityscapes.pdparams)|
25+
26+
27+
#### NOTE:
28+
29+
The `weight` in the training parameters is dataset dependent, if you are using another dataset, modify the weight please.
30+
31+
``` yaml
32+
# follow the OCNet, compute the weights by 1/log(pixel_count)
33+
# see https://github.com/openseg-group/OCNet.pytorch/issues/14
34+
weight: &weight [0.8373, 0.9180, 0.8660, 1.0345, 1.0166, 0.9969, 0.9754,
35+
1.0489, 0.8786, 1.0023, 0.9539, 0.9843, 1.1116, 0.9037,
36+
1.0865, 1.0955, 1.0865, 1.1529, 1.0507]
37+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_base_: 'pidnet_small_cityscapes_1024x1024_120k.yml'
2+
3+
model:
4+
head_channels: 256
5+
backbone:
6+
type: PIDNet_Large
7+
pretrained: https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_large_imagenet1k.pdparams
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_base_: 'pidnet_small_cityscapes_1024x1024_120k.yml'
2+
3+
model:
4+
backbone:
5+
type: PIDNet_Medium
6+
pretrained: https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_medium_imagenet1k.pdparams
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
_base_: '../_base_/cityscapes_1024x1024.yml'
2+
3+
batch_size: 6 # total batch size is 12
4+
iters: 120000 # 484 epochs
5+
6+
mean: &mean [0.485, 0.456, 0.406]
7+
std: &std [0.229, 0.224, 0.225]
8+
9+
# follow the OCNet, compute the weights by 1/log(pixel_count)
10+
# see https://github.com/openseg-group/OCNet.pytorch/issues/14
11+
weight: &weight [0.8373, 0.9180, 0.8660, 1.0345, 1.0166, 0.9969, 0.9754,
12+
1.0489, 0.8786, 1.0023, 0.9539, 0.9843, 1.1116, 0.9037,
13+
1.0865, 1.0955, 1.0865, 1.1529, 1.0507]
14+
15+
model:
16+
type: PIDNet
17+
num_classes: 19
18+
head_channels: 128
19+
backbone:
20+
type: PIDNet_Small
21+
pretrained: https://paddleseg.bj.bcebos.com/dygraph/pidnet/pidnet_small_imagenet1k.pdparams
22+
23+
train_dataset:
24+
transforms:
25+
- type: AddEdgeLabel
26+
- type: ResizeStepScaling
27+
min_scale_factor: 0.5
28+
max_scale_factor: 2.1
29+
scale_step_size: 0.1
30+
- type: RandomPaddingCrop
31+
crop_size: [1024, 1024]
32+
- type: RandomHorizontalFlip
33+
- type: Normalize
34+
mean: *mean
35+
std: *std
36+
37+
val_dataset:
38+
transforms:
39+
- type: Normalize
40+
mean: *mean
41+
std: *std
42+
43+
optimizer:
44+
weight_decay: 0.0005
45+
46+
loss:
47+
types:
48+
- type: CrossEntropyLoss
49+
weight: *weight
50+
avg_non_ignore: False
51+
- type: OhemCrossEntropyLoss
52+
weight: *weight
53+
min_kept: 131072
54+
thresh: 0.9
55+
- type: BCELoss
56+
weight: dynamic
57+
edge_label: True
58+
- type: OhemCrossEntropyLoss
59+
weight: *weight
60+
min_kept: 131072
61+
thresh: 0.9
62+
coef: [0.4, 1.0, 10.0, 1.0]

paddleseg/datasets/dataset.py

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def __getitem__(self, idx):
165165
edge_mask = F.mask_to_binary_edge(
166166
data['label'], radius=2, num_classes=self.num_classes)
167167
data['edge'] = edge_mask
168+
elif 'edge' in data: # for AddEdgeLabel
169+
# F.mask_to_binary_edge is so slow
170+
# AddEdgeLabel will faster
171+
# But offline generation of edges might be better
172+
data['edge'][data['edge'] == self.ignore_index] = 0
168173
return data
169174

170175
def __len__(self):

paddleseg/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@
7575
from .segnext import SegNeXt
7676
from .knet import KNet
7777
from .pp_mobileseg import PPMobileSeg
78+
from .pidnet import PIDNet

paddleseg/models/backbones/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
from .vit_adapter import *
3434
from .mscan import *
3535
from .seaformer import *
36+
from .pidnet import *

0 commit comments

Comments
 (0)