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

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # Contents
  2. - [YOLOv3_ResNet18 Description](#yolov3_resnet18-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. - [Evaluation Process](#evaluation-process)
  13. - [Evaluation](#evaluation)
  14. - [Export MindIR](#export-mindir)
  15. - [Inference Process](#inference-process)
  16. - [Model Description](#model-description)
  17. - [Performance](#performance)
  18. - [Evaluation Performance](#evaluation-performance)
  19. - [Inference Performance](#evaluation-performance)
  20. - [Description of Random Situation](#description-of-random-situation)
  21. - [ModelZoo Homepage](#modelzoo-homepage)
  22. # [YOLOv3_ResNet18 Description](#contents)
  23. YOLOv3 network based on ResNet-18, with support for training and evaluation.
  24. [Paper](https://arxiv.org/abs/1804.02767): Joseph Redmon, Ali Farhadi. arXiv preprint arXiv:1804.02767, 2018. 2, 4, 7, 11.
  25. # [Model Architecture](#contents)
  26. The overall network architecture of YOLOv3 is show below:
  27. And we use ResNet18 as the backbone of YOLOv3_ResNet18. The architecture of ResNet18 has 4 stages. The ResNet architecture performs the initial convolution and max-pooling using 7×7 and 3×3 kernel sizes respectively. Afterward, every stage of the network has different Residual blocks (2, 2, 2, 2) containing two 3×3 conv layers. Finally, the network has an Average Pooling layer followed by a fully connected layer.
  28. # [Dataset](#contents)
  29. Note that you can run the scripts based on the dataset mentioned in original paper or widely used in relevant domain/network architecture. In the following sections, we will introduce how to run the scripts using the related dataset below.
  30. Dataset used: [COCO2017](<http://images.cocodataset.org/>)
  31. - Dataset size:19G
  32. - Train:18G,118000 images
  33. - Val:1G,5000 images
  34. - Annotations:241M,instances,captions,person_keypoints etc
  35. - Data format:image and json files
  36. - Note:Data will be processed in dataset.py
  37. - Dataset
  38. 1. The directory structure is as follows:
  39. ```
  40. .
  41. ├── annotations # annotation jsons
  42. ├── train2017 # train dataset
  43. └── val2017 # infer dataset
  44. ```
  45. 2. Organize the dataset information into a TXT file, each row in the file is as follows:
  46. ```
  47. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  48. ```
  49. Each row is an image annotation which split by space, the first column is a relative path of image, the others are box and class infomations of the format [xmin,ymin,xmax,ymax,class]. `dataset.py` is the parsing script, we read image from an image path joined by the `image_dir`(dataset directory) and the relative path in `anno_path`(the TXT file path), `image_dir` and `anno_path` are external inputs.
  50. # [Environment Requirements](#contents)
  51. - Hardware(Ascend)
  52. - Prepare hardware environment with Ascend processor.
  53. - Framework
  54. - [MindSpore](https://www.mindspore.cn/install/en)
  55. - For more information, please check the resources below:
  56. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  57. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  58. # [Quick Start](#contents)
  59. After installing MindSpore via the official website, you can start training and evaluation on Ascend as follows:
  60. - running on Ascend
  61. ```shell script
  62. #run standalone training example
  63. sh run_standalone_train.sh [DEVICE_ID] [EPOCH_SIZE] [MINDRECORD_DIR] [IMAGE_DIR] [ANNO_PATH]
  64. #run distributed training example
  65. sh run_distribute_train.sh [DEVICE_NUM] [EPOCH_SIZE] [MINDRECORD_DIR] [IMAGE_DIR] [ANNO_PATH] [RANK_TABLE_FILE]
  66. #run evaluation example
  67. sh run_eval.sh [DEVICE_ID] [CKPT_PATH] [MINDRECORD_DIR] [IMAGE_DIR] [ANNO_PATH]
  68. ```
  69. # [Script Description](#contents)
  70. ## [Script and Sample Code](#contents)
  71. ```python
  72. └── cv
  73. ├── README.md // descriptions about all the models
  74. ├── mindspore_hub_conf.md // config for mindspore hub
  75. └── yolov3_resnet18
  76. ├── README.md // descriptions about yolov3_resnet18
  77. ├── scripts
  78. ├── run_distribute_train.sh // shell script for distributed on Ascend
  79. ├── run_standalone_train.sh // shell script for distributed on Ascend
  80. └── run_eval.sh // shell script for evaluation on Ascend
  81. ├── src
  82. ├── dataset.py // creating dataset
  83. ├── yolov3.py // yolov3 architecture
  84. ├── config.py // parameter configuration
  85. └── utils.py // util function
  86. ├── train.py // training script
  87. └── eval.py // evaluation script
  88. ```
  89. ## [Script Parameters](#contents)
  90. Major parameters in train.py and config.py as follows:
  91. ```python
  92. device_num: Use device nums, default is 1.
  93. lr: Learning rate, default is 0.001.
  94. epoch_size: Epoch size, default is 50.
  95. batch_size: Batch size, default is 32.
  96. pre_trained: Pretrained Checkpoint file path.
  97. pre_trained_epoch_size: Pretrained epoch size.
  98. mindrecord_dir: Mindrecord directory.
  99. image_dir: Dataset path.
  100. anno_path: Annotation path.
  101. img_shape: Image height and width used as input to the model.
  102. ```
  103. ## [Training Process](#contents)
  104. ### Training on Ascend
  105. To train the model, run `train.py` with the dataset `image_dir`, `anno_path` and `mindrecord_dir`. If the `mindrecord_dir` is empty, it wil generate [mindrecord](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/convert_dataset.html) file by `image_dir` and `anno_path`(the absolute image path is joined by the `image_dir` and the relative path in `anno_path`). **Note if `mindrecord_dir` isn't empty, it will use `mindrecord_dir` rather than `image_dir` and `anno_path`.**
  106. - Stand alone mode
  107. ```bash
  108. sh run_standalone_train.sh 0 50 ./Mindrecord_train ./dataset ./dataset/train.txt
  109. ```
  110. The input variables are device id, epoch size, mindrecord directory path, dataset directory path and train TXT file path.
  111. - Distributed mode
  112. ```bash
  113. sh run_distribute_train.sh 8 150 /data/Mindrecord_train /data /data/train.txt /data/hccl.json
  114. ```
  115. The input variables are device numbers, epoch size, mindrecord directory path, dataset directory path, train TXT file path and [hccl json configuration file](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools). **It is better to use absolute path.**
  116. You will get the loss value and time of each step as following:
  117. ```bash
  118. epoch: 145 step: 156, loss is 12.202981
  119. epoch time: 25599.22742843628, per step time: 164.0976117207454
  120. epoch: 146 step: 156, loss is 16.91706
  121. epoch time: 23199.971675872803, per step time: 148.7177671530308
  122. epoch: 147 step: 156, loss is 13.04007
  123. epoch time: 23801.95164680481, per step time: 152.57661312054364
  124. epoch: 148 step: 156, loss is 10.431475
  125. epoch time: 23634.241580963135, per step time: 151.50154859591754
  126. epoch: 149 step: 156, loss is 14.665991
  127. epoch time: 24118.8325881958, per step time: 154.60790120638333
  128. epoch: 150 step: 156, loss is 10.779521
  129. epoch time: 25319.57221031189, per step time: 162.30495006610187
  130. ```
  131. Note the results is two-classification(person and face) used our own annotations with coco2017, you can change `num_classes` in `config.py` to train your dataset. And we will support 80 classifications in coco2017 the near future.
  132. ## [Evaluation Process](#contents)
  133. ### Evaluation on Ascend
  134. To eval, run `eval.py` with the dataset `image_dir`, `anno_path`(eval txt), `mindrecord_dir` and `ckpt_path`. `ckpt_path` is the path of [checkpoint](https://www.mindspore.cn/tutorial/training/en/master/use/save_model.html) file.
  135. ```bash
  136. sh run_eval.sh 0 yolo.ckpt ./Mindrecord_eval ./dataset ./dataset/eval.txt
  137. ```
  138. The input variables are device id, checkpoint path, mindrecord directory path, dataset directory path and train TXT file path.
  139. You will get the precision and recall value of each class:
  140. ```bash
  141. class 0 precision is 88.18%, recall is 66.00%
  142. class 1 precision is 85.34%, recall is 79.13%
  143. ```
  144. Note the precision and recall values are results of two-classification(person and face) used our own annotations with coco2017.
  145. ## [Export MindIR](#contents)
  146. Currently, batchsize can only set to 1.
  147. ```shell
  148. python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
  149. ```
  150. The ckpt_file parameter is required,
  151. `EXPORT_FORMAT` should be in ["AIR", "MINDIR"]
  152. ## [Inference Process](#contents)
  153. ### Usage
  154. Before performing inference, the mindir file must be exported by export.py.
  155. Current batch_Size can only be set to 1. Images to be processed needs to be copied to the to-be-processed folder based on the annotation file.
  156. ```shell
  157. # Ascend310 inference
  158. bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [ANNO_PATH] [DEVICE_ID]
  159. ```
  160. `DEVICE_ID` is optional, default value is 0.
  161. ### result
  162. Inference result is saved in current path, you can find result in acc.log file.
  163. ```bash
  164. class 0 precision is 88.18%, recall is 66.00%
  165. class 1 precision is 85.34%, recall is 79.13%
  166. ```
  167. # [Model Description](#contents)
  168. ## [Performance](#contents)
  169. ### Evaluation Performance
  170. | Parameters | Ascend |
  171. | -------------------------- | ----------------------------------------------------------- |
  172. | Model Version | YOLOv3_Resnet18 V1 |
  173. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  174. | uploaded Date | 09/15/2020 (month/day/year) |
  175. | MindSpore Version | 1.0.0 |
  176. | Dataset | COCO2017 |
  177. | Training Parameters | epoch = 150, batch_size = 32, lr = 0.001 |
  178. | Optimizer | Adam |
  179. | Loss Function | Sigmoid Cross Entropy |
  180. | outputs | probability |
  181. | Speed | 1pc: 120 ms/step; 8pcs: 160 ms/step |
  182. | Total time | 1pc: 150 mins; 8pcs: 70 mins |
  183. | Parameters (M) | 189 |
  184. | Scripts | [yolov3_resnet18 script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/yolov3_resnet18) | [yolov3_resnet18 script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/yolov3_resnet18) |
  185. ### Inference Performance
  186. | Parameters | Ascend |
  187. | ------------------- | ----------------------------------------------- |
  188. | Model Version | YOLOv3_Resnet18 V1 |
  189. | Resource | Ascend 910; OS Euler2.8 |
  190. | Uploaded Date | 09/15/2020 (month/day/year) |
  191. | MindSpore Version | 1.0.0 |
  192. | Dataset | COCO2017 |
  193. | batch_size | 1 |
  194. | outputs | presion and recall |
  195. | Accuracy | class 0: 88.18%/66.00%; class 1: 85.34%/79.13% |
  196. # [Description of Random Situation](#contents)
  197. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  198. # [ModelZoo Homepage](#contents)
  199. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).