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

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # MaskRcnn Example
  2. ## Description
  3. MaskRcnn 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 MaskRcnn 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. Notice that the coco2017 dataset will be converted to MindRecord which is a data format in MindSpore. The dataset conversion may take about 4 hours.
  26. 2. If your own dataset is used. **Select dataset to other when run script.**
  27. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  28. ```
  29. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  30. ```
  31. 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`.
  32. ## Example structure
  33. ```shell
  34. .
  35. └─MaskRcnn
  36. ├─README.md
  37. ├─scripts
  38. ├─run_download_process_data.sh
  39. ├─run_standalone_train.sh
  40. ├─run_train.sh
  41. └─run_eval.sh
  42. ├─src
  43. ├─MaskRcnn
  44. ├─__init__.py
  45. ├─anchor_generator.py
  46. ├─bbox_assign_sample.py
  47. ├─bbox_assign_sample_stage2.py
  48. ├─mask_rcnn_r50.py
  49. ├─fpn_neck.py
  50. ├─proposal_generator.py
  51. ├─rcnn_cls.py
  52. ├─rcnn_mask.py
  53. ├─resnet50.py
  54. ├─roi_align.py
  55. └─rpn.py
  56. ├─config.py
  57. ├─dataset.py
  58. ├─lr_schedule.py
  59. ├─network_define.py
  60. └─util.py
  61. ├─eval.py
  62. └─train.py
  63. ```
  64. ## Running the example
  65. ### Train
  66. #### Usage
  67. ```
  68. # distributed training
  69. sh run_distribute_train.sh [RANK_TABLE_FILE] [PRETRAINED_MODEL]
  70. # standalone training
  71. sh run_standalone_train.sh [PRETRAINED_MODEL]
  72. ```
  73. > hccl.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).
  74. > As for PRETRAINED_MODEL,if not set, the model will be trained from the very beginning.Ready-made pretrained_models are not available now. Stay tuned.
  75. #### Result
  76. 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.
  77. ```
  78. # distribute training result(8p)
  79. epoch: 1 step: 7393 ,rpn_loss: 0.10626, rcnn_loss: 0.81592, rpn_cls_loss: 0.05862, rpn_reg_loss: 0.04761, rcnn_cls_loss: 0.32642, rcnn_reg_loss: 0.15503, rcnn_mask_loss: 0.33447, total_loss: 0.92218
  80. epoch: 2 step: 7393 ,rpn_loss: 0.00911, rcnn_loss: 0.34082, rpn_cls_loss: 0.00341, rpn_reg_loss: 0.00571, rcnn_cls_loss: 0.07440, rcnn_reg_loss: 0.05872, rcnn_mask_loss: 0.20764, total_loss: 0.34993
  81. epoch: 3 step: 7393 ,rpn_loss: 0.02087, rcnn_loss: 0.98633, rpn_cls_loss: 0.00665, rpn_reg_loss: 0.01422, rcnn_cls_loss: 0.35913, rcnn_reg_loss: 0.21375, rcnn_mask_loss: 0.41382, total_loss: 1.00720
  82. ...
  83. epoch: 10 step: 7393 ,rpn_loss: 0.02122, rcnn_loss: 0.55176, rpn_cls_loss: 0.00620, rpn_reg_loss: 0.01503, rcnn_cls_loss: 0.12708, rcnn_reg_loss: 0.10254, rcnn_mask_loss: 0.32227, total_loss: 0.57298
  84. epoch: 11 step: 7393 ,rpn_loss: 0.03772, rcnn_loss: 0.60791, rpn_cls_loss: 0.03058, rpn_reg_loss: 0.00713, rcnn_cls_loss: 0.23987, rcnn_reg_loss: 0.11743, rcnn_mask_loss: 0.25049, total_loss: 0.64563
  85. epoch: 12 step: 7393 ,rpn_loss: 0.06482, rcnn_loss: 0.47681, rpn_cls_loss: 0.04770, rpn_reg_loss: 0.01709, rcnn_cls_loss: 0.16492, rcnn_reg_loss: 0.04990, rcnn_mask_loss: 0.26196, total_loss: 0.54163
  86. ```
  87. ### Evaluation
  88. #### Usage
  89. ```
  90. # infer
  91. sh run_eval.sh [VALIDATION_ANN_FILE_JSON] [CHECKPOINT_PATH]
  92. ```
  93. > As for the COCO2017 dataset, VALIDATION_ANN_FILE_JSON is refer to the annotations/instances_val2017.json in the dataset directory.
  94. > checkpoint can be produced and saved in training process, whose folder name begins with "train/checkpoint" or "train_parallel*/checkpoint".
  95. #### Result
  96. 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.
  97. ```
  98. Evaluate annotation type *bbox*
  99. Accumulating evaluation results...
  100. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.366
  101. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.591
  102. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.393
  103. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.241
  104. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.405
  105. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.454
  106. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.304
  107. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.492
  108. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.521
  109. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.372
  110. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.560
  111. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.637
  112. Evaluate annotation type *segm*
  113. Accumulating evaluation results...
  114. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.318
  115. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.546
  116. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.332
  117. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.165
  118. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.348
  119. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.449
  120. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.272
  121. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.421
  122. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.440
  123. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.292
  124. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.479
  125. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.558
  126. ```