Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Add training part of PSPNet #634

Merged
merged 42 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1bacd45
add train
yuyu2172 Jun 1, 2018
5837310
add imagenet option to pretrained model
yuyu2172 Nov 23, 2018
32a7137
add imagenet support
yuyu2172 Nov 26, 2018
64bec89
add PSPNetResNet50
yuyu2172 Nov 26, 2018
77ecaf8
add eval_ade20k
yuyu2172 Nov 26, 2018
6cce889
delete eval_ade20k
yuyu2172 Dec 5, 2018
9700b6f
train_multi
yuyu2172 Dec 5, 2018
1b7e96f
merge
yuyu2172 Dec 5, 2018
1c50763
Merge remote-tracking branch 'yuyu2172/rotate-cv' into resnet-train
yuyu2172 Dec 5, 2018
e1ddd2d
fix train_multi
yuyu2172 Dec 5, 2018
570f2ed
Merge branch 'psp-50' into resnet-train
yuyu2172 Dec 5, 2018
3e8578d
delete polynomial_shift
yuyu2172 Dec 5, 2018
7482797
Merge remote-tracking branch 'yuyu2172/psp-50' into HEAD
yuyu2172 Dec 5, 2018
aa64842
update train
yuyu2172 Dec 5, 2018
885fd08
no weight decay for bn beta and gamma
yuyu2172 Dec 5, 2018
14c4bdd
fix
yuyu2172 Dec 5, 2018
f361c57
Merge remote-tracking branch 'yuyu2172/rotate-cv' into HEAD
yuyu2172 Dec 5, 2018
91ea07f
fix
yuyu2172 Dec 5, 2018
59b1615
Merge remote-tracking branch 'origin/master' into pspnet-train
yuyu2172 Dec 6, 2018
378c3ca
fix
yuyu2172 Dec 7, 2018
d8743d9
gradient scale layers that are not pretrained
yuyu2172 Dec 8, 2018
8f72cb7
fix validation score
yuyu2172 Dec 8, 2018
b219f5f
Merge remote-tracking branch 'yuyu2172/pspnet-train' into HEAD
yuyu2172 Dec 8, 2018
30d7473
add weight decay to aux convs
yuyu2172 Dec 9, 2018
1e9953d
Merge branch 'pspnet-train' of https://github.com/yuyu2172/chainercv …
yuyu2172 Dec 9, 2018
92a6fc3
fix arg order
yuyu2172 Dec 17, 2018
868dd6f
add cityscapes weights
yuyu2172 Dec 19, 2018
12b27c6
Merge remote-tracking branch 'yuyu2172/simplify-camvid' into HEAD
yuyu2172 Dec 19, 2018
dd1f730
update README
yuyu2172 Dec 19, 2018
8b3230e
flake8
yuyu2172 Dec 19, 2018
b60f3f5
fix README
yuyu2172 Dec 19, 2018
b70256c
Merge remote-tracking branch 'yuyu2172/ade20k-change-label' into pspn…
yuyu2172 Dec 20, 2018
abebe87
Merge remote-tracking branch 'yuyu2172/pspnet-train' into pspnet-train
yuyu2172 Dec 20, 2018
b9c5570
delete ignore_label option
yuyu2172 Dec 20, 2018
c5788af
Merge remote-tracking branch 'yuyu2172/simplify-camvid' into HEAD
yuyu2172 Dec 23, 2018
cf6d8da
add ade20k trained weights and fix tests
yuyu2172 Dec 23, 2018
cf2678e
Merge remote-tracking branch 'origin/master' into HEAD
yuyu2172 Jan 17, 2019
b139a60
add test_train_multi.py
yuyu2172 Jan 25, 2019
f43f891
support resnet101 in the test
yuyu2172 Jan 25, 2019
96c30e5
add ade20k description to the doc
yuyu2172 Feb 6, 2019
405b0af
remove cv2 workaround
yuyu2172 Feb 6, 2019
542ec0d
Merge remote-tracking branch 'origin/master' into pspnet-train
yuyu2172 Feb 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ADE20KSemanticSegmentationDataset(GetterDataset):
:obj:`img`, ":math:`(3, H, W)`", :obj:`float32`, \
"RGB, :math:`[0, 255]`"
:obj:`label`, ":math:`(H, W)`", :obj:`int32`, \
":math:`[0, \#class - 1]`"
":math:`[-1, \#class - 1]`"
"""

def __init__(self, data_dir='auto', split='train'):
Expand Down Expand Up @@ -72,5 +72,7 @@ def _get_image(self, i):
return read_image(self.img_paths[i])

def _get_label(self, i):
return read_image(
label = read_image(
self.label_paths[i], dtype=np.int32, color=False)[0]
# [-1, n_class - 1]
return label - 1
2 changes: 0 additions & 2 deletions chainercv/datasets/ade20k/ade20k_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get_ade20k(root, url):


ade20k_semantic_segmentation_label_names = (
'other_objects',
'wall',
'edifice',
'sky',
Expand Down Expand Up @@ -171,7 +170,6 @@ def get_ade20k(root, url):
)

ade20k_semantic_segmentation_label_colors = (
(0, 0, 0),
(120, 120, 120),
(180, 120, 120),
(6, 230, 230),
Expand Down
19 changes: 17 additions & 2 deletions chainercv/experimental/links/model/pspnet/pspnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,13 @@ class PSPNetResNet101(PSPNet):
_models = {
'cityscapes': {
'param': {'n_class': 19, 'input_size': (713, 713)},
'url': 'https://github.com/yuyu2172/share-weights/releases/'
'download/0.0.6/pspnet_resnet101_cityscapes_convert_2018_05_22.npz'
'url': 'https://chainercv-models.preferred.jp/'
'pspnet_resnet101_cityscapes_trained_2018_12_19.npz',
},
'ade20k': {
'param': {'n_class': 150, 'input_size': (473, 473)},
'url': 'https://chainercv-models.preferred.jp/'
'pspnet_resnet101_ade20k_trained_2018_12_23.npz',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about updating this block?

* :obj:`'cityscapes'`: Load weights trained on the train split of \
Cityscapes dataset. \
:obj:`n_class` must be :obj:`19` or :obj:`None`.
* :obj:`'imagenet'`: Load ImageNet pretrained weights for \
the extractor.
* `filepath`: A path of npz file. In this case, :obj:`n_class` \
must be specified properly.
* :obj:`None`: Do not load weights.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

},
}

Expand All @@ -324,6 +329,16 @@ class PSPNetResNet50(PSPNet):
_extractor_kwargs = {'n_layer': 50}
_extractor_pick = ('res4', 'res5')
_models = {
'cityscapes': {
'param': {'n_class': 19, 'input_size': (713, 713)},
'url': 'https://chainercv-models.preferred.jp/'
'pspnet_resnet50_cityscapes_trained_2018_12_19.npz',
},
'ade20k': {
'param': {'n_class': 150, 'input_size': (473, 473)},
'url': 'https://chainercv-models.preferred.jp/'
'pspnet_resnet50_ade20k_trained_2018_12_23.npz',
},
}


Expand Down
58 changes: 47 additions & 11 deletions examples/pspnet/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
# Examples of Pyramid Scene Parsing Network (PSPNet)

## Performance
## Demo
This demo downloads a pretrained model automatically if a pretrained model path is not given.
```
$ python demo.py [--gpu <gpu>] [--pretrained-model <model_path>] [--input-size <size>] <image>.jpg
```

## Weight Covnersion

Convert `*.caffemodel` to `*.npz`. Some layers are renamed to fit ChainerCV.
```
$ python caffe2npz.py <source>.caffemodel <target>.npz
```

The converted weight can be downloaded from [here](https://chainercv-models.preferred.jp/pspnet_resnet101_cityscapes_converted_2018_05_22.npz).

The performance on the Cityscapes dataset is as follows with single scale inference.
Scores are measured by mean Intersection over Union (mIoU).

| Model | Reference | ChainerCV (weight conversion) |
|:-:|:-:|:-:|
| Cityscapes (single scale) | 79.70 % [1] | 79.03 % |

Scores are measured by mean Intersection over Union (mIoU).
## Training model

The model can be trained with a script `train_mutli.py`.

### Cityscapes

The following table shows the performance of the models trained with our scripts.

| Base model | Training Data | Reference | ChainerCV |
|:-:|:-:|:-:|:-:|
| Dilated ResNet50 | fine only (3K) | 76.9 % [2] | 73.99 % |
| Dilated ResNet101 | fine only (3K) | 77.9 % [2] | 76.01 % |

Here are the commands used to train the models included in the table.

## Demo
This demo downloads Cityscapes pretrained model automatically if a pretrained model path is not given.
```
$ python demo.py [--gpu <gpu>] [--pretrained-model <model_path>] [--input-size <size>] <image>.jpg
$ mpiexec -n 8 python3 train_multi.py --dataset cityscapes --model pspnet_resnet50 --iteration 90000
$ mpiexec -n 8 python3 train_multi.py --dataset cityscapes --model pspnet_resnet101 --iteration 90000
```

### ADE20K

The following table shows the performance of the models trained with our scripts.

| Base model | Reference | ChainerCV |
|:-:|:-:|:-:|
| Dilated ResNet50 | 41.68 % [1] | 34.97 % |
| Dilated ResNet101 | | 36.55 % |

Here are the commands used to train the models included in the table.

## Convert Caffe model
Convert `*.caffemodel` to `*.npz`. Some layers are renamed to fit ChainerCV.
```
$ python caffe2npz.py <source>.caffemodel <target>.npz
$ mpiexec -n 8 python3 train_multi.py --dataset ade20k --model pspnet_resnet50 --iteration 150000
$ mpiexec -n 8 python3 train_multi.py --dataset ade20k --model pspnet_resnet101 --iteration 150000
```


## Evaluation
The evaluation can be conducted using [`chainercv/examples/semantic_segmentation/eval_cityscapes.py`](https://github.com/chainer/chainercv/blob/master/examples/semantic_segmentation).
The evaluation can be conducted using [`chainercv/examples/semantic_segmentation/eval_semantic_segmentation.py`](https://github.com/chainer/chainercv/blob/master/examples/semantic_segmentation).


## References
1. Hengshuang Zhao et al. "Pyramid Scene Parsing Network" CVPR 2017.
2. [chainer-pspnet by mitmul](https://github.com/mitmul/chainer-pspnet)
2. https://github.com/holyseven/PSPNet-TF-Reproduce (Validation scores for Cityscapes are lacking in the original paper)
3. [chainer-pspnet by mitmul](https://github.com/mitmul/chainer-pspnet)
Loading