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

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. # Contents
  2. - [Description](#description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Mixed Precision](#mixed-precision)
  7. - [Environment Requirements](#environment-requirements)
  8. - [Quick Start](#quick-start)
  9. - [Dataset Preparation](#dataset-preparation)
  10. - [Model Checkpoints](#model-checkpoints)
  11. - [Running](#running)
  12. - [Script Description](#script-description)
  13. - [Script and Sample Code](#script-and-sample-code)
  14. - [Script Parameters](#script-parameters)
  15. - [Training Process](#training-process)
  16. - [Training](#training)
  17. - [Distributed Training](#distributed-training)
  18. - [Evaluation Process](#evaluation-process)
  19. - [Model Description](#model-description)
  20. - [Performance](#performance)
  21. - [Description of Random Situation](#description-of-random-situation)
  22. - [ModelZoo Homepage](#modelzoo-homepage)
  23. # [Description](#contents)
  24. SimplePoseNet is a convolution-based neural network for the task of human pose estimation and tracking. It provides baseline methods that are surprisingly simple and effective, thus helpful for inspiring and evaluating new ideas for the field. State-of-the-art results are achieved on challenging benchmarks. More detail about this model can be found in:
  25. B. Xiao, H. Wu, and Y. Wei, “Simple baselines for human pose estimation and tracking,” in Proc. Eur. Conf. Comput. Vis., 2018, pp. 472–487.
  26. This repository contains a Mindspore implementation of SimplePoseNet based upon Microsoft's original Pytorch implementation (<https://github.com/microsoft/human-pose-estimation.pytorch>). The training and validating scripts are also included, and the evaluation results are shown in the [Performance](#performance) section.
  27. # [Model Architecture](#contents)
  28. The overall network architecture of SimplePoseNet is shown below:
  29. [Link](https://arxiv.org/pdf/1804.06208.pdf)
  30. # [Dataset](#contents)
  31. 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.
  32. Dataset used: COCO2017
  33. - Dataset size:
  34. - Train: 19G, 118,287 images
  35. - Test: 788MB, 5,000 images
  36. - Data format: JPG images
  37. - Note: Data will be processed in `src/dataset.py`
  38. - Person detection result for validation: Detection result provided by author in the [repository](https://github.com/microsoft/human-pose-estimation.pytorch)
  39. # [Features](#contents)
  40. ## [Mixed Precision](#contents)
  41. The [mixed precision](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/enable_mixed_precision.html) training method accelerates the deep learning neural network training process by using both the single-precision and half-precision data formats, and maintains the network precision achieved by the single-precision training at the same time. Mixed precision training can accelerate the computation process, reduce memory usage, and enable a larger model or batch size to be trained on specific hardware. For FP16 operators, if the input data type is FP32, the backend of MindSpore will automatically handle it with reduced precision. Users could check the reduced-precision operators by enabling INFO log and then searching ‘reduce precision’.
  42. # [Environment Requirements](#contents)
  43. To run the python scripts in the repository, you need to prepare the environment as follow:
  44. - Hardware
  45. - Prepare hardware environment with Ascend.
  46. - Python and dependencies
  47. - python 3.7
  48. - mindspore 1.0.1
  49. - easydict 1.9
  50. - opencv-python 4.3.0.36
  51. - pycocotools 2.0
  52. - For more information, please check the resources below:
  53. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  54. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  55. # [Quick Start](#contents)
  56. ## [Dataset Preparation](#contents)
  57. SimplePoseNet use COCO2017 dataset to train and validate in this repository. Download the dataset from [official website](https://cocodataset.org/). You can place the dataset anywhere and tell the scripts where it is by modifying the `DATASET.ROOT` setting in configuration file `src/config.py`. For more information about the configuration file, please refer to [Script Parameters](#script-parameters).
  58. You also need the person detection result of COCO val2017 to reproduce the multi-person pose estimation results, as mentioned in [Dataset](#dataset). Please checkout the author's repository, download and extract them under `<ROOT>/experiments/`, and make them look like this:
  59. ```text
  60. └─ <ROOT>
  61. └─ experiments
  62. └─ COCO_val2017_detections_AP_H_56_person.json
  63. ```
  64. ## [Model Checkpoints](#contents)
  65. Before you start your training process, you need to obtain mindspore imagenet pretrained models. The model weight file can be obtained by running the Resnet training script in [official model zoo](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet). We also provide a pretrained model that can be used to train SimplePoseNet directly in [GoogleDrive](https://drive.google.com/file/d/1r3Hs0QNys0HyNtsQhSvx6IKdyRkC-3Hh/view?usp=sharing). The model file should be placed under `<ROOT>/models/` like this:
  66. ```text
  67. └─ <ROOT>
  68. └─ models
  69. └─resnet50.ckpt
  70. ```
  71. ## [Running](#contents)
  72. To train the model, run the shell script `scripts/train_standalone.sh` with the format below:
  73. ```shell
  74. sh scripts/train_standalone.sh [device_id] [ckpt_path_to_save]
  75. ```
  76. To validate the model, change the settings in `src/config.py` to the path of the model you want to validate. For example:
  77. ```python
  78. config.TEST.MODEL_FILE='results/xxxx.ckpt'
  79. ```
  80. Then, run the shell script `scripts/eval.sh` with the format below:
  81. ```shell
  82. sh scripts/eval.sh [device_id]
  83. ```
  84. # [Script Description](#contents)
  85. ## [Script and Sample Code](#contents)
  86. The structure of the files in this repository is shown below.
  87. ```text
  88. └─ mindspore-simpleposenet
  89. ├─ scripts
  90. │ ├─ eval.sh // launch ascend standalone evaluation
  91. │ ├─ train_distributed.sh // launch ascend distributed training
  92. │ └─ train_standalone.sh // launch ascend standalone training
  93. ├─ src
  94. │ ├─utils
  95. │ │ ├─ transform.py // utils about image transformation
  96. │ │ └─ nms.py // utils about nms
  97. │ ├─evaluate
  98. │ │ └─ coco_eval.py // evaluate result by coco
  99. │ ├─ config.py // network and running config
  100. │ ├─ dataset.py // dataset processor and provider
  101. │ ├─ model.py // SimplePoseNet implementation
  102. │ ├─ network_define.py // define loss
  103. │ └─ predict.py // predict keypoints from heatmaps
  104. ├─ eval.py // evaluation script
  105. ├─ param_convert.py // model parameters conversion script
  106. ├─ train.py // training script
  107. └─ README.md // descriptions about this repository
  108. ```
  109. ## [Script Parameters](#contents)
  110. Configurations for both training and evaluation are set in `src/config.py`. All the settings are shown following.
  111. - config for SimplePoseNet on COCO2017 dataset:
  112. ```python
  113. # pose_resnet related params
  114. POSE_RESNET.HEATMAP_SIZE = [48, 64] # heatmap size
  115. POSE_RESNET.SIGMA = 2 # Gaussian hyperparameter in heatmap generation
  116. POSE_RESNET.FINAL_CONV_KERNEL = 1 # final convolution kernel size
  117. POSE_RESNET.DECONV_WITH_BIAS = False # deconvolution bias
  118. POSE_RESNET.NUM_DECONV_LAYERS = 3 # the number of deconvolution layers
  119. POSE_RESNET.NUM_DECONV_FILTERS = [256, 256, 256] # the filter size of deconvolution layers
  120. POSE_RESNET.NUM_DECONV_KERNELS = [4, 4, 4] # kernel size of deconvolution layers
  121. POSE_RESNET.NUM_LAYERS = 50 # number of layers(for resnet)
  122. # common params for NETWORK
  123. config.MODEL.NAME = 'pose_resnet' # model name
  124. config.MODEL.INIT_WEIGHTS = True # init model weights by resnet
  125. config.MODEL.PRETRAINED = './models/resnet50.ckpt' # pretrained model
  126. config.MODEL.NUM_JOINTS = 17 # the number of keypoints
  127. config.MODEL.IMAGE_SIZE = [192, 256] # image size
  128. # dataset
  129. config.DATASET.ROOT = '/data/coco2017/' # coco2017 dataset root
  130. config.DATASET.TEST_SET = 'val2017' # folder name of test set
  131. config.DATASET.TRAIN_SET = 'train2017' # folder name of train set
  132. # data augmentation
  133. config.DATASET.FLIP = True # random flip
  134. config.DATASET.ROT_FACTOR = 40 # random rotation
  135. config.DATASET.SCALE_FACTOR = 0.3 # random scale
  136. # for train
  137. config.TRAIN.BATCH_SIZE = 64 # batch size
  138. config.TRAIN.BEGIN_EPOCH = 0 # begin epoch
  139. config.TRAIN.END_EPOCH = 140 # end epoch
  140. config.TRAIN.LR = 0.001 # initial learning rate
  141. config.TRAIN.LR_FACTOR = 0.1 # learning rate reduce factor
  142. config.TRAIN.LR_STEP = [90,120] # step to reduce lr
  143. # test
  144. config.TEST.BATCH_SIZE = 32 # batch size
  145. config.TEST.FLIP_TEST = True # flip test
  146. config.TEST.POST_PROCESS = True # post process
  147. config.TEST.SHIFT_HEATMAP = True # shift heatmap
  148. config.TEST.USE_GT_BBOX = False # use groundtruth bbox
  149. config.TEST.MODEL_FILE = '' # model file to test
  150. # detect bbox file
  151. config.TEST.COCO_BBOX_FILE = 'experiments/COCO_val2017_detections_AP_H_56_person.json'
  152. # nms
  153. config.TEST.OKS_THRE = 0.9 # oks threshold
  154. config.TEST.IN_VIS_THRE = 0.2 # visible threshold
  155. config.TEST.BBOX_THRE = 1.0 # bbox threshold
  156. config.TEST.IMAGE_THRE = 0.0 # image threshold
  157. config.TEST.NMS_THRE = 1.0 # nms threshold
  158. ```
  159. ## [Training Process](#contents)
  160. ### [Training](#contents)
  161. #### Running on Ascend
  162. Run `scripts/train_standalone.sh` to train the model standalone. The usage of the script is:
  163. ```shell
  164. sh scripts/train_standalone.sh [device_id] [ckpt_path_to_save]
  165. ```
  166. For example, you can run the shell command below to launch the training procedure.
  167. ```shell
  168. sh scripts/train_standalone.sh 0 results/standalone/
  169. ```
  170. The script will run training in the background, you can view the results through the file `train_log[X].txt` as follows:
  171. ```text
  172. loading parse...
  173. batch size :128
  174. loading dataset from /data/coco2017/train2017
  175. loaded 149813 records from coco dataset.
  176. loading pretrained model ./models/resnet50.ckpt
  177. start training, epoch size = 140
  178. epoch: 1 step: 1170, loss is 0.000699
  179. Epoch time: 492271.194, per step time: 420.745
  180. epoch: 2 step: 1170, loss is 0.000586
  181. Epoch time: 456265.617, per step time: 389.971
  182. ...
  183. ```
  184. The model checkpoint will be saved into `[ckpt_path_to_save]`.
  185. ### [Distributed Training](#contents)
  186. #### Running on Ascend
  187. Run `scripts/train_distributed.sh` to train the model distributed. The usage of the script is:
  188. ```shell
  189. sh scripts/train_distributed.sh [rank_table] [ckpt_path_to_save] [device_number]
  190. ```
  191. For example, you can run the shell command below to launch the distributed training procedure.
  192. ```shell
  193. sh scripts/train_distributed.sh /home/rank_table.json results/distributed/ 4
  194. ```
  195. The above shell script will run distribute training in the background. You can view the results through the file `train_parallel[X]/log.txt` as follows:
  196. ```text
  197. loading parse...
  198. batch size :64
  199. loading dataset from /data/coco2017/train2017
  200. loaded 149813 records from coco dataset.
  201. loading pretrained model ./models/resnet50.ckpt
  202. start training, epoch size = 140
  203. epoch: 1 step: 585, loss is 0.0007944
  204. Epoch time: 236219.684, per step time: 403.794
  205. epoch: 2 step: 585, loss is 0.000617
  206. Epoch time: 164792.001, per step time: 281.696
  207. ...
  208. ```
  209. The model checkpoint will be saved into `[ckpt_path_to_save]`.
  210. ## [Evaluation Process](#contents)
  211. ### Running on Ascend
  212. Change the settings in `src/config.py` to the path of the model you want to validate. For example:
  213. ```python
  214. config.TEST.MODEL_FILE='results/xxxx.ckpt'
  215. ```
  216. Then, run `scripts/eval.sh` to evaluate the model with one Ascend processor. The usage of the script is:
  217. ```shell
  218. sh scripts/eval.sh [device_id]
  219. ```
  220. For example, you can run the shell command below to launch the validation procedure.
  221. ```shell
  222. sh scripts/eval.sh 0
  223. ```
  224. The above shell command will run validation procedure in the background. You can view the results through the file `eval_log[X].txt`. The result will be achieved as follows:
  225. ```text
  226. use flip test: True
  227. loading model ckpt from results/distributed/sim-140_1170.ckpt
  228. loading dataset from /data/coco2017/val2017
  229. loading bbox file from experiments/COCO_val2017_detections_AP_H_56_person.json
  230. Total boxes: 104125
  231. 1024 samples validated in 18.133189916610718 seconds
  232. 2048 samples validated in 4.724390745162964 seconds
  233. ...
  234. ```
  235. # [Model Description](#contents)
  236. ## [Performance](#contents)
  237. ### SimplePoseNet on COCO2017 with detector
  238. #### Performance parameters
  239. | Parameters | Standalone | Distributed |
  240. | ------------------- | --------------------------- | --------------------------- |
  241. | Model Version | SimplePoseNet | SimplePoseNet |
  242. | Resource | Ascend 910 | 4 Ascend 910 cards |
  243. | Uploaded Date | 12/18/2020 (month/day/year) | 12/18/2020 (month/day/year) |
  244. | MindSpore Version | 1.1.0 | 1.1.0 |
  245. | Dataset | COCO2017 | COCO2017 |
  246. | Training Parameters | epoch=140, batch_size=128 | epoch=140, batch_size=64 |
  247. | Optimizer | Adam | Adam |
  248. | Loss Function | Mean Squared Error | Mean Squared Error |
  249. | Outputs | heatmap | heatmap |
  250. | Train Performance | mAP: 70.4 | mAP: 70.4 |
  251. | Speed | 1pc: 389.915 ms/step | 4pc: 281.356 ms/step |
  252. #### Note
  253. - Flip test is used.
  254. - Person detector has person AP of 56.4 on COCO val2017 dataset.
  255. - The dataset preprocessing and general training configurations are shown in [Script Parameters](#script-parameters) section.
  256. # [Description of Random Situation](#contents)
  257. In `src/dataset.py`, we set the seed inside “create_dataset" function. We also use random seed in `src/model.py` to initial network weights.
  258. # [ModelZoo Homepage](#contents)
  259. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).