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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # FasterRcnn Example
  2. ## Description
  3. 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.
  4. ## Requirements
  5. - Install [MindSpore](https://www.mindspore.cn/install/en).
  6. - Download the dataset COCO2017.
  7. - We use coco2017 as training dataset in this example by default, and you can also use your own datasets.
  8. 1. If coco dataset is used. **Select dataset to coco when run script.**
  9. Install Cython and pycocotool, and you can also install mmcv to process data.
  10. ```
  11. pip install Cython
  12. pip install pycocotools
  13. pip install mmcv
  14. ```
  15. And change the COCO_ROOT and other settings you need in `config.py`. The directory structure is as follows:
  16. ```
  17. .
  18. └─cocodataset
  19. ├─annotations
  20. ├─instance_train2017.json
  21. └─instance_val2017.json
  22. ├─val2017
  23. └─train2017
  24. ```
  25. 2. If your own dataset is used. **Select dataset to other when run script.**
  26. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  27. ```
  28. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  29. ```
  30. 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`.
  31. ## Example structure
  32. ```shell
  33. .
  34. └─FasterRcnn
  35. ├─README.md
  36. ├─scripts
  37. ├─run_download_process_data.sh
  38. ├─run_standalone_train.sh
  39. ├─run_train.sh
  40. └─run_eval.sh
  41. ├─src
  42. ├─FasterRcnn
  43. ├─__init__.py
  44. ├─anchor_generator.py
  45. ├─bbox_assign_sample.py
  46. ├─bbox_assign_sample_stage2.py
  47. ├─faster_rcnn_r50.py
  48. ├─fpn_neck.py
  49. ├─proposal_generator.py
  50. ├─rcnn.py
  51. ├─resnet50.py
  52. ├─roi_align.py
  53. └─rpn.py
  54. ├─config.py
  55. ├─dataset.py
  56. ├─lr_schedule.py
  57. ├─network_define.py
  58. └─util.py
  59. ├─eval.py
  60. └─train.py
  61. ```
  62. ## Running the example
  63. ### Train
  64. #### Usage
  65. ```
  66. # distributed training
  67. sh run_distribute_train.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  68. # standalone training
  69. sh run_standalone_train.sh [PRETRAINED_MODEL]
  70. ```
  71. > 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).
  72. > As for PRETRAINED_MODEL,it should be a ResNet50 checkpoint that trained over ImageNet2012. Ready-made pretrained_models are not available now. Stay tuned.
  73. #### Result
  74. 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.
  75. ```
  76. # distribute training result(8p)
  77. 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
  78. 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
  79. 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
  80. ...
  81. 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
  82. 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
  83. 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
  84. ```
  85. ### Infer
  86. #### Usage
  87. ```
  88. # infer
  89. sh run_eval.sh [VALIDATION_JSON_FILE] [CHECKPOINT_PATH]
  90. ```
  91. > checkpoint can be produced in training process.
  92. #### Result
  93. Inference result will be stored in the example path, whose folder name is "eval". Under this, you can find result like the followings in log.
  94. ```
  95. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.360
  96. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.586
  97. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.385
  98. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.229
  99. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.402
  100. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.441
  101. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.299
  102. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.487
  103. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.515
  104. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.346
  105. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.562
  106. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.631
  107. ```