You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 15 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. # Contents
  2. - [YOLOv3-DarkNet53-Quant Description](#yolov3-darknet53-quant-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Quick Start](#quick-start)
  7. - [Script Description](#script-description)
  8. - [Script and Sample Code](#script-and-sample-code)
  9. - [Script Parameters](#script-parameters)
  10. - [Training Process](#training-process)
  11. - [Training](#training)
  12. - [Distributed Training](#distributed-training)
  13. - [Evaluation Process](#evaluation-process)
  14. - [Evaluation](#evaluation)
  15. - [Model Description](#model-description)
  16. - [Performance](#performance)
  17. - [Evaluation Performance](#evaluation-performance)
  18. - [Inference Performance](#evaluation-performance)
  19. - [Description of Random Situation](#description-of-random-situation)
  20. - [ModelZoo Homepage](#modelzoo-homepage)
  21. # [YOLOv3-DarkNet53-Quant Description](#contents)
  22. You only look once (YOLO) is a state-of-the-art, real-time object detection system. YOLOv3 is extremely fast and accurate.
  23. Prior detection systems repurpose classifiers or localizers to perform detection. They apply the model to an image at multiple locations and scales. High scoring regions of the image are considered detections.
  24. YOLOv3 use a totally different approach. It apply a single neural network to the full image. This network divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities.
  25. YOLOv3 uses a few tricks to improve training and increase performance, including: multi-scale predictions, a better backbone classifier, and more. The full details are in the paper!
  26. In order to reduce the size of the weight and improve the low-bit computing performance, int8 quantization is used.
  27. [Paper](https://pjreddie.com/media/files/papers/YOLOv3.pdf): YOLOv3: An Incremental Improvement. Joseph Redmon, Ali Farhadi,
  28. University of Washington
  29. # [Model Architecture](#contents)
  30. YOLOv3 use DarkNet53 for performing feature extraction, which is a hybrid approach between the network used in YOLOv2, Darknet-19, and that newfangled residual network stuff. DarkNet53 uses successive 3 × 3 and 1 × 1 convolutional layers and has some shortcut connections as well and is significantly larger. It has 53 convolutional layers.
  31. # [Dataset](#contents)
  32. Dataset used: [COCO2014](https://cocodataset.org/#download)
  33. - Dataset size: 19G, 123,287 images, 80 object categories.
  34. - Train:13G, 82,783 images
  35. - Val:6GM, 40,504 images
  36. - Annotations: 241M, Train/Val annotations
  37. - Data format:zip files
  38. - Note:Data will be processed in yolo_dataset.py, and unzip files before uses it.
  39. # [Environment Requirements](#contents)
  40. - Hardware(Ascend)
  41. - Prepare hardware environment with Ascend processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
  42. - Framework
  43. - [MindSpore](https://www.mindspore.cn/install/en)
  44. - For more information, please check the resources below:
  45. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  46. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  47. # [Quick Start](#contents)
  48. After installing MindSpore via the official website, you can start training and evaluation in Ascend as follows:
  49. ```
  50. # The yolov3_darknet53_noquant.ckpt in the follow script is got from yolov3-darknet53 training like paper.
  51. # The parameter of resume_yolov3 is necessary.
  52. # The parameter of training_shape define image shape for network, default is "".
  53. # It means use 10 kinds of shape as input shape, or it can be set some kind of shape.
  54. # run training example(1p) by python command.
  55. python train.py \
  56. --data_dir=./dataset/coco2014 \
  57. --resume_yolov3=yolov3_darknet53_noquant.ckpt \
  58. --is_distributed=0 \
  59. --per_batch_size=16 \
  60. --lr=0.012 \
  61. --T_max=135 \
  62. --max_epoch=135 \
  63. --warmup_epochs=5 \
  64. --lr_scheduler=cosine_annealing > log.txt 2>&1 &
  65. # standalone training example(1p) by shell script
  66. sh run_standalone_train.sh dataset/coco2014 yolov3_darknet53_noquant.ckpt
  67. # distributed training example(8p) by shell script
  68. sh run_distribute_train.sh dataset/coco2014 yolov3_darknet53_noquant.ckpt rank_table_8p.json
  69. # run evaluation by python command
  70. python eval.py \
  71. --data_dir=./dataset/coco2014 \
  72. --pretrained=yolov3_quant.ckpt \
  73. --testing_shape=416 > log.txt 2>&1 &
  74. # run evaluation by shell script
  75. sh run_eval.sh dataset/coco2014/ checkpoint/yolov3_quant.ckpt 0
  76. ```
  77. # [Script Description](#contents)
  78. ## [Script and Sample Code](#contents)
  79. ```
  80. .
  81. └─yolov3_darknet53_quant
  82. ├─README.md
  83. ├─mindspore_hub_conf.md # config for mindspore hub
  84. ├─scripts
  85. ├─run_standalone_train.sh # launch standalone training(1p) in ascend
  86. ├─run_distribute_train.sh # launch distributed training(8p) in ascend
  87. └─run_eval.sh # launch evaluating in ascend
  88. ├─src
  89. ├─__init__.py # python init file
  90. ├─config.py # parameter configuration
  91. ├─darknet.py # backbone of network
  92. ├─distributed_sampler.py # iterator of dataset
  93. ├─initializer.py # initializer of parameters
  94. ├─logger.py # log function
  95. ├─loss.py # loss function
  96. ├─lr_scheduler.py # generate learning rate
  97. ├─transforms.py # Preprocess data
  98. ├─util.py # util function
  99. ├─yolo.py # yolov3 network
  100. ├─yolo_dataset.py # create dataset for YOLOV3
  101. ├─eval.py # eval net
  102. └─train.py # train net
  103. ```
  104. ## [Script Parameters](#contents)
  105. ```
  106. Major parameters in train.py as follow.
  107. optional arguments:
  108. -h, --help show this help message and exit
  109. --data_dir DATA_DIR Train dataset directory. Default: "".
  110. --per_batch_size PER_BATCH_SIZE
  111. Batch size for per device. Default: 16.
  112. --resume_yolov3 RESUME_YOLOV3
  113. The ckpt file of YOLOv3, which used to fine tune.
  114. Default: ""
  115. --lr_scheduler LR_SCHEDULER
  116. Learning rate scheduler, options: exponential,
  117. cosine_annealing. Default: exponential
  118. --lr LR Learning rate. Default: 0.012
  119. --lr_epochs LR_EPOCHS
  120. Epoch of changing of lr changing, split with ",".
  121. Default: 92, 105
  122. --lr_gamma LR_GAMMA Decrease lr by a factor of exponential lr_scheduler.
  123. Default: 0.1
  124. --eta_min ETA_MIN Eta_min in cosine_annealing scheduler. Default: 0
  125. --T_max T_MAX T-max in cosine_annealing scheduler. Default: 135
  126. --max_epoch MAX_EPOCH
  127. Max epoch num to train the model. Default: 135
  128. --warmup_epochs WARMUP_EPOCHS
  129. Warmup epochs. Default: 0
  130. --weight_decay WEIGHT_DECAY
  131. Weight decay factor. Default: 0.0005
  132. --momentum MOMENTUM Momentum. Default: 0.9
  133. --loss_scale LOSS_SCALE
  134. Static loss scale. Default: 1024
  135. --label_smooth LABEL_SMOOTH
  136. Whether to use label smooth in CE. Default:0
  137. --label_smooth_factor LABEL_SMOOTH_FACTOR
  138. Smooth strength of original one-hot. Default: 0.1
  139. --log_interval LOG_INTERVAL
  140. Logging interval steps. Default: 100
  141. --ckpt_path CKPT_PATH
  142. Checkpoint save location. Default: "outputs/"
  143. --ckpt_interval CKPT_INTERVAL
  144. Save checkpoint interval. Default: None
  145. --is_save_on_master IS_SAVE_ON_MASTER
  146. Save ckpt on master or all rank, 1 for master, 0 for
  147. all ranks. Default: 1
  148. --is_distributed IS_DISTRIBUTED
  149. Distribute train or not, 1 for yes, 0 for no. Default: 0
  150. --rank RANK Local rank of distributed. Default: 0
  151. --group_size GROUP_SIZE
  152. World size of device. Default: 1
  153. --need_profiler NEED_PROFILER
  154. Whether use profiler. 1 for yes. 0 for no. Default: 0
  155. --training_shape TRAINING_SHAPE
  156. Fix training shape. Default: ""
  157. --resize_rate RESIZE_RATE
  158. Resize rate for multi-scale training. Default: None
  159. ```
  160. ## [Training Process](#contents)
  161. ### Training on Ascend
  162. ### Distributed Training
  163. ```
  164. sh run_distribute_train.sh dataset/coco2014 yolov3_darknet53_noquant.ckpt rank_table_8p.json
  165. ```
  166. The above shell script will run distribute training in the background. You can view the results through the file `train_parallel[X]/log.txt`. The loss value will be achieved as follows:
  167. ```
  168. # distribute training result(8p)
  169. epoch[0], iter[0], loss:483.341675, 0.31 imgs/sec, lr:0.0
  170. epoch[0], iter[100], loss:55.690952, 3.46 imgs/sec, lr:0.0
  171. epoch[0], iter[200], loss:54.045728, 126.54 imgs/sec, lr:0.0
  172. epoch[0], iter[300], loss:48.771608, 133.04 imgs/sec, lr:0.0
  173. epoch[0], iter[400], loss:48.486769, 139.69 imgs/sec, lr:0.0
  174. epoch[0], iter[500], loss:48.649275, 143.29 imgs/sec, lr:0.0
  175. epoch[0], iter[600], loss:44.731309, 144.03 imgs/sec, lr:0.0
  176. epoch[1], iter[700], loss:43.037023, 136.08 imgs/sec, lr:0.0
  177. epoch[1], iter[800], loss:41.514788, 132.94 imgs/sec, lr:0.0
  178. epoch[133], iter[85700], loss:33.326716, 136.14 imgs/sec, lr:6.497331924038008e-06
  179. epoch[133], iter[85800], loss:34.968744, 136.76 imgs/sec, lr:6.497331924038008e-06
  180. epoch[134], iter[85900], loss:35.868543, 137.08 imgs/sec, lr:1.6245529650404933e-06
  181. epoch[134], iter[86000], loss:35.740817, 139.49 imgs/sec, lr:1.6245529650404933e-06
  182. epoch[134], iter[86100], loss:34.600463, 141.47 imgs/sec, lr:1.6245529650404933e-06
  183. epoch[134], iter[86200], loss:36.641916, 137.91 imgs/sec, lr:1.6245529650404933e-06
  184. epoch[134], iter[86300], loss:32.819769, 138.17 imgs/sec, lr:1.6245529650404933e-06
  185. epoch[134], iter[86400], loss:35.603033, 142.23 imgs/sec, lr:1.6245529650404933e-06
  186. epoch[134], iter[86500], loss:34.303755, 145.18 imgs/sec, lr:1.6245529650404933e-06
  187. ```
  188. ## [Evaluation Process](#contents)
  189. ### Evaluation on Ascend
  190. Before running the command below.
  191. ```
  192. python eval.py \
  193. --data_dir=./dataset/coco2014 \
  194. --pretrained=0-130_83330.ckpt \
  195. --testing_shape=416 > log.txt 2>&1 &
  196. OR
  197. sh run_eval.sh dataset/coco2014/ checkpoint/0-130_83330.ckpt 0
  198. ```
  199. The above python command will run in the background. You can view the results through the file "log.txt". The mAP of the test dataset will be as follows:
  200. ```
  201. # log.txt
  202. =============coco eval reulst=========
  203. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.310
  204. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.531
  205. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.322
  206. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.130
  207. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.326
  208. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.425
  209. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.260
  210. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.402
  211. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.429
  212. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.232
  213. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.450
  214. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.558
  215. ```
  216. # [Model Description](#contents)
  217. ## [Performance](#contents)
  218. ### Evaluation Performance
  219. | Parameters | Ascend |
  220. | -------------------------- | ---------------------------------------------------------------------------------------------- |
  221. | Model Version | YOLOv3_Darknet53_Quant V1 |
  222. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory, 755G |
  223. | uploaded Date | 06/31/2020 (month/day/year) |
  224. | MindSpore Version | 0.6.0-alpha |
  225. | Dataset | COCO2014 |
  226. | Training Parameters | epoch=135, batch_size=16, lr=0.012, momentum=0.9 |
  227. | Optimizer | Momentum |
  228. | Loss Function | Sigmoid Cross Entropy with logits |
  229. | outputs | boxes and label |
  230. | Loss | 34 |
  231. | Speed | 1pc: 135 ms/step; |
  232. | Total time | 8pc: 23.5 hours |
  233. | Parameters (M) | 62.1 |
  234. | Checkpoint for Fine tuning | 474M (.ckpt file) |
  235. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/yolov3_darknet53_quant |
  236. ### Inference Performance
  237. | Parameters | Ascend |
  238. | ------------------- | --------------------------- |
  239. | Model Version | YOLOv3_Darknet53_Quant V1 |
  240. | Resource | Ascend 910 |
  241. | Uploaded Date | 06/31/2020 (month/day/year) |
  242. | MindSpore Version | 0.6.0-alpha |
  243. | Dataset | COCO2014, 40,504 images |
  244. | batch_size | 1 |
  245. | outputs | mAP |
  246. | Accuracy | 8pcs: 31.0% |
  247. | Model for inference | 474M (.ckpt file) |
  248. # [Description of Random Situation](#contents)
  249. There are random seeds in distributed_sampler.py, transforms.py, yolo_dataset.py files.
  250. # [ModelZoo Homepage](#contents)
  251. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).