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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. 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.
  28. Dataset used: [COCO2017](<https://cocodataset.org/>)
  29. - Dataset size:19G
  30. - Train:18G,118000 images
  31. - Val:1G,5000 images
  32. - Annotations:241M,instances,captions,person_keypoints etc
  33. - Data format:image and json files
  34. - Note:Data will be processed in dataset.py
  35. # Environment Requirements
  36. - Install [MindSpore](https://www.mindspore.cn/install/en).
  37. - Download the dataset COCO2017.
  38. - We use COCO2017 as training dataset in this example by default, and you can also use your own datasets.
  39. 1. If coco dataset is used. **Select dataset to coco when run script.**
  40. Install Cython and pycocotool, and you can also install mmcv to process data.
  41. ```
  42. pip install Cython
  43. pip install pycocotools
  44. pip install mmcv==0.2.14
  45. ```
  46. And change the COCO_ROOT and other settings you need in `config.py`. The directory structure is as follows:
  47. ```
  48. .
  49. └─cocodataset
  50. ├─annotations
  51. ├─instance_train2017.json
  52. └─instance_val2017.json
  53. ├─val2017
  54. └─train2017
  55. ```
  56. 2. If your own dataset is used. **Select dataset to other when run script.**
  57. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  58. ```
  59. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  60. ```
  61. 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`.
  62. # Quick Start
  63. After installing MindSpore via the official website, you can start training and evaluation as follows:
  64. Note: 1.the first run will generate the mindeocrd file, which will take a long time.
  65. 2.pretrained model is a resnet50 checkpoint that trained over ImageNet2012.
  66. 3.VALIDATION_JSON_FILE is label file. CHECKPOINT_PATH is a checkpoint file after trained.
  67. ```
  68. # standalone training
  69. sh run_standalone_train_ascend.sh [PRETRAINED_MODEL]
  70. # distributed training
  71. sh run_distribute_train_ascend.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  72. # eval
  73. sh run_eval_ascend.sh [VALIDATION_JSON_FILE] [CHECKPOINT_PATH]
  74. ```
  75. # Script Description
  76. ## Script and Sample Code
  77. ```shell
  78. .
  79. └─faster_rcnn
  80. ├─README.md // descriptions about fasterrcnn
  81. ├─scripts
  82. ├─run_standalone_train_ascend.sh // shell script for standalone on ascend
  83. ├─run_distribute_train_ascend.sh // shell script for distributed on ascend
  84. └─run_eval_ascend.sh // shell script for eval on ascend
  85. ├─src
  86. ├─FasterRcnn
  87. ├─__init__.py // init file
  88. ├─anchor_generator.py // anchor generator
  89. ├─bbox_assign_sample.py // first stage sampler
  90. ├─bbox_assign_sample_stage2.py // second stage sampler
  91. ├─faster_rcnn_r50.py // fasterrcnn network
  92. ├─fpn_neck.py //feature pyramid network
  93. ├─proposal_generator.py // proposal generator
  94. ├─rcnn.py // rcnn network
  95. ├─resnet50.py // backbone network
  96. ├─roi_align.py // roi align network
  97. └─rpn.py // region proposal network
  98. ├─config.py // total config
  99. ├─dataset.py // create dataset and process dataset
  100. ├─lr_schedule.py // learning ratio generator
  101. ├─network_define.py // network define for fasterrcnn
  102. └─util.py // routine operation
  103. ├─eval.py //eval scripts
  104. └─train.py // train scripts
  105. ```
  106. ## Training Process
  107. ### Usage
  108. ```
  109. # standalone training on ascend
  110. sh run_standalone_train_ascend.sh [PRETRAINED_MODEL]
  111. # distributed training on ascend
  112. sh run_distribute_train_ascend.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  113. ```
  114. > 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).
  115. > As for PRETRAINED_MODEL,it should be a ResNet50 checkpoint that trained over ImageNet2012. Ready-made pretrained_models are not available now. Stay tuned.
  116. > The original dataset path needs to be in the config.py,you can select "coco_root" or "image_dir".
  117. ### Result
  118. 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_rankid.log.
  119. ```
  120. # distribute training result(8p)
  121. 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
  122. 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
  123. 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
  124. ...
  125. 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
  126. 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
  127. 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
  128. ```
  129. ## Evaluation Process
  130. ### Usage
  131. ```
  132. # eval on ascend
  133. sh run_eval_ascend.sh [VALIDATION_JSON_FILE] [CHECKPOINT_PATH]
  134. ```
  135. > checkpoint can be produced in training process.
  136. ### Result
  137. 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.
  138. ```
  139. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.360
  140. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.586
  141. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.385
  142. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.229
  143. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.402
  144. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.441
  145. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.299
  146. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.487
  147. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.515
  148. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.346
  149. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.562
  150. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.631
  151. ```
  152. # Model Description
  153. ## Performance
  154. ### Training Performance
  155. | Parameters | FasterRcnn |
  156. | -------------------------- | ----------------------------------------------------------- |
  157. | Model Version | V1 |
  158. | Resource | Ascend 910 ;CPU 2.60GHz,192cores;Memory,755G |
  159. | uploaded Date | 08/31/2020 (month/day/year) |
  160. | MindSpore Version | 1.0.0 |
  161. | Dataset | COCO2017 |
  162. | Training Parameters | epoch=12, batch_size=2 |
  163. | Optimizer | SGD |
  164. | Loss Function | Softmax Cross Entropy ,Sigmoid Cross Entropy,SmoothL1Loss |
  165. | Speed | 1pc: 190 ms/step; 8pcs: 200 ms/step |
  166. | Total time | 1pc: 37.17 hours; 8pcs: 4.89 hours |
  167. | Parameters (M) | 250 |
  168. | Scripts | [fasterrcnn script](https://gitee.com/mindspore/mindspore/tree/r1.0/model_zoo/official/cv/faster_rcnn) |
  169. ### Evaluation Performance
  170. | Parameters | FasterRcnn |
  171. | ------------------- | --------------------------- |
  172. | Model Version | V1 |
  173. | Resource | Ascend 910 |
  174. | Uploaded Date | 08/31/2020 (month/day/year) |
  175. | MindSpore Version | 1.0.0 |
  176. | Dataset | COCO2017 |
  177. | batch_size | 2 |
  178. | outputs | mAP |
  179. | Accuracy | IoU=0.50: 57.6% |
  180. | Model for inference | 250M (.ckpt file) |
  181. # [ModelZoo Homepage](#contents)
  182. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).