Skip to content

Commit 9bf5107

Browse files
author
Tete Xiao
committed
update readme
1 parent 6324799 commit 9bf5107

File tree

1 file changed

+80
-77
lines changed

1 file changed

+80
-77
lines changed

README.md

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,135 +8,129 @@ https://github.com/CSAILVision/sceneparsing
88
Pretrained models can be found at:
99
http://sceneparsing.csail.mit.edu/model/
1010

11-
<img src="./teaser/validation_ADE_val_00000278.png" width="900"/>
12-
<img src="./teaser/validation_ADE_val_00001519.png" width="900"/>
11+
<img src="./teaser/ADE_val_00000045.png" width="900"/>
12+
<img src="./teaser/ADE_val_00001130.png" width="900"/>
1313
From left to right: Test Image, Ground Truth, Predicted Result
1414

15-
## Supported models:
15+
## Highlights
16+
17+
### Syncronized Batch Normalization on PyTorch
18+
This module differs from the built-in PyTorch BatchNorm as the mean and standard-deviation are reduced across all devices during training. For example, when one uses `nn.DataParallel` to wrap the network during training, PyTorch's implementation normalizes the tensor on each device using the statistics only on that device, which accelerated the computation and is also easy to implement, but the statistics might be inaccurate. Instead, in this synchronized version, the statistics will be computed over all training samples distributed on multiple devices.
19+
20+
The importance of synchronized batch normalization in object detection has been recently proved with a an extensive analysis in the paper [MegDet: A Large Mini-Batch Object Detector](https://arxiv.org/abs/1711.07240). And we empirically find that it is also important for segmentation.
21+
22+
The implementation is reasonable due to the following reasons:
23+
- This implementation is in pure-python. No C++ extra extension libs.
24+
- Easy to use.
25+
- It is completely compatible with PyTorch's implementation. Specifically, it uses unbiased variance to update the moving average, and use sqrt(max(var, eps)) instead of sqrt(var + eps).
26+
27+
***To the best knowledge, it is the first pure-python implementation of sync bn on PyTorch, and also the first one completely compatible with PyTorch. It is also efficient, only 20% to 30% slower than un-sync bn.*** We especially thank [Jiayuan Mao](http://vccy.xyz/) for his kind contributions. For more details about the implementation and usage, refer to [Synchronized-BatchNorm-PyTorch](https://github.com/vacancy/Synchronized-BatchNorm-PyTorch).
28+
29+
### Dynamic scales of input for training with multiple GPUs
30+
Different from image classification task, where the input images are resized to a certain scale such as 224x224 or 229x229, it is better for semantic segmentation and object detection networks that the aspect ratios of input images remain what they original are. It is not trivial on PyTorch, because the dataloader loads a pile of images first, then the `nn.DataParallel` module automatically splits them to multiple GPUs. That is, the images are concatenated first, then distributed. The concatenation, of course, requires the images to be of the same size.
31+
32+
Alternatively, we re-implement the `DataParallel` module, and make it support distributing data to multiple GPUs in python dict. You are free to put a lot of stuff in a dict. At the same time, the dataloader also operates differently. *Now the batch size of a dataloader always equals to the number of GPUs*, cause each elements will be sent to a GPU later. In this way, for example, if you'd like to put 2 images on each GPU, its the dataloader's job. We also need to make it compatible with the multi-processing. Note that the file index for the multi-processing dataloader is stored on the master process, which is in contradict to our goal that each worker maintains its own file list. So we use a trick that although the master process still gives dataloader an index for `__getitem__` function, we just ignore such request and send a random batch dict. Also, *the multiple workers forked by the dataloader all have the same seed*, you will find that multiple workers will yield exactly the same data, if we use the above-mentioned trick directly. Therefore, we add one line of code which sets the defaut seed for `numpy.random` before activating multiple worker in dataloader.
33+
34+
35+
## Supported models
1636
We split our models into encoder and decoder, where encoders are usually modified directly from classification networks, and decoders consist of final convolutions and upsampling.
1737

1838
Encoder:
19-
- vgg16_dilated8
20-
- vgg19_dilated8
21-
- resnet34_dilated16
22-
- resnet34_dilated8
2339
- resnet50_dilated16
2440
- resnet50_dilated8
2541

42+
***Coming soon***:
43+
- resnet101_dilated16
44+
- resnet101_dilated8
45+
2646
(resnetXX_dilatedYY: customized resnetXX with dilated convolutions, output feature map is 1/YY of input size.)
2747

2848
Decoder:
2949
- c1_bilinear (1 conv + bilinear upsample)
50+
- c1_bilinear_deepsup (c1_blinear + deep supervision trick)
3051
- psp_bilinear (pyramid pooling + bilinear upsample, see PSPNet paper for details)
52+
- psp_bilinear_deepsup (psp_bilinear + deep supervision trick)
53+
54+
***Coming soon***:
55+
- UPerNet based on Feature Pyramid Network (FPN) and Pyramid Pooling Module (PPM), with down-sampling rate of 4, 8 and 16. It doesn't need dilated convolution, a operator that is time-and-memory consuming. It is comparable or even better compared with pspnet *with bells and whistles*, while requires much shorter training time and less GPU memory.
3156

3257

3358
## Performance:
34-
IMPORTANT: One obstacle to a good dilated ResNet model is that batch normalization layers are usually not well trained with a small batch size (<16). Ideally, batch size >64 will get you the best results. In this repo, we trained customized ResNet on Places365 (will be automatically downloaded when needed) as the initialization for scene parsing model, which partly solved the problem. You can simply set ```--fix_bn 1``` to freeze BN parameters during training.
35-
36-
<table><tbody>
37-
<th valign="bottom">Encoder</th>
38-
<th valign="bottom">Decoder</th>
39-
<th valign="bottom">Mean IoU</th>
40-
<th valign="bottom">Pixel Accuracy</th>
41-
<tr>
42-
<td>resnet34_dilated8</td>
43-
<td>c1_bilinear</td>
44-
<td>0.3277</td>
45-
<td>76.47%</td>
46-
</tr>
47-
<tr>
48-
<td>resnet34_dilated8</td>
49-
<td>psp_bilinear</td>
50-
<td>0.3634</td>
51-
<td>77.98%</td>
52-
</tr>
53-
<tr>
54-
<td>resnet50_dilated8</td>
55-
<td>c1_bilinear</td>
56-
<td>0.3385</td>
57-
<td>76.40%</td>
58-
</tr>
59-
<tr>
60-
<td>resnet50_dilated8</td>
61-
<td>psp_bilinear</td>
62-
<td>0.3800</td>
63-
<td>78.21%</td>
64-
</tr>
65-
</tbody></table>
59+
IMPORTANT: We use our self-trained base model on ImageNet. The model takes the input in BGR form (consistent with opencv) instead of RGB form as used by default implementation of PyTorch. The base model will be automatically downloaded when needed.
60+
61+
### Main Results
62+
| | MS Test | Mean IoU | Accuracy | Overall | Training Time |
63+
|---------------|:----:|:----:|:-----:|:--------------:|:-------:|
64+
|ResNet-50_dilated8 + c1_bilinear_deepsup | No | - | - | - | 27.5 hours |
65+
|ResNet-50_dilated8 + psp_bilinear_deepsup | No | 40.60 | 79.66 | 60.13 | 33.4 hours |
66+
|Same as above | Yes | 41.31 | 80.14 | 60.73 | Same as above |
67+
|ResNet-101_dilated8 + c1_bilinear_deepsup | No | - | - | - | hours |
68+
|ResNet-101_dilated8 + psp_bilinear_deepsup | No | - | - | - | hours |
69+
|Same as above | Yes | - | - | - | Same as above |
70+
|UPerNet-50 (coming soon!) | No | - | - | - | hours |
71+
|UPerNet-50 (coming soon!) | Yes| - | - | - | Same as above |
72+
6673

6774
## Environment
6875
The code is developed under the following configurations.
6976
- Hardware: 2-8 Pascal Titan X GPUs (change ```[--num_gpus NUM_GPUS]``` accordingly)
70-
- Software: Ubuntu 14.04, CUDA8.0, Python2.7, PyTorch 0.2.0
77+
- Software: Ubuntu 16.04.3 LTS, CUDA 8.0, ***Python3.5***, ***PyTorch 0.4.0***
78+
79+
*Warning:* We don't support the outdated Python 2 anymore. PyTorch 0.4.0 or higher is required to run the codes.
7180

7281
## Training
7382
1. Download the ADE20K scene parsing dataset:
7483
```bash
7584
chmod +x download_ADE20K.sh
7685
./download_ADE20K.sh
7786
```
78-
2. Train a network (default: resnet34_dilated8). During training, checkpoints will be saved in folder ```ckpt```, visual results will be saved in folder ```vis```.
87+
2. Train a network (default: resnet50_dilated8_deepsup). During training, checkpoints will be saved in folder ```ckpt```.
7988
```bash
80-
python train.py
89+
python3 train.py
8190
```
8291

83-
3. Input arguments: (see full input arguments via ```python train.py -h ```)
92+
3. Input arguments: (see full input arguments via ```python3 train.py -h ```)
8493
```bash
8594
usage: train.py [-h] [--id ID] [--arch_encoder ARCH_ENCODER]
8695
[--arch_decoder ARCH_DECODER]
8796
[--weights_encoder WEIGHTS_ENCODER]
8897
[--weights_decoder WEIGHTS_DECODER] [--fc_dim FC_DIM]
8998
[--list_train LIST_TRAIN] [--list_val LIST_VAL]
90-
[--root_img ROOT_IMG] [--root_seg ROOT_SEG]
91-
[--num_gpus NUM_GPUS]
99+
[--root_dataset ROOT_DATASET] [--num_gpus NUM_GPUS]
92100
[--batch_size_per_gpu BATCH_SIZE_PER_GPU]
93-
[--num_epoch NUM_EPOCH] [--optim OPTIM]
94-
[--lr_encoder LR_ENCODER] [--lr_decoder LR_DECODER]
95-
[--beta1 BETA1]
96-
[--weight_decay WEIGHT_DECAY] [--fix_bn FIX_BN]
97-
[--num_val NUM_VAL] [--workers WORKERS] [--imgSize IMGSIZE]
98-
[--segSize SEGSIZE] [--num_class NUM_CLASS]
99-
[--seed SEED] [--ckpt CKPT] [--vis VIS]
100-
[--disp_iter DISP_ITER] [--eval_epoch EVAL_EPOCH]
101-
[--ckpt_epoch CKPT_EPOCH]
101+
[--num_epoch NUM_EPOCH] [--epoch_iters EPOCH_ITERS]
102+
[--optim OPTIM] [--lr_encoder LR_ENCODER]
103+
[--lr_decoder LR_DECODER] [--lr_pow LR_POW] [--beta1 BETA1]
104+
[--weight_decay WEIGHT_DECAY]
105+
[--deep_sup_scale DEEP_SUP_SCALE] [--fix_bn FIX_BN]
106+
[--num_class NUM_CLASS] [--workers WORKERS]
107+
[--imgSize IMGSIZE] [--imgMaxSize IMGMAXSIZE]
108+
[--padding_constant PADDING_CONSTANT]
109+
[--segm_downsampling_rate SEGM_DOWNSAMPLING_RATE]
110+
[--random_flip RANDOM_FLIP] [--seed SEED] [--ckpt CKPT]
111+
[--disp_iter DISP_ITER]
102112
```
103113

104114

105115
## Evaluation
106116
1. Evaluate a trained network on the validation set:
107117
```bash
108-
python eval.py --id MODEL_ID
118+
python3 eval.py --id MODEL_ID
109119
```
110120

111-
2. Input arguments: (see full input arguments via ```python eval.py -h ```)
121+
2. Input arguments: (see full input arguments via ```python3 eval.py -h ```)
112122
```bash
113123
usage: eval.py [-h] --id ID [--suffix SUFFIX] [--arch_encoder ARCH_ENCODER]
114124
[--arch_decoder ARCH_DECODER] [--fc_dim FC_DIM]
115-
[--list_val LIST_VAL] [--root_img ROOT_IMG]
116-
[--root_seg ROOT_SEG] [--num_val NUM_VAL]
125+
[--list_val LIST_VAL] [--root_dataset ROOT_DATASET]
126+
[--num_val NUM_VAL] [--num_class NUM_CLASS]
117127
[--batch_size BATCH_SIZE] [--imgSize IMGSIZE]
118-
[--segSize SEGSIZE] [--num_class NUM_CLASS] [--ckpt CKPT]
119-
[--visualize VISUALIZE] [--result RESULT]
128+
[--imgMaxSize IMGMAXSIZE] [--padding_constant PADDING_CONSTANT]
129+
[--segm_downsampling_rate SEGM_DOWNSAMPLING_RATE] [--ckpt CKPT]
130+
[--visualize VISUALIZE] [--result RESULT] [--gpu_id GPU_ID]
120131
```
121132

122133

123-
## Test/Inference
124-
1. Here is a simple demo to do inference on a single image:
125-
```bash
126-
chmod +x demo_test.sh
127-
./demo_test.sh
128-
```
129-
This script downloads pretrained models and a test image, runs the test script, and saves predicted segmentation (.png) to the working directory.
130-
131-
2. Input arguments: (see full input arguments via ```python test.py -h ```)
132-
```bash
133-
usage: test.py [-h] --test_img TEST_IMG --model_path MODEL_PATH
134-
[--suffix SUFFIX] [--result RESULT]
135-
[--arch_encoder ARCH_ENCODER] [--arch_decoder ARCH_DECODER]
136-
[--fc_dim FC_DIM] [--num_class NUM_CLASS] [--imgSize IMGSIZE]
137-
[--segSize SEGSIZE]
138-
```
139-
140134
## Reference
141135

142136
If you find the code or pre-trained models useful, please cite the following paper:
@@ -150,6 +144,15 @@ Scene Parsing through ADE20K Dataset. B. Zhou, H. Zhao, X. Puig, S. Fidler, A. B
150144
year={2017}
151145
}
152146

147+
Unified Perceptual Parsing for Scene Understanding. T. Xiao, Y. Liu, B. Zhou, Y. Jiang, and J. Sun. arXiv preprint
148+
149+
@article{xiao2018unified,
150+
title={Unified Perceptual Parsing for Scene Understanding},
151+
author={Xiao, Tete and Liu, Yingcheng and Zhou, Bolei and Jiang, Yuning and Sun, Jian},
152+
journal={arXiv preprint},
153+
year={2018}
154+
}
155+
153156
Semantic Understanding of Scenes through ADE20K Dataset. B. Zhou, H. Zhao, X. Puig, S. Fidler, A. Barriuso and A. Torralba. arXiv:1608.05442. (https://arxiv.org/pdf/1608.05442.pdf)
154157

155158
@article{zhou2016semantic,

0 commit comments

Comments
 (0)