Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a improvement slightweight segmentation #190

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8a8b0db
Add files via upload
Jeralyn123 Mar 21, 2022
c63d50a
Update train.py
Jeralyn123 Mar 21, 2022
121740d
Update demo.py
Jeralyn123 Mar 21, 2022
255a22c
Add files via upload
Jeralyn123 Mar 21, 2022
768a6aa
Update train.py
Jeralyn123 Mar 21, 2022
19b7313
Delete cgnet.py
Jeralyn123 Mar 21, 2022
bbbc65e
Delete bisenet.py
Jeralyn123 Mar 21, 2022
55547a0
Delete segbase.py
Jeralyn123 Mar 21, 2022
e54000d
Delete danet.py
Jeralyn123 Mar 21, 2022
8f13f1b
Delete deeplabv3.py
Jeralyn123 Mar 21, 2022
eee940d
Delete deeplabv3_plus.py
Jeralyn123 Mar 21, 2022
7ce10de
Delete dfanet.py
Jeralyn123 Mar 21, 2022
e50d41a
Delete denseaspp.py
Jeralyn123 Mar 21, 2022
ec2080d
Delete dunet.py
Jeralyn123 Mar 21, 2022
7fe4ce2
Delete encnet.py
Jeralyn123 Mar 21, 2022
5b3824b
Delete enet.py
Jeralyn123 Mar 21, 2022
dbbbbd2
Delete ocnet.py
Jeralyn123 Mar 21, 2022
718b964
Delete pspnet.py
Jeralyn123 Mar 21, 2022
2a70666
Delete psanet.py
Jeralyn123 Mar 21, 2022
36b45a0
Delete lednet.py
Jeralyn123 Mar 21, 2022
584b3c3
Delete espnet.py
Jeralyn123 Mar 21, 2022
5da5d7a
Delete hrnet.py
Jeralyn123 Mar 21, 2022
c36dbda
Delete icnet.py
Jeralyn123 Mar 21, 2022
46fe834
Update swnet.py
Jeralyn123 Mar 21, 2022
a43458d
Update swnet.py
Jeralyn123 Mar 21, 2022
99e43f2
Update README.md
Jeralyn123 Mar 21, 2022
87950c3
Update README.md
Jeralyn123 Mar 21, 2022
3d520ad
Update README.md
Jeralyn123 Mar 21, 2022
d5da0b6
Delete fcn32s_vgg16_pascal_voc.sh
Jeralyn123 Mar 21, 2022
4a20b69
Delete fcn32s_vgg16_pascal_voc_dist.sh
Jeralyn123 Mar 21, 2022
ce0a81a
Update README.md
Jeralyn123 Mar 21, 2022
2bbc28e
Update README.md
Jeralyn123 Mar 21, 2022
d8a04b9
Update README.md
Jeralyn123 Mar 21, 2022
db62d62
Update README.md
Jeralyn123 Mar 21, 2022
d29da72
Update README.md
Jeralyn123 Mar 21, 2022
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
224 changes: 30 additions & 194 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,213 +1,49 @@
# Semantic Segmentation on PyTorch

English | [简体中文](/README_zh-CN.md)

[![python-image]][python-url]
[![pytorch-image]][pytorch-url]
[![lic-image]][lic-url]
# slightweight Segmentation

This project aims at providing a concise, easy-to-use, modifiable reference implementation for semantic segmentation models using PyTorch.

<p align="center"><img width="100%" src="docs/weimar_000091_000019_gtFine_color.png" /></p>
stage 1: # Installation

## Installation

```
# semantic-segmentation-pytorch dependencies
stage 2: # dependencies
pip install ninja tqdm

# follow PyTorch installation in https://pytorch.org/get-started/locally/
stage 3: # follow PyTorch installation in https://pytorch.org/get-started/locally/
conda install pytorch torchvision -c pytorch

# install PyTorch Segmentation
git clone https://github.com/Tramac/awesome-semantic-segmentation-pytorch.git
```

## Usage
### Train
-----------------
- **Single GPU training**
```
# for example, train fcn32_vgg16_pascal_voc:
python train.py --model fcn32s --backbone vgg16 --dataset pascal_voc --lr 0.0001 --epochs 50
```
- **Multi-GPU training**

```
# for example, train fcn32_vgg16_pascal_voc with 4 GPUs:
export NGPUS=4
python -m torch.distributed.launch --nproc_per_node=$NGPUS train.py --model fcn32s --backbone vgg16 --dataset pascal_voc --lr 0.0001 --epochs 50
```

### Evaluation
-----------------
- **Single GPU evaluating**
```
# for example, evaluate fcn32_vgg16_pascal_voc
python eval.py --model fcn32s --backbone vgg16 --dataset pascal_voc
```
- **Multi-GPU evaluating**
```
# for example, evaluate fcn32_vgg16_pascal_voc with 4 GPUs:
export NGPUS=4
python -m torch.distributed.launch --nproc_per_node=$NGPUS eval.py --model fcn32s --backbone vgg16 --dataset pascal_voc
```
stage 4: # for example, train swnet_resnet_citys:
python train.py --model swnet --backbone resnet --dataset citys --lr 0.0001 --epochs 50


stage 5: # for example, evaluate swnet_resnet_citys
python eval.py --model swnet --backbone resnet --dataset citys

### Demo
```

cd ./scripts
#for new users:
python demo.py --model fcn32s_vgg16_voc --input-pic ../tests/test_img.jpg
python demo.py --model swnet_resnet_citys --input-pic ../tests/test_img.jpg
#you should add 'test.jpg' by yourself
python demo.py --model fcn32s_vgg16_voc --input-pic ../datasets/test.jpg
```

```
.{SEG_ROOT}
├── scripts
│   ├── demo.py
│   ├── eval.py
│   └── train.py
```

## Support

#### Model

- [FCN](https://arxiv.org/abs/1411.4038)
- [ENet](https://arxiv.org/pdf/1606.02147)
- [PSPNet](https://arxiv.org/pdf/1612.01105)
- [ICNet](https://arxiv.org/pdf/1704.08545)
- [DeepLabv3](https://arxiv.org/abs/1706.05587)
- [DeepLabv3+](https://arxiv.org/pdf/1802.02611)
- [DenseASPP](http://openaccess.thecvf.com/content_cvpr_2018/papers/Yang_DenseASPP_for_Semantic_CVPR_2018_paper.pdf)
- [EncNet](https://arxiv.org/abs/1803.08904v1)
- [BiSeNet](https://arxiv.org/abs/1808.00897)
- [PSANet](https://hszhao.github.io/papers/eccv18_psanet.pdf)
- [DANet](https://arxiv.org/pdf/1809.02983)
- [OCNet](https://arxiv.org/pdf/1809.00916)
- [CGNet](https://arxiv.org/pdf/1811.08201)
- [ESPNetv2](https://arxiv.org/abs/1811.11431)
- [DUNet(DUpsampling)](https://arxiv.org/abs/1903.02120)
- [FastFCN(JPU)](https://arxiv.org/abs/1903.11816)
- [LEDNet](https://arxiv.org/abs/1905.02423)
- [Fast-SCNN](https://github.com/Tramac/Fast-SCNN-pytorch)
- [LightSeg](https://github.com/Tramac/Lightweight-Segmentation)
- [DFANet](https://arxiv.org/abs/1904.02216)

[DETAILS](https://github.com/Tramac/awesome-semantic-segmentation-pytorch/blob/master/docs/DETAILS.md) for model & backbone.
```
.{SEG_ROOT}
├── core
│   ├── models
│   │   ├── bisenet.py
│   │   ├── danet.py
│   │   ├── deeplabv3.py
│ │ ├── deeplabv3+.py
│   │   ├── denseaspp.py
│   │   ├── dunet.py
│   │   ├── encnet.py
│   │   ├── fcn.py
│   │   ├── pspnet.py
│   │   ├── icnet.py
│   │   ├── enet.py
│   │   ├── ocnet.py
│   │   ├── psanet.py
│   │   ├── cgnet.py
│   │   ├── espnet.py
│   │   ├── lednet.py
│   │   ├── dfanet.py
│   │   ├── ......
```
python demo.py --model swnet_resnet_citys --input-pic ../datasets/test.jpg

### performance evaluation

![image](https://user-images.githubusercontent.com/43395674/159203398-86f4874e-7b0f-48a3-8414-cdf662d56f99.png)
![image](https://user-images.githubusercontent.com/43395674/159203405-7b656176-2e93-4d67-98e6-6d650204b0d6.png)

![image](https://user-images.githubusercontent.com/43395674/159203470-99a509cc-68cc-4fa4-be65-43e0c9204cb1.png)
![image](https://user-images.githubusercontent.com/43395674/159203480-10ff8f81-965f-419c-ab98-83fade7b3b65.png)

### a experiment on a simulative scene based on Jetson
![image](https://user-images.githubusercontent.com/43395674/159203486-19980424-c6c4-4644-a44b-9f52085b2067.png)


#### Dataset

You can run script to download dataset, such as:

```

cd ./core/data/downloader
python ade20k.py --download-dir ../datasets/ade
```

| Dataset | training set | validation set | testing set |
| :----------------------------------------------------------: | :----------: | :------------: | :---------: |
| [VOC2012](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar) | 1464 | 1449 | ✘ |
| [VOCAug](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz) | 11355 | 2857 | ✘ |
| [ADK20K](http://groups.csail.mit.edu/vision/datasets/ADE20K/) | 20210 | 2000 | ✘ |
| [Cityscapes](https://www.cityscapes-dataset.com/downloads/) | 2975 | 500 | ✘ |
| [COCO](http://cocodataset.org/#download) | | | |
| [SBU-shadow](http://www3.cs.stonybrook.edu/~cvl/content/datasets/shadow_db/SBU-shadow.zip) | 4085 | 638 | ✘ |
| [LIP(Look into Person)](http://sysu-hcp.net/lip/) | 30462 | 10000 | 10000 |

```
.{SEG_ROOT}
├── core
│   ├── data
│   │   ├── dataloader
│   │   │   ├── ade.py
│   │   │   ├── cityscapes.py
│   │   │   ├── mscoco.py
│   │   │   ├── pascal_aug.py
│   │   │   ├── pascal_voc.py
│   │   │   ├── sbu_shadow.py
│   │   └── downloader
│   │   ├── ade20k.py
│   │   ├── cityscapes.py
│   │   ├── mscoco.py
│   │   ├── pascal_voc.py
│   │   └── sbu_shadow.py
```

## Result
- **PASCAL VOC 2012**

|Methods|Backbone|TrainSet|EvalSet|crops_size|epochs|JPU|Mean IoU|pixAcc|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|FCN32s|vgg16|train|val|480|60|✘|47.50|85.39|
|FCN16s|vgg16|train|val|480|60|✘|49.16|85.98|
|FCN8s|vgg16|train|val|480|60|✘|48.87|85.02|
|FCN32s|resnet50|train|val|480|50|✘|54.60|88.57|
|PSPNet|resnet50|train|val|480|60|✘|63.44|89.78|
|DeepLabv3|resnet50|train|val|480|60|✘|60.15|88.36|

Note: `lr=1e-4, batch_size=4, epochs=80`.

## Overfitting Test
See [TEST](https://github.com/Tramac/Awesome-semantic-segmentation-pytorch/tree/master/tests) for details.

```
.{SEG_ROOT}
├── tests
│   └── test_model.py
```

## To Do
- [x] add train script
- [ ] remove syncbn
- [ ] train & evaluate
- [x] test distributed training
- [x] fix syncbn ([Why SyncBN?](https://tramac.github.io/2019/02/25/%E8%B7%A8%E5%8D%A1%E5%90%8C%E6%AD%A5%20Batch%20Normalization[%E8%BD%AC]/))
- [x] add distributed ([How DIST?]("https://tramac.github.io/2019/03/06/%E5%88%86%E5%B8%83%E5%BC%8F%E8%AE%AD%E7%BB%83-PyTorch/"))
<!--
- [x] fix syncbn ([Why SyncBN?](https://tramac.github.io/2019/04/08/SyncBN/))
- [x] add distributed ([How DIST?](https://tramac.github.io/2019/04/22/%E5%88%86%E5%B8%83%E5%BC%8F%E8%AE%AD%E7%BB%83-PyTorch/))
-->
## References
- [PyTorch-Encoding](https://github.com/zhanghang1989/PyTorch-Encoding)
- [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark)
- [gloun-cv](https://github.com/dmlc/gluon-cv)
- [imagenet](https://github.com/pytorch/examples/tree/master/imagenet)



<!--
[![python-image]][python-url]
[![pytorch-image]][pytorch-url]
[![lic-image]][lic-url]
-->

[python-image]: https://img.shields.io/badge/Python-2.x|3.x-ff69b4.svg
[python-url]: https://www.python.org/
[pytorch-image]: https://img.shields.io/badge/PyTorch-1.1-2BAF2B.svg
[pytorch-url]: https://pytorch.org/
[lic-image]: https://img.shields.io/badge/Apache-2.0-blue.svg
[lic-url]: https://github.com/Tramac/Awesome-semantic-segmentation-pytorch/blob/master/LICENSE

Acknowledgement: we thanks the code support from "awesome-semantic-segmentation-pytorch (https://github.com/Tramac/Awesome-semantic-segmentation-pytorch)". The swnet is a improvement from enet.

Loading