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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # [SSD Description](#contents)
  2. SSD discretizes the output space of bounding boxes into a set of default boxes over different aspect ratios and scales per feature map location. At prediction time, the network generates scores for the presence of each object category in each default box and produces adjustments to the box to better match the object shape.Additionally, the network combines predictions from multiple feature maps with different resolutions to naturally handle objects of various sizes.
  3. [Paper](https://arxiv.org/abs/1512.02325): Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg.European Conference on Computer Vision (ECCV), 2016 (In press).
  4. # [Model Architecture](#contents)
  5. The SSD approach is based on a feed-forward convolutional network that produces a fixed-size collection of bounding boxes and scores for the presence of object class instances in those boxes, followed by a non-maximum suppression step to produce the final detections. The early network layers are based on a standard architecture used for high quality image classification, which is called the base network. Then add auxiliary structure to the network to produce detections.
  6. # [Dataset](#contents)
  7. Dataset used: [COCO2017](<http://images.cocodataset.org/>)
  8. - Dataset size:19G
  9. - Train:18G,118000 images
  10. - Val:1G,5000 images
  11. - Annotations:241M,instances,captions,person_keypoints etc
  12. - Data format:image and json files
  13. - Note:Data will be processed in dataset.py
  14. # [Environment Requirements](#contents)
  15. - Hardware(Ascend/GPU)
  16. - Prepare hardware environment with Ascend or GPU processor.
  17. - Framework
  18. - [MindSpore](https://www.mindspore.cn/install/en)
  19. - For more information, please check the resources below:
  20. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  21. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  22. - Install [MindSpore](https://www.mindspore.cn/install/en).
  23. - Download the dataset COCO2017.
  24. - We use COCO2017 as training dataset in this example by default, and you can also use your own datasets.
  25. 1. If coco dataset is used. **Select dataset to coco when run script.**
  26. Install Cython and pycocotool, and you can also install mmcv to process data.
  27. ```bash
  28. pip install Cython
  29. pip install pycocotools
  30. ```
  31. And change the COCO_ROOT and other settings you need in `config.py`. The directory structure is as follows:
  32. ```python
  33. .
  34. └─cocodataset
  35. ├─annotations
  36. ├─instance_train2017.json
  37. └─instance_val2017.json
  38. ├─val2017
  39. └─train2017
  40. ```
  41. 2. If your own dataset is used. **Select dataset to other when run script.**
  42. Organize the dataset information into a TXT file, each row in the file is as follows:
  43. ```python
  44. train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
  45. ```
  46. 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`.
  47. # [Quick Start](#contents)
  48. After installing MindSpore via the official website, you can start training and evaluation on Ascend as follows:
  49. ```bash
  50. # single npu training on Ascend
  51. python train.py
  52. # distributed training on Ascend
  53. sh run_distribute_train_ghostnet.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE]
  54. # run eval on Ascend
  55. python eval.py --device_id 0 --dataset coco --checkpoint_path LOG4/ssd-500_458.ckpt
  56. ```
  57. # [Script Description](#contents)
  58. ## [Script and Sample Code](#contents)
  59. ```python
  60. ├── ssd_ghostnet
  61. ├── README.md ## readme file of ssd_ghostnet
  62. ├── scripts
  63. └─ run_distribute_train_ghostnet.sh ## shell script for distributed on ascend
  64. ├── src
  65. ├─ box_util.py ## bbox utils
  66. ├─ coco_eval.py ## coco metrics utils
  67. ├─ config_ghostnet_13x.py ## total config
  68. ├─ dataset.py ## create dataset and process dataset
  69. ├─ init_params.py ## parameters utils
  70. ├─ lr_schedule.py ## learning ratio generator
  71. └─ ssd_ghostnet.py ## ssd architecture
  72. ├── eval.py ## eval scripts
  73. ├── train.py ## train scripts
  74. ├── mindspore_hub_conf.py # export model for hub
  75. ```
  76. ## [Script Parameters](#contents)
  77. ```python
  78. Major parameters in train.py and config_ghostnet_13x.py as follows:
  79. "device_num": 1 # Use device nums
  80. "lr": 0.05 # Learning rate init value
  81. "dataset": coco # Dataset name
  82. "epoch_size": 500 # Epoch size
  83. "batch_size": 32 # Batch size of input tensor
  84. "pre_trained": None # Pretrained checkpoint file path
  85. "pre_trained_epoch_size": 0 # Pretrained epoch size
  86. "save_checkpoint_epochs": 10 # The epoch interval between two checkpoints. By default, the checkpoint will be saved per 10 epochs
  87. "loss_scale": 1024 # Loss scale
  88. "class_num": 81 # Dataset class number
  89. "image_shape": [300, 300] # Image height and width used as input to the model
  90. "mindrecord_dir": "/data/MindRecord_COCO" # MindRecord path
  91. "coco_root": "/data/coco2017" # COCO2017 dataset path
  92. "voc_root": "" # VOC original dataset path
  93. "image_dir": "" # Other dataset image path, if coco or voc used, it will be useless
  94. "anno_path": "" # Other dataset annotation path, if coco or voc used, it will be useless
  95. ```
  96. ## [Training Process](#contents)
  97. ### Training on Ascend
  98. To train the model, run `train.py`. If the `mindrecord_dir` is empty, it will generate [mindrecord](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/convert_dataset.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.**
  99. - Distribute mode
  100. ```bash
  101. sh run_distribute_train_ghostnet.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE] [PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)
  102. ```
  103. We need five or seven parameters for this scripts.
  104. - `DEVICE_NUM`: the device number for distributed train.
  105. - `EPOCH_NUM`: epoch num for distributed train.
  106. - `LR`: learning rate init value for distributed train.
  107. - `DATASET`:the dataset mode for distributed train.
  108. - `RANK_TABLE_FILE :` the path of [rank_table.json](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools), it is better to use absolute path.
  109. - `PRE_TRAINED :` the path of pretrained checkpoint file, it is better to use absolute path.
  110. - `PRE_TRAINED_EPOCH_SIZE :` the epoch num of pretrained.
  111. Training result will be stored in the current path, whose folder name begins with "LOG". Under this, you can find checkpoint file together with result like the followings in LOG4/log.txt.
  112. ## [Evaluation Process](#contents)
  113. ### Evaluation on Ascend
  114. ```bash
  115. python eval.py --device_id 0 --dataset coco --checkpoint_path LOG4/ssd-500_458.ckpt
  116. ```
  117. # [Model Description](#contents)
  118. ## [Performance](#contents)
  119. ### Evaluation Performance
  120. | Parameters | Ascend |
  121. | -------------------------- | -------------------------------------------------------------|
  122. | Model Version | SSD ghostnet |
  123. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  124. | MindSpore Version | 0.7.0 |
  125. | Dataset | COCO2017 |
  126. | Training Parameters | epoch = 500, batch_size = 32 |
  127. | Optimizer | Momentum |
  128. | Loss Function | Sigmoid Cross Entropy,SmoothL1Loss |
  129. | Total time | 8pcs: 12hours |
  130. ### Inference Performance
  131. | Parameters | Ascend |
  132. | ------------------- | ----------------------------|
  133. | Model Version | SSD ghostnet |
  134. | Resource | Ascend 910; OS Euler2.8 |
  135. | Uploaded Date | 09/08/2020 (month/day/year) |
  136. | MindSpore Version | 0.7.0 |
  137. | Dataset | COCO2017 |
  138. | batch_size | 1 |
  139. | outputs | mAP |
  140. | Accuracy | IoU=0.50: 24.1% |
  141. | Model for inference | 55M(.ckpt file) |