交通事故检测代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # Rethinking BiSeNet For Real-time Semantic Segmentation[[PDF](https://openaccess.thecvf.com/content/CVPR2021/papers/Fan_Rethinking_BiSeNet_for_Real-Time_Semantic_Segmentation_CVPR_2021_paper.pdf)]
  2. [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
  3. Mingyuan Fan, Shenqi Lai, Junshi Huang, Xiaoming Wei, Zhenhua Chai, Junfeng Luo, Xiaolin Wei
  4. In CVPR 2021.
  5. ## Overview
  6. <p align="center">
  7. <img src="images/overview-of-our-method.png" alt="overview-of-our-method" width="600"/></br>
  8. <span align="center">Speed-Accuracy performance comparison on the Cityscapes test set</span>
  9. </p>
  10. We present STDC-Seg, an mannully designed semantic segmentation network with not only state-of-the-art performance but also faster speed than current methods.
  11. Highlights:
  12. * **Short-Term Dense Concatenation Net**: A task-specific network for dense prediction task.
  13. * **Detail Guidance**: encode spatial information without harming inference speed.
  14. * **SOTA**: STDC-Seg achieves extremely fast speed (over 45\% faster than the closest automatically designed competitor on CityScapes) and maintains competitive accuracy.
  15. - see our Cityscapes test set submission [STDC1-Seg50](https://www.cityscapes-dataset.com/anonymous-results/?id=805e22f63fc53d1d0726cefdfe12527275afeb58d7249393bec6f483c3342b3b) [STDC1-Seg75](https://www.cityscapes-dataset.com/anonymous-results/?id=6bd0def75600fd0f1f411101fe2bbb0a2be5dba5c74e2f7d7f50eecc23bae64c) [STDC2-Seg50](https://www.cityscapes-dataset.com/anonymous-results/?id=b009a595f0d4e10a7f10ac25f29962b67995dc11b059f0c733ddd212a56b9ee0) [STDC2-Seg75](https://www.cityscapes-dataset.com/anonymous-results/?id=9012a16cdeb9d52aaa9ad5fb9cc1c6284efe8a3daecee85b4413284364ff3f45).
  16. - Here is our speed-accuracy comparison on Cityscapes test&val set.
  17. <p align="center">
  18. <img src="images/comparison-cityscapes.png" alt="Cityscapes" width="400"/></br>
  19. </p>
  20. ## Methods
  21. <p align="center">
  22. <img src="images/stdc-architecture.png" alt="stdc-architecture" width="600"/></br>
  23. </p>
  24. <p align="center">
  25. <img src="images/stdcseg-architecture.png" alt="stdcseg-artchitecture" width="800"/></br>
  26. <span align="center">Overview of the STDC Segmentation network</span>
  27. </p>
  28. ## Prerequisites
  29. - Pytorch 1.1
  30. - Python 3.5.6
  31. - NVIDIA GPU
  32. - TensorRT v5.1.5.0 (Only need for testing inference speed)
  33. This repository has been trained on Tesla V100. Configurations (e.g batch size, image patch size) may need to be changed on different platforms. Also, for fair competition, we test the inference speed on NVIDIA GTX 1080Ti.
  34. ## Installation
  35. * Clone this repo:
  36. ```bash
  37. git clone https://github.com/MichaelFan01/STDC-Seg.git
  38. cd STDC-Seg
  39. ```
  40. * Install dependencies:
  41. ```bash
  42. pip install -r requirements.txt
  43. ```
  44. * Install [PyCuda](https://wiki.tiker.net/PyCuda/Installation) which is a dependency of TensorRT.
  45. * Install [TensorRT](https://github.com/NVIDIA/TensorRT) (v5.1.5.0): a library for high performance inference on NVIDIA GPUs with [Python API](https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/index.html#python).
  46. ## Usage
  47. ### 0. Prepare the dataset
  48. * Download the [leftImg8bit_trainvaltest.zip](https://www.cityscapes-dataset.com/file-handling/?packageID=3) and [gtFine_trainvaltest.zip](https://www.cityscapes-dataset.com/file-handling/?packageID=1) from the Cityscapes.
  49. * Link data to the `data` dir.
  50. ```bash
  51. ln -s /path_to_data/cityscapes/gtFine data/gtFine
  52. ln -s /path_to_data/leftImg8bit data/leftImg8bit
  53. ```
  54. ### 1. Train STDC-Seg
  55. Note: Backbone STDCNet813 denotes STDC1, STDCNet1446 denotes STDC2.
  56. * Train STDC1Seg:
  57. ```bash
  58. export CUDA_VISIBLE_DEVICES=0,1,2
  59. python -m torch.distributed.launch \
  60. --nproc_per_node=3 train.py \
  61. --respath checkpoints/train_STDC1-Seg/ \
  62. --backbone STDCNet813 \
  63. --mode train \
  64. --n_workers_train 12 \
  65. --n_workers_val 1 \
  66. --max_iter 60000 \
  67. --use_boundary_8 True \
  68. --pretrain_path checkpoints/STDCNet813M_73.91.tar
  69. ```
  70. * Train STDC2Seg:
  71. ```bash
  72. export CUDA_VISIBLE_DEVICES=0,1,2
  73. python -m torch.distributed.launch \
  74. --nproc_per_node=3 train.py \
  75. --respath checkpoints/train_STDC2-Seg/ \
  76. --backbone STDCNet1446 \
  77. --mode train \
  78. --n_workers_train 12 \
  79. --n_workers_val 1 \
  80. --max_iter 60000 \
  81. --use_boundary_8 True \
  82. --pretrain_path checkpoints/STDCNet1446_76.47.tar
  83. ```
  84. We will save the model's params in model_maxmIOU50.pth for input resolution 512x1024,and model_maxmIOU75.pth for input resolution 768 x 1536.
  85. ImageNet Pretrained STDCNet Weights for training and Cityscapes trained STDC-Seg weights for evaluation:
  86. BaiduYun Link: https://pan.baidu.com/s/1OdMsuQSSiK1EyNs6_KiFIw Password: q7dt
  87. GoogleDrive Link:[https://drive.google.com/drive/folders/1wROFwRt8qWHD4jSo8Zu1gp1d6oYJ3ns1?usp=sharing](https://drive.google.com/drive/folders/1wROFwRt8qWHD4jSo8Zu1gp1d6oYJ3ns1?usp=sharing)
  88. ###
  89. ### 2. Evaluation
  90. Here we use our pretrained STDCSeg as an example for the evaluation.
  91. * Choose the evaluation model in evaluation.py:
  92. ```python
  93. #STDC1-Seg50 mIoU 0.7222
  94. evaluatev0('./checkpoints/STDC1-Seg/model_maxmIOU50.pth', dspth='./data', backbone='STDCNet813', scale=0.5,
  95. use_boundary_2=False, use_boundary_4=False, use_boundary_8=True, use_boundary_16=False)
  96. #STDC1-Seg75 mIoU 0.7450
  97. evaluatev0('./checkpoints/STDC1-Seg/model_maxmIOU75.pth', dspth='./data', backbone='STDCNet813', scale=0.75,
  98. use_boundary_2=False, use_boundary_4=False, use_boundary_8=True, use_boundary_16=False)
  99. #STDC2-Seg50 mIoU 0.7424
  100. evaluatev0('./checkpoints/STDC2-Seg/model_maxmIOU50.pth', dspth='./data', backbone='STDCNet1446', scale=0.5,
  101. use_boundary_2=False, use_boundary_4=False, use_boundary_8=True, use_boundary_16=False)
  102. #STDC2-Seg75 mIoU 0.7704
  103. evaluatev0('./checkpoints/STDC2-Seg/model_maxmIOU75.pth', dspth='./data', backbone='STDCNet1446', scale=0.75,
  104. use_boundary_2=False, use_boundary_4=False, use_boundary_8=True, use_boundary_16=False)
  105. ```
  106. * Start the evaluation process:
  107. ```bash
  108. CUDA_VISIBLE_DEVICES=0 python evaluation.py
  109. ```
  110. ### 3. Latency
  111. #### 3.0 Latency measurement tools
  112. * If you have successfully installed [TensorRT](https://github.com/chenwydj/FasterSeg#installation), you will automatically use TensorRT for the following latency tests (see [function](https://github.com/chenwydj/FasterSeg/blob/master/tools/utils/darts_utils.py#L167) here).
  113. * Otherwise you will be switched to use Pytorch for the latency tests (see [function](https://github.com/chenwydj/FasterSeg/blob/master/tools/utils/darts_utils.py#L184) here).
  114. #### 3.1 Measure the latency of the FasterSeg
  115. * Choose the evaluation model in run_latency:
  116. ```python
  117. # STDC1Seg-50 250.4FPS on NVIDIA GTX 1080Ti
  118. backbone = 'STDCNet813'
  119. methodName = 'STDC1-Seg'
  120. inputSize = 512
  121. inputScale = 50
  122. inputDimension = (1, 3, 512, 1024)
  123. # STDC1Seg-75 126.7FPS on NVIDIA GTX 1080Ti
  124. backbone = 'STDCNet813'
  125. methodName = 'STDC1-Seg'
  126. inputSize = 768
  127. inputScale = 75
  128. inputDimension = (1, 3, 768, 1536)
  129. # STDC2Seg-50 188.6FPS on NVIDIA GTX 1080Ti
  130. backbone = 'STDCNet1446'
  131. methodName = 'STDC2-Seg'
  132. inputSize = 512
  133. inputScale = 50
  134. inputDimension = (1, 3, 512, 1024)
  135. # STDC2Seg-75 97.0FPS on NVIDIA GTX 1080Ti
  136. backbone = 'STDCNet1446'
  137. methodName = 'STDC2-Seg'
  138. inputSize = 768
  139. inputScale = 75
  140. inputDimension = (1, 3, 768, 1536)
  141. ```
  142. * Run the script:
  143. ```bash
  144. CUDA_VISIBLE_DEVICES=0 python run_latency.py
  145. ```
  146. ## Citation
  147. ```
  148. @InProceedings{Fan_2021_CVPR,
  149. author = {Fan, Mingyuan and Lai, Shenqi and Huang, Junshi and Wei, Xiaoming and Chai, Zhenhua and Luo, Junfeng and Wei, Xiaolin},
  150. title = {Rethinking BiSeNet for Real-Time Semantic Segmentation},
  151. booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  152. month = {June},
  153. year = {2021},
  154. pages = {9716-9725}
  155. }
  156. ```
  157. ## Acknowledgement
  158. * Segmentation training and evaluation code from [BiSeNet](https://github.com/CoinCheung/BiSeNet).
  159. * Latency measurement from the [Faster-Seg](https://github.com/VITA-Group/FasterSeg).