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 17 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. # Contents
  2. - [YOLOv3-DarkNet53 Description](#yolov3-darknet53-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 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. [Paper](https://pjreddie.com/media/files/papers/YOLOv3.pdf): YOLOv3: An Incremental Improvement. Joseph Redmon, Ali Farhadi,
  27. University of Washington
  28. # [Model Architecture](#contents)
  29. 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.
  30. # [Dataset](#contents)
  31. Dataset used: [COCO2014](https://cocodataset.org/#download)
  32. - Dataset size: 19G, 123,287 images, 80 object categories.
  33. - Train:13G, 82,783 images
  34. - Val:6GM, 40,504 images
  35. - Annotations: 241M, Train/Val annotations
  36. - Data format:zip files
  37. - Note:Data will be processed in yolo_dataset.py, and unzip files before uses it.
  38. # [Environment Requirements](#contents)
  39. - Hardware(Ascend/GPU)
  40. - Prepare hardware environment with Ascend or GPU 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.
  41. - Framework
  42. - [MindSpore](https://www.mindspore.cn/install/en)
  43. - For more information, please check the resources below:
  44. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
  45. - [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)
  46. # [Quick Start](#contents)
  47. After installing MindSpore via the official website, you can start training and evaluation in as follows. If running on GPU, please add `--device_target=GPU` in the python command or use the "_gpu" shell script ("xxx_gpu.sh").
  48. ```
  49. # The darknet53_backbone.ckpt in the follow script is got from darknet53 training like paper.
  50. # The parameter of pretrained_backbone is not necessary.
  51. # The parameter of training_shape define image shape for network, default is "".
  52. # It means use 10 kinds of shape as input shape, or it can be set some kind of shape.
  53. # run training example(1p) by python command.
  54. python train.py \
  55. --data_dir=./dataset/coco2014 \
  56. --pretrained_backbone=darknet53_backbone.ckpt \
  57. --is_distributed=0 \
  58. --lr=0.1 \
  59. --T_max=320 \
  60. --max_epoch=320 \
  61. --warmup_epochs=4 \
  62. --training_shape=416 \
  63. --lr_scheduler=cosine_annealing > log.txt 2>&1 &
  64. # standalone training example(1p) by shell script
  65. sh run_standalone_train.sh dataset/coco2014 darknet53_backbone.ckpt
  66. # For Ascend device, distributed training example(8p) by shell script
  67. sh run_distribute_train.sh dataset/coco2014 darknet53_backbone.ckpt rank_table_8p.json
  68. # For GPU device, distributed training example(8p) by shell script
  69. sh run_distribute_train_gpu.sh dataset/coco2014 darknet53_backbone.ckpt
  70. # run evaluation by python command
  71. python eval.py \
  72. --data_dir=./dataset/coco2014 \
  73. --pretrained=yolov3.ckpt \
  74. --testing_shape=416 > log.txt 2>&1 &
  75. # run evaluation by shell script
  76. sh run_eval.sh dataset/coco2014/ checkpoint/0-319_102400.ckpt
  77. ```
  78. # [Script Description](#contents)
  79. ## [Script and Sample Code](#contents)
  80. ```
  81. .
  82. └─yolov3_darknet53
  83. ├─README.md
  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. ├─run_standalone_train_gpu.sh # launch standalone training(1p) in gpu
  89. ├─run_distribute_train_gpu.sh # launch distributed training(8p) in gpu
  90. └─run_eval_gpu.sh # launch evaluating in gpu
  91. ├─src
  92. ├─__init__.py # python init file
  93. ├─config.py # parameter configuration
  94. ├─darknet.py # backbone of network
  95. ├─distributed_sampler.py # iterator of dataset
  96. ├─initializer.py # initializer of parameters
  97. ├─logger.py # log function
  98. ├─loss.py # loss function
  99. ├─lr_scheduler.py # generate learning rate
  100. ├─transforms.py # Preprocess data
  101. ├─util.py # util function
  102. ├─yolo.py # yolov3 network
  103. ├─yolo_dataset.py # create dataset for YOLOV3
  104. ├─eval.py # eval net
  105. └─train.py # train net
  106. ```
  107. ## [Script Parameters](#contents)
  108. ```
  109. Major parameters in train.py as follow.
  110. optional arguments:
  111. -h, --help show this help message and exit
  112. --device_target device where the code will be implemented: "Ascend" | "GPU", default is "Ascend"
  113. --data_dir DATA_DIR Train dataset directory.
  114. --per_batch_size PER_BATCH_SIZE
  115. Batch size for Training. Default: 32.
  116. --pretrained_backbone PRETRAINED_BACKBONE
  117. The ckpt file of DarkNet53. Default: "".
  118. --resume_yolov3 RESUME_YOLOV3
  119. The ckpt file of YOLOv3, which used to fine tune.
  120. Default: ""
  121. --lr_scheduler LR_SCHEDULER
  122. Learning rate scheduler, options: exponential,
  123. cosine_annealing. Default: exponential
  124. --lr LR Learning rate. Default: 0.001
  125. --lr_epochs LR_EPOCHS
  126. Epoch of changing of lr changing, split with ",".
  127. Default: 220,250
  128. --lr_gamma LR_GAMMA Decrease lr by a factor of exponential lr_scheduler.
  129. Default: 0.1
  130. --eta_min ETA_MIN Eta_min in cosine_annealing scheduler. Default: 0
  131. --T_max T_MAX T-max in cosine_annealing scheduler. Default: 320
  132. --max_epoch MAX_EPOCH
  133. Max epoch num to train the model. Default: 320
  134. --warmup_epochs WARMUP_EPOCHS
  135. Warmup epochs. Default: 0
  136. --weight_decay WEIGHT_DECAY
  137. Weight decay factor. Default: 0.0005
  138. --momentum MOMENTUM Momentum. Default: 0.9
  139. --loss_scale LOSS_SCALE
  140. Static loss scale. Default: 1024
  141. --label_smooth LABEL_SMOOTH
  142. Whether to use label smooth in CE. Default:0
  143. --label_smooth_factor LABEL_SMOOTH_FACTOR
  144. Smooth strength of original one-hot. Default: 0.1
  145. --log_interval LOG_INTERVAL
  146. Logging interval steps. Default: 100
  147. --ckpt_path CKPT_PATH
  148. Checkpoint save location. Default: outputs/
  149. --ckpt_interval CKPT_INTERVAL
  150. Save checkpoint interval. Default: None
  151. --is_save_on_master IS_SAVE_ON_MASTER
  152. Save ckpt on master or all rank, 1 for master, 0 for
  153. all ranks. Default: 1
  154. --is_distributed IS_DISTRIBUTED
  155. Distribute train or not, 1 for yes, 0 for no. Default:
  156. 1
  157. --rank RANK Local rank of distributed. Default: 0
  158. --group_size GROUP_SIZE
  159. World size of device. Default: 1
  160. --need_profiler NEED_PROFILER
  161. Whether use profiler. 0 for no, 1 for yes. Default: 0
  162. --training_shape TRAINING_SHAPE
  163. Fix training shape. Default: ""
  164. --resize_rate RESIZE_RATE
  165. Resize rate for multi-scale training. Default: None
  166. ```
  167. ## [Training Process](#contents)
  168. ### Training
  169. ```
  170. python train.py \
  171. --data_dir=./dataset/coco2014 \
  172. --pretrained_backbone=darknet53_backbone.ckpt \
  173. --is_distributed=0 \
  174. --lr=0.1 \
  175. --T_max=320 \
  176. --max_epoch=320 \
  177. --warmup_epochs=4 \
  178. --training_shape=416 \
  179. --lr_scheduler=cosine_annealing > log.txt 2>&1 &
  180. ```
  181. The python command above will run in the background, you can view the results through the file `log.txt`. If running on GPU, please add `--device_target=GPU` in the python command.
  182. After training, you'll get some checkpoint files under the outputs folder by default. The loss value will be achieved as follows:
  183. ```
  184. # grep "loss:" train/log.txt
  185. 2020-08-20 14:14:43,640:INFO:epoch[0], iter[0], loss:7809.262695, 0.15 imgs/sec, lr:9.746589057613164e-06
  186. 2020-08-20 14:15:05,142:INFO:epoch[0], iter[100], loss:2778.349033, 133.92 imgs/sec, lr:0.0009844054002314806
  187. 2020-08-20 14:15:31,796:INFO:epoch[0], iter[200], loss:535.517361, 130.54 imgs/sec, lr:0.0019590642768889666
  188. ...
  189. ```
  190. The model checkpoint will be saved in outputs directory.
  191. ### Distributed Training
  192. For Ascend device, distributed training example(8p) by shell script
  193. ```
  194. sh run_distribute_train.sh dataset/coco2014 darknet53_backbone.ckpt rank_table_8p.json
  195. ```
  196. For GPU device, distributed training example(8p) by shell script
  197. ```
  198. sh run_distribute_train_gpu.sh dataset/coco2014 darknet53_backbone.ckpt
  199. ```
  200. 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:
  201. ```
  202. # distribute training result(8p)
  203. epoch[0], iter[0], loss:14623.384766, 1.23 imgs/sec, lr:7.812499825377017e-05
  204. epoch[0], iter[100], loss:1486.253051, 15.01 imgs/sec, lr:0.007890624925494194
  205. epoch[0], iter[200], loss:288.579535, 490.41 imgs/sec, lr:0.015703124925494194
  206. epoch[0], iter[300], loss:153.136754, 531.99 imgs/sec, lr:0.023515624925494194
  207. epoch[1], iter[400], loss:106.429322, 405.14 imgs/sec, lr:0.03132812678813934
  208. ...
  209. epoch[318], iter[102000], loss:34.135306, 431.06 imgs/sec, lr:9.63797629083274e-06
  210. epoch[319], iter[102100], loss:35.652469, 449.52 imgs/sec, lr:2.409552052995423e-06
  211. epoch[319], iter[102200], loss:34.652273, 384.02 imgs/sec, lr:2.409552052995423e-06
  212. epoch[319], iter[102300], loss:35.430038, 423.49 imgs/sec, lr:2.409552052995423e-06
  213. ...
  214. ```
  215. ## [Evaluation Process](#contents)
  216. ### Evaluation
  217. Before running the command below. If running on GPU, please add `--device_target=GPU` in the python command or use the "_gpu" shell script ("xxx_gpu.sh").
  218. ```
  219. python eval.py \
  220. --data_dir=./dataset/coco2014 \
  221. --pretrained=yolov3.ckpt \
  222. --testing_shape=416 > log.txt 2>&1 &
  223. OR
  224. sh run_eval.sh dataset/coco2014/ checkpoint/0-319_102400.ckpt
  225. ```
  226. 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:
  227. ```
  228. # log.txt
  229. =============coco eval reulst=========
  230. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.311
  231. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.528
  232. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.322
  233. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.127
  234. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.323
  235. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.428
  236. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.259
  237. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.398
  238. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.423
  239. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.224
  240. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.442
  241. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.551
  242. ```
  243. # [Model Description](#contents)
  244. ## [Performance](#contents)
  245. ### Evaluation Performance
  246. | Parameters | YOLO |YOLO |
  247. | -------------------------- | ----------------------------------------------------------- |----------------------------------------------------------- |
  248. | Model Version | YOLOv3 |YOLOv3 |
  249. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory, 755G | NV SMX2 V100-16G; CPU 2.10GHz, 96cores; Memory, 251G |
  250. | uploaded Date | 06/31/2020 (month/day/year) | 09/02/2020 (month/day/year) |
  251. | MindSpore Version | 0.5.0-alpha | 0.7.0 |
  252. | Dataset | COCO2014 | COCO2014 |
  253. | Training Parameters | epoch=320, batch_size=32, lr=0.001, momentum=0.9 | epoch=320, batch_size=32, lr=0.001, momentum=0.9 |
  254. | Optimizer | Momentum | Momentum |
  255. | Loss Function | Sigmoid Cross Entropy with logits | Sigmoid Cross Entropy with logits |
  256. | outputs | boxes and label | boxes and label |
  257. | Loss | 34 | 34 |
  258. | Speed | 1pc: 350 ms/step; | 1pc: 600 ms/step; |
  259. | Total time | 8pc: 25 hours | 8pc: 18 hours(shape=416) |
  260. | Parameters (M) | 62.1 | 62.1 |
  261. | Checkpoint for Fine tuning | 474M (.ckpt file) | 474M (.ckpt file) |
  262. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/yolov3_darknet53 | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/yolov3_darknet53 |
  263. ### Inference Performance
  264. | Parameters | YOLO |YOLO |
  265. | ------------------- | --------------------------- |------------------------------|
  266. | Model Version | YOLOv3 | YOLOv3 |
  267. | Resource | Ascend 910 | NV SMX2 V100-16G |
  268. | Uploaded Date | 06/31/2020 (month/day/year) | 08/20/2020 (month/day/year) |
  269. | MindSpore Version | 0.5.0-alpha | 0.7.0 |
  270. | Dataset | COCO2014, 40,504 images | COCO2014, 40,504 images |
  271. | batch_size | 1 | 1 |
  272. | outputs | mAP | mAP |
  273. | Accuracy | 8pcs: 31.1% | 8pcs: 29.7%~30.3% (shape=416)|
  274. | Model for inference | 474M (.ckpt file) | 474M (.ckpt file) |
  275. # [Description of Random Situation](#contents)
  276. There are random seeds in distributed_sampler.py, transforms.py, yolo_dataset.py files.
  277. # [ModelZoo Homepage](#contents)
  278. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).