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

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. # Contents
  2. - [SSD Description](#ssd-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. - [Model Description](#model-description)
  15. - [Performance](#performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [Inference Performance](#evaluation-performance)
  18. - [Description of Random Situation](#description-of-random-situation)
  19. - [ModelZoo Homepage](#modelzoo-homepage)
  20. # [SSD Description](#contents)
  21. SSD discretizes the output space of bounding boxes into a set of default boxes over different aspect ratios and scales per feature map location. At prediction time, the network generates scores for the presence of each object category in each default box and produces adjustments to the box to better match the object shape.Additionally, the network combines predictions from multiple feature maps with different resolutions to naturally handle objects of various sizes.
  22. [Paper](https://arxiv.org/abs/1512.02325): Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg.European Conference on Computer Vision (ECCV), 2016 (In press).
  23. # [Model Architecture](#contents)
  24. The SSD approach is based on a feed-forward convolutional network that produces a fixed-size collection of bounding boxes and scores for the presence of object class instances in those boxes, followed by a non-maximum suppression step to produce the final detections. The early network layers are based on a standard architecture used for high quality image classification, which is called the base network. Then add auxiliary structure to the network to produce detections.
  25. # [Dataset](#contents)
  26. Dataset used: [COCO2017](<http://images.cocodataset.org/>)
  27. - Dataset size:19G
  28. - Train:18G,118000 images
  29. - Val:1G,5000 images
  30. - Annotations:241M,instances,captions,person_keypoints etc
  31. - Data format:image and json files
  32. - Note:Data will be processed in dataset.py
  33. # [Environment Requirements](#contents)
  34. - Install [MindSpore](https://www.mindspore.cn/install/en).
  35. - Download the dataset COCO2017.
  36. - We use COCO2017 as training dataset in this example by default, and you can also use your own datasets.
  37. 1. If coco dataset is used. **Select dataset to coco when run script.**
  38. Install Cython and pycocotool, and you can also install mmcv to process data.
  39. ```
  40. pip install Cython
  41. pip install pycocotools
  42. ```
  43. And change the COCO_ROOT and other settings you need in `config.py`. The directory structure is as follows:
  44. ```
  45. .
  46. └─cocodataset
  47. ├─annotations
  48. ├─instance_train2017.json
  49. └─instance_val2017.json
  50. ├─val2017
  51. └─train2017
  52. ```
  53. 2. If your own dataset is used. **Select dataset to other when run script.**
  54. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  55. ```
  56. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  57. ```
  58. 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]. 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 setting in `config.py`.
  59. # [Quick Start](#contents)
  60. After installing MindSpore via the official website, you can start training and evaluation as follows:
  61. - runing on Ascend
  62. ```
  63. # distributed training on Ascend
  64. sh run_distribute_train.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE]
  65. # run eval on Ascend
  66. sh run_eval.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID]
  67. ```
  68. - runing on GPU
  69. ```
  70. # distributed training on GPU
  71. sh run_distribute_train_gpu.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET]
  72. # run eval on GPU
  73. sh run_eval_gpu.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID]
  74. ```
  75. # [Script Description](#contents)
  76. ## [Script and Sample Code](#contents)
  77. ```shell
  78. .
  79. └─ cv
  80. └─ ssd
  81. ├─ README.md ## descriptions about SSD
  82. ├─ scripts
  83. ├─ run_distribute_train.sh ## shell script for distributed on ascend
  84. ├─ run_distribute_train_gpu.sh ## shell script for distributed on gpu
  85. ├─ run_eval.sh ## shell script for eval on ascend
  86. └─ run_eval_gpu.sh ## shell script for eval on gpu
  87. ├─ src
  88. ├─ __init__.py ## init file
  89. ├─ box_util.py ## bbox utils
  90. ├─ coco_eval.py ## coco metrics utils
  91. ├─ config.py ## total config
  92. ├─ dataset.py ## create dataset and process dataset
  93. ├─ init_params.py ## parameters utils
  94. ├─ lr_schedule.py ## learning ratio generator
  95. └─ ssd.py ## ssd architecture
  96. ├─ eval.py ## eval scripts
  97. ├─ train.py ## train scripts
  98. └─ mindspore_hub_conf.py ## mindspore hub interface
  99. ```
  100. ## [Script Parameters](#contents)
  101. ```
  102. Major parameters in train.py and config.py as follows:
  103. "device_num": 1 # Use device nums
  104. "lr": 0.05 # Learning rate init value
  105. "dataset": coco # Dataset name
  106. "epoch_size": 500 # Epoch size
  107. "batch_size": 32 # Batch size of input tensor
  108. "pre_trained": None # Pretrained checkpoint file path
  109. "pre_trained_epoch_size": 0 # Pretrained epoch size
  110. "save_checkpoint_epochs": 10 # The epoch interval between two checkpoints. By default, the checkpoint will be saved per 10 epochs
  111. "loss_scale": 1024 # Loss scale
  112. "class_num": 81 # Dataset class number
  113. "image_shape": [300, 300] # Image height and width used as input to the model
  114. "mindrecord_dir": "/data/MindRecord_COCO" # MindRecord path
  115. "coco_root": "/data/coco2017" # COCO2017 dataset path
  116. "voc_root": "" # VOC original dataset path
  117. "image_dir": "" # Other dataset image path, if coco or voc used, it will be useless
  118. "anno_path": "" # Other dataset annotation path, if coco or voc used, it will be useless
  119. ```
  120. ## [Training Process](#contents)
  121. To train the model, run `train.py`. If the `mindrecord_dir` is empty, it will generate [mindrecord](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/convert_dataset.html) files by `coco_root`(coco dataset) or `iamge_dir` and `anno_path`(own dataset). **Note if mindrecord_dir isn't empty, it will use mindrecord_dir instead of raw images.**
  122. ### Training on Ascend
  123. - Distribute mode
  124. ```
  125. sh run_distribute_train.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE] [PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)
  126. ```
  127. We need five or seven parameters for this scripts.
  128. - `DEVICE_NUM`: the device number for distributed train.
  129. - `EPOCH_NUM`: epoch num for distributed train.
  130. - `LR`: learning rate init value for distributed train.
  131. - `DATASET`:the dataset mode for distributed train.
  132. - `RANK_TABLE_FILE :` the path of [rank_table.json](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools), it is better to use absolute path.
  133. - `PRE_TRAINED :` the path of pretrained checkpoint file, it is better to use absolute path.
  134. - `PRE_TRAINED_EPOCH_SIZE :` the epoch num of pretrained.
  135. Training result will be stored in the current path, whose folder name begins with "LOG". Under this, you can find checkpoint file together with result like the followings in log
  136. ```
  137. epoch: 1 step: 458, loss is 3.1681802
  138. epoch time: 228752.4654865265, per step time: 499.4595316299705
  139. epoch: 2 step: 458, loss is 2.8847265
  140. epoch time: 38912.93382644653, per step time: 84.96273761232868
  141. epoch: 3 step: 458, loss is 2.8398118
  142. epoch time: 38769.184827804565, per step time: 84.64887516987896
  143. ...
  144. epoch: 498 step: 458, loss is 0.70908034
  145. epoch time: 38771.079778671265, per step time: 84.65301261718616
  146. epoch: 499 step: 458, loss is 0.7974688
  147. epoch time: 38787.413120269775, per step time: 84.68867493508685
  148. epoch: 500 step: 458, loss is 0.5548882
  149. epoch time: 39064.8467540741, per step time: 85.29442522723602
  150. ```
  151. ### Training on GPU
  152. - Distribute mode
  153. ```
  154. sh run_distribute_train_gpu.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)
  155. ```
  156. We need five or seven parameters for this scripts.
  157. - `DEVICE_NUM`: the device number for distributed train.
  158. - `EPOCH_NUM`: epoch num for distributed train.
  159. - `LR`: learning rate init value for distributed train.
  160. - `DATASET`:the dataset mode for distributed train.
  161. - `PRE_TRAINED :` the path of pretrained checkpoint file, it is better to use absolute path.
  162. - `PRE_TRAINED_EPOCH_SIZE :` the epoch num of pretrained.
  163. Training result will be stored in the current path, whose folder name is "LOG". Under this, you can find checkpoint files together with result like the followings in log
  164. ```
  165. epoch: 1 step: 1, loss is 420.11783
  166. epoch: 1 step: 2, loss is 434.11032
  167. epoch: 1 step: 3, loss is 476.802
  168. ...
  169. epoch: 1 step: 458, loss is 3.1283689
  170. epoch time: 150753.701, per step time: 329.157
  171. ...
  172. ```
  173. ## [Evaluation Process](#contents)
  174. ### Evaluation on Ascend
  175. ```
  176. sh run_eval.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID]
  177. ```
  178. We need two parameters for this scripts.
  179. - `DATASET`:the dataset mode of evaluation dataset.
  180. - `CHECKPOINT_PATH`: the absolute path for checkpoint file.
  181. - `DEVICE_ID`: the device id for eval.
  182. > checkpoint can be produced in training process.
  183. Inference result will be stored in the example path, whose folder name begins with "eval". Under this, you can find result like the followings in log.
  184. ```
  185. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.238
  186. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.400
  187. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.240
  188. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.039
  189. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.198
  190. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.438
  191. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.250
  192. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.389
  193. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.424
  194. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.122
  195. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.434
  196. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.697
  197. ========================================
  198. mAP: 0.23808886505483504
  199. ```
  200. ### Evaluation on GPU
  201. ```
  202. sh run_eval_gpu.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID]
  203. ```
  204. We need two parameters for this scripts.
  205. - `DATASET`:the dataset mode of evaluation dataset.
  206. - `CHECKPOINT_PATH`: the absolute path for checkpoint file.
  207. - `DEVICE_ID`: the device id for eval.
  208. > checkpoint can be produced in training process.
  209. Inference result will be stored in the example path, whose folder name begins with "eval". Under this, you can find result like the followings in log.
  210. ```
  211. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.224
  212. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.375
  213. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.228
  214. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.034
  215. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.189
  216. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.407
  217. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.243
  218. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.382
  219. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.417
  220. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.120
  221. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.425
  222. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.686
  223. ========================================
  224. mAP: 0.2244936111705981
  225. ```
  226. # [Model Description](#contents)
  227. ## [Performance](#contents)
  228. ### Evaluation Performance
  229. | Parameters | Ascend | GPU |
  230. | -------------------------- | -------------------------------------------------------------| -------------------------------------------------------------|
  231. | Model Version | SSD V1 | SSD V1 |
  232. | Resource | Ascend 910 ;CPU 2.60GHz,192cores;Memory,755G | NV SMX2 V100-16G |
  233. | uploaded Date | 06/01/2020 (month/day/year) | 09/24/2020 (month/day/year) |
  234. | MindSpore Version | 0.3.0-alpha | 1.0.0 |
  235. | Dataset | COCO2017 | COCO2017 |
  236. | Training Parameters | epoch = 500, batch_size = 32 | epoch = 800, batch_size = 32 |
  237. | Optimizer | Momentum | Momentum |
  238. | Loss Function | Sigmoid Cross Entropy,SmoothL1Loss | Sigmoid Cross Entropy,SmoothL1Loss |
  239. | Speed | 8pcs: 90ms/step | 8pcs: 121ms/step |
  240. | Total time | 8pcs: 4.81hours | 8pcs: 12.31hours |
  241. | Parameters (M) | 34 | 34 |
  242. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/ssd | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/ssd |
  243. ### Inference Performance
  244. | Parameters | Ascend | GPU |
  245. | ------------------- | ----------------------------| ----------------------------|
  246. | Model Version | SSD V1 | SSD V1 |
  247. | Resource | Ascend 910 | GPU |
  248. | Uploaded Date | 06/01/2020 (month/day/year) | 09/24/2020 (month/day/year) |
  249. | MindSpore Version | 0.3.0-alpha | 1.0.0 |
  250. | Dataset | COCO2017 | COCO2017 |
  251. | batch_size | 1 | 1 |
  252. | outputs | mAP | mAP |
  253. | Accuracy | IoU=0.50: 23.8% | IoU=0.50: 22.4% |
  254. | Model for inference | 34M(.ckpt file) | 34M(.ckpt file) |
  255. # [Description of Random Situation](#contents)
  256. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  257. # [ModelZoo Homepage](#contents)
  258. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).