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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # SSD Example
  2. ## Description
  3. SSD network based on MobileNetV2, with support for training and evaluation.
  4. ## Requirements
  5. - Install [MindSpore](https://www.mindspore.cn/install/en).
  6. - Dataset
  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.
  10. ```
  11. pip install Cython
  12. pip install pycocotools
  13. ```
  14. And change the coco_root and other settings you need in `config.py`. The directory structure is as follows:
  15. ```
  16. .
  17. └─cocodataset
  18. ├─annotations
  19. ├─instance_train2017.json
  20. └─instance_val2017.json
  21. ├─val2017
  22. └─train2017
  23. ```
  24. 2. If your own dataset is used. **Select dataset to other when run script.**
  25. Organize the dataset infomation into a TXT file, each row in the file is as follows:
  26. ```
  27. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  28. ```
  29. 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`.
  30. ## Running the example
  31. ### Training
  32. To train the model, run `train.py`. If the `mindrecord_dir` is empty, it will generate [mindrecord](https://www.mindspore.cn/tutorial/en/master/use/data_preparation/converting_datasets.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.**
  33. - Stand alone mode
  34. ```
  35. python train.py --dataset coco
  36. ```
  37. You can run ```python train.py -h``` to get more information.
  38. - Distribute mode
  39. ```
  40. sh run_distribute_train.sh 8 500 0.2 coco /data/hccl.json
  41. ```
  42. The input parameters are device numbers, epoch size, learning rate, dataset mode and [hccl json configuration file](https://www.mindspore.cn/tutorial/en/master/advanced_use/distributed_training.html). **It is better to use absolute path.**
  43. You will get the loss value of each step as following:
  44. ```
  45. epoch: 1 step: 458, loss is 3.1681802
  46. epoch time: 228752.4654865265, per step time: 499.4595316299705
  47. epoch: 2 step: 458, loss is 2.8847265
  48. epoch time: 38912.93382644653, per step time: 84.96273761232868
  49. epoch: 3 step: 458, loss is 2.8398118
  50. epoch time: 38769.184827804565, per step time: 84.64887516987896
  51. ...
  52. epoch: 498 step: 458, loss is 0.70908034
  53. epoch time: 38771.079778671265, per step time: 84.65301261718616
  54. epoch: 499 step: 458, loss is 0.7974688
  55. epoch time: 38787.413120269775, per step time: 84.68867493508685
  56. epoch: 500 step: 458, loss is 0.5548882
  57. epoch time: 39064.8467540741, per step time: 85.29442522723602
  58. ```
  59. ### Evaluation
  60. for evaluation , run `eval.py` with `checkpoint_path`. `checkpoint_path` is the path of [checkpoint](https://www.mindspore.cn/tutorial/en/master/use/saving_and_loading_model_parameters.html) file.
  61. ```
  62. python eval.py --checkpoint_path ssd.ckpt --dataset coco
  63. ```
  64. You can run ```python eval.py -h``` to get more information.
  65. You will get the result as following:
  66. ```
  67. Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.189
  68. Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.341
  69. Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.183
  70. Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.040
  71. Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.181
  72. Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.326
  73. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.213
  74. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.348
  75. Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.380
  76. Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.124
  77. Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.412
  78. Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.588
  79. ========================================
  80. mAP: 0.18937438355383837
  81. ```