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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Contents
  2. - [FasterRcnn Description](#fasterrcnn-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. - [Training Process](#training-process)
  10. - [Training Usage](#usage)
  11. - [Training Result](#result)
  12. - [Evaluation Process](#evaluation-process)
  13. - [Evaluation Usage](#usage)
  14. - [Evaluation Result](#result)
  15. - [Model Description](#model-description)
  16. - [Performance](#performance)
  17. - [Evaluation Performance](#evaluation-performance)
  18. - [Inference Performance](#evaluation-performance)
  19. - [ModelZoo Homepage](#modelzoo-homepage)
  20. # FasterRcnn Description
  21. Before FasterRcnn, the target detection networks rely on the region proposal algorithm to assume the location of targets, such as SPPnet and Fast R-CNN. Progress has reduced the running time of these detection networks, but it also reveals that the calculation of the region proposal is a bottleneck.
  22. FasterRcnn proposed that convolution feature maps based on region detectors (such as Fast R-CNN) can also be used to generate region proposals. At the top of these convolution features, a Region Proposal Network (RPN) is constructed by adding some additional convolution layers (which share the convolution characteristics of the entire image with the detection network, thus making it possible to make regions almost costlessProposal), outputting both region bounds and objectness score for each location.Therefore, RPN is a full convolutional network (FCN), which can be trained end-to-end, generate high-quality region proposals, and then fed into Fast R-CNN for detection.
  23. [Paper](https://arxiv.org/abs/1506.01497): Ren S , He K , Girshick R , et al. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2015, 39(6).
  24. # Model Architecture
  25. FasterRcnn is a two-stage target detection network,This network uses a region proposal network (RPN), which can share the convolution features of the whole image with the detection network, so that the calculation of region proposal is almost cost free. The whole network further combines RPN and FastRcnn into a network by sharing the convolution features.
  26. # Dataset
  27. Dataset used: [COCO2017](<http://images.cocodataset.org/>)
  28. - Dataset size:19G
  29. - Train:18G,118000 images
  30. - Val:1G,5000 images
  31. - Annotations:241M,instances,captions,person_keypoints etc
  32. - Data format:image and json files
  33. - Note:Data will be processed in dataset.py
  34. # Environment Requirements
  35. - Install [MindSpore](https://www.mindspore.cn/install/en).
  36. - Download the dataset COCO2017.
  37. - We use COCO2017 as training dataset in this example by default, and you can also use your own datasets.
  38. 1. If coco dataset is used. **Select dataset to coco when run script.**
  39. Install Cython and pycocotool, and you can also install mmcv to process data.
  40. ```
  41. pip install Cython
  42. pip install pycocotools
  43. pip install mmcv==0.2.14
  44. ```
  45. And change the COCO_ROOT and other settings you need in `config.py`. The directory structure is as follows:
  46. ```
  47. .
  48. └─cocodataset
  49. ├─annotations
  50. ├─instance_train2017.json
  51. └─instance_val2017.json
  52. ├─val2017
  53. └─train2017
  54. ```
  55. 2. If your own dataset is used. **Select dataset to other when run script.**
  56. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  57. ```
  58. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  59. ```
  60. 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`.
  61. # Quick Start
  62. After installing MindSpore via the official website, you can start training and evaluation as follows:
  63. Note: 1.the first run will generate the mindeocrd file, which will take a long time. 2. pretrained model is a resnet50 checkpoint that trained over ImageNet2012. 3. VALIDATION_JSON_FILE is label file. CHECKPOINT_PATH is a checkpoint file after trained.
  64. ```
  65. # standalone training
  66. sh run_standalone_train_ascend.sh [PRETRAINED_MODEL]
  67. # distributed training
  68. sh run_distribute_train_ascend.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  69. # eval
  70. sh run_eval_ascend.sh [VALIDATION_JSON_FILE] [CHECKPOINT_PATH]
  71. ```
  72. # Script Description
  73. ## Script and Sample Code
  74. ```shell
  75. .
  76. └─FasterRcnn
  77. ├─README.md // descriptions about fasterrcnn
  78. ├─scripts
  79. ├─run_standalone_train_ascend.sh // shell script for standalone on ascend
  80. ├─run_distribute_train_ascend.sh // shell script for distributed on ascend
  81. └─run_eval_ascend.sh // shell script for eval on ascend
  82. ├─src
  83. ├─FasterRcnn
  84. ├─__init__.py // init file
  85. ├─anchor_generator.py // anchor generator
  86. ├─bbox_assign_sample.py // first stage sampler
  87. ├─bbox_assign_sample_stage2.py // second stage sampler
  88. ├─faster_rcnn_r50.py // fasterrcnn network
  89. ├─fpn_neck.py //feature pyramid network
  90. ├─proposal_generator.py // proposal generator
  91. ├─rcnn.py // rcnn network
  92. ├─resnet50.py // backbone network
  93. ├─roi_align.py // roi align network
  94. └─rpn.py // region proposal network
  95. ├─config.py // total config
  96. ├─dataset.py // create dataset and process dataset
  97. ├─lr_schedule.py // learning ratio generator
  98. ├─network_define.py // network define for fasterrcnn
  99. └─util.py // routine operation
  100. ├─eval.py //eval scripts
  101. └─train.py // train scripts
  102. ```
  103. ## Training Process
  104. ### Usage
  105. ```
  106. # standalone training on ascend
  107. sh run_standalone_train_ascend.sh [PRETRAINED_MODEL]
  108. # distributed training on ascend
  109. sh run_distribute_train_ascend.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  110. ```
  111. > Rank_table.json which is specified by RANK_TABLE_FILE is needed when you are running a distribute task. You can generate it by using the [hccl_tools](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools).
  112. > As for PRETRAINED_MODEL,it should be a ResNet50 checkpoint that trained over ImageNet2012. Ready-made pretrained_models are not available now. Stay tuned.
  113. ### Result
  114. Training result will be stored in the example path, whose folder name begins with "train" or "train_parallel". You can find checkpoint file together with result like the followings in loss.log.
  115. ```
  116. # distribute training result(8p)
  117. epoch: 1 step: 7393, rpn_loss: 0.12054, rcnn_loss: 0.40601, rpn_cls_loss: 0.04025, rpn_reg_loss: 0.08032, rcnn_cls_loss: 0.25854, rcnn_reg_loss: 0.14746, total_loss: 0.52655
  118. epoch: 2 step: 7393, rpn_loss: 0.06561, rcnn_loss: 0.50293, rpn_cls_loss: 0.02587, rpn_reg_loss: 0.03967, rcnn_cls_loss: 0.35669, rcnn_reg_loss: 0.14624, total_loss: 0.56854
  119. epoch: 3 step: 7393, rpn_loss: 0.06940, rcnn_loss: 0.49658, rpn_cls_loss: 0.03769, rpn_reg_loss: 0.03165, rcnn_cls_loss: 0.36353, rcnn_reg_loss: 0.13318, total_loss: 0.56598
  120. ...
  121. epoch: 10 step: 7393, rpn_loss: 0.03555, rcnn_loss: 0.32666, rpn_cls_loss: 0.00697, rpn_reg_loss: 0.02859, rcnn_cls_loss: 0.16125, rcnn_reg_loss: 0.16541, total_loss: 0.36221
  122. epoch: 11 step: 7393, rpn_loss: 0.19849, rcnn_loss: 0.47827, rpn_cls_loss: 0.11639, rpn_reg_loss: 0.08209, rcnn_cls_loss: 0.29712, rcnn_reg_loss: 0.18115, total_loss: 0.67676
  123. epoch: 12 step: 7393, rpn_loss: 0.00691, rcnn_loss: 0.10168, rpn_cls_loss: 0.00529, rpn_reg_loss: 0.00162, rcnn_cls_loss: 0.05426, rcnn_reg_loss: 0.04745, total_loss: 0.10859
  124. ```
  125. ## Evaluation Process
  126. ### Usage
  127. ```
  128. # eval on ascend
  129. sh run_eval_ascend.sh [VALIDATION_JSON_FILE] [CHECKPOINT_PATH]
  130. ```
  131. > checkpoint can be produced in training process.
  132. ### Result
  133. Eval result will be stored in the example path, whose folder name is "eval". Under this, you can find result like the followings in log.
  134. ```
  135. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.360
  136. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.586
  137. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.385
  138. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.229
  139. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.402
  140. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.441
  141. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.299
  142. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.487
  143. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.515
  144. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.346
  145. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.562
  146. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.631
  147. ```
  148. # Model Description
  149. ## Performance
  150. ### Training Performance
  151. | Parameters | FasterRcnn |
  152. | -------------------------- | ----------------------------------------------------------- |
  153. | Model Version | V1 |
  154. | Resource | Ascend 910 ;CPU 2.60GHz,56cores;Memory,314G |
  155. | uploaded Date | 06/01/2020 (month/day/year) |
  156. | MindSpore Version | 0.3.0-alpha |
  157. | Dataset | COCO2017 |
  158. | Training Parameters | epoch=12, batch_size = 2 |
  159. | Optimizer | SGD |
  160. | Loss Function | Softmax Cross Entropy ,Sigmoid Cross Entropy,SmoothL1Loss |
  161. | Speed | 1pc: 190 ms/step; 8pcs: 200 ms/step |
  162. | Total time | 1pc: 37.17 hours; 8pcs: 4.89 hours |
  163. | Parameters (M) | 250 |
  164. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/faster_rcnn |
  165. ### Evaluation Performance
  166. | Parameters | FasterRcnn |
  167. | ------------------- | --------------------------- |
  168. | Model Version | V1 |
  169. | Resource | Ascend 910 |
  170. | Uploaded Date | 06/01/2020 (month/day/year) |
  171. | MindSpore Version | 0.3.0-alpha |
  172. | Dataset | COCO2017 |
  173. | batch_size | 2 |
  174. | outputs | mAP |
  175. | Accuracy | IoU=0.50: 58.6% |
  176. | Model for inference | 250M (.ckpt file) |
  177. # [ModelZoo Homepage](#contents)
  178. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).