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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. # Contents
  2. - [Face Recognition For Tracking Description](#face-recognition-for-tracking-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Script Description](#script-description)
  7. - [Script and Sample Code](#script-and-sample-code)
  8. - [Running Example](#running-example)
  9. - [Model Description](#model-description)
  10. - [Performance](#performance)
  11. - [ModelZoo Homepage](#modelzoo-homepage)
  12. # [Face Recognition For Tracking Description](#contents)
  13. This is a face recognition for tracking network based on Resnet, with support for training and evaluation on Ascend910, GPU and CPU.
  14. ResNet (residual neural network) was proposed by Kaiming He and other four Chinese of Microsoft Research Institute. Through the use of ResNet unit, it successfully trained 152 layers of neural network, and won the championship in ilsvrc2015. The error rate on top 5 was 3.57%, and the parameter quantity was lower than vggnet, so the effect was very outstanding. Traditional convolution network or full connection network will have more or less information loss. At the same time, it will lead to the disappearance or explosion of gradient, which leads to the failure of deep network training. ResNet solves this problem to a certain extent. By passing the input information to the output, the integrity of the information is protected. The whole network only needs to learn the part of the difference between input and output, which simplifies the learning objectives and difficulties.The structure of ResNet can accelerate the training of neural network very quickly, and the accuracy of the model is also greatly improved. At the same time, ResNet is very popular, even can be directly used in the concept net network.
  15. [Paper](https://arxiv.org/pdf/1512.03385.pdf): Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun. "Deep Residual Learning for Image Recognition"
  16. # [Model Architecture](#contents)
  17. Face Recognition For Tracking uses a Resnet network for performing feature extraction.
  18. # [Dataset](#contents)
  19. We use about 10K face images as training dataset and 2K as evaluating dataset in this example, and you can also use your own datasets or open source datasets (e.g. Labeled Faces in the Wild)
  20. The directory structure is as follows:
  21. ```python
  22. .
  23. └─ dataset
  24. ├─ train dataset
  25. ├─ ID1
  26. ├─ ID1_0001.jpg
  27. ├─ ID1_0002.jpg
  28. ...
  29. ├─ ID2
  30. ...
  31. ├─ ID3
  32. ...
  33. ...
  34. ├─ test dataset
  35. ├─ ID1
  36. ├─ ID1_0001.jpg
  37. ├─ ID1_0002.jpg
  38. ...
  39. ├─ ID2
  40. ...
  41. ├─ ID3
  42. ...
  43. ...
  44. ```
  45. # [Environment Requirements](#contents)
  46. - Hardware(Ascend/GPU/CPU)
  47. - Prepare hardware environment with Ascend processor.
  48. - Framework
  49. - [MindSpore](https://www.mindspore.cn/install/en)
  50. - For more information, please check the resources below:
  51. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  52. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  53. # [Script Description](#contents)
  54. ## [Script and Sample Code](#contents)
  55. The entire code structure is as following:
  56. ```python
  57. .
  58. └─ Face Recognition For Tracking
  59. ├─ README.md
  60. ├─ scripts
  61. ├─ run_standalone_train.sh # launch standalone training(1p) in ascend
  62. ├─ run_distribute_train.sh # launch distributed training(8p) in ascend
  63. ├─ run_eval.sh # launch evaluating in ascend
  64. ├─ run_export.sh # launch exporting air/mindir model
  65. ├─ run_standalone_train_gpu.sh # launch standalone training(1p) in gpu
  66. ├─ run_distribute_train_gpu.sh # launch distributed training(8p) in gpu
  67. ├─ run_eval_gpu.sh # launch evaluating in gpu
  68. ├─ run_export_gpu.sh # launch exporting mindir model in gpu
  69. ├─ run_train_cpu.sh # launch standalone training in cpu
  70. ├─ run_eval_cpu.sh # launch evaluating in cpu
  71. └─ run_export_cpu.sh # launch exporting mindir model in cpu
  72. ├─ src
  73. ├─ config.py # parameter configuration
  74. ├─ dataset.py # dataset loading and preprocessing for training
  75. ├─ reid.py # network backbone
  76. ├─ log.py # log function
  77. ├─ loss.py # loss function
  78. ├─ lr_generator.py # generate learning rate
  79. └─ me_init.py # network initialization
  80. ├─ train.py # training scripts
  81. ├─ eval.py # evaluation scripts
  82. └─ export.py # export air/mindir model
  83. ```
  84. ## [Running Example](#contents)
  85. ### Train
  86. - Stand alone mode
  87. ```bash
  88. Ascend:
  89. cd ./scripts
  90. sh run_standalone_train.sh [DATA_DIR] [USE_DEVICE_ID]
  91. ```
  92. ```bash
  93. GPU:
  94. cd ./scripts
  95. sh run_standalone_train_gpu.sh [DATA_DIR]
  96. ```
  97. ```bash
  98. CPU:
  99. cd ./scripts
  100. sh run_train_cpu.sh [DATA_DIR]
  101. ```
  102. or (fine-tune)
  103. ```bash
  104. Ascend:
  105. cd ./scripts
  106. sh run_standalone_train.sh [DATA_DIR] [USE_DEVICE_ID] [PRETRAINED_BACKBONE]
  107. ```
  108. ```bash
  109. GPU:
  110. cd ./scripts
  111. sh run_standalone_train.sh [DATA_DIR] [PRETRAINED_BACKBONE]
  112. ```
  113. ```bash
  114. CPU:
  115. cd ./scripts
  116. sh run_train.sh [DATA_DIR] [PRETRAINED_BACKBONE]
  117. ```
  118. for example, on Ascend:
  119. ```bash
  120. cd ./scripts
  121. sh run_standalone_train.sh /home/train_dataset 0 /home/a.ckpt
  122. ```
  123. - Distribute mode (recommended)
  124. ```bash
  125. Ascend:
  126. cd ./scripts
  127. sh run_distribute_train.sh [DATA_DIR] [RANK_TABLE]
  128. ```
  129. ```bash
  130. GPU:
  131. cd ./scripts
  132. sh run_distribute_train_gpu.sh [DEVICE_NUM] [VISIBLE_DEVICES(0, 1, 2, 3, 4, 5, 6, 7)] [DATASET_PATH]
  133. ```
  134. or (fine-tune)
  135. ```bash
  136. Ascend:
  137. cd ./scripts
  138. sh run_distribute_train.sh [DATA_DIR] [RANK_TABLE] [PRETRAINED_BACKBONE]
  139. ```
  140. ```bash
  141. GPU:
  142. cd ./scripts
  143. sh run_distribute_train_gpu.sh [DEVICE_NUM] [VISIBLE_DEVICES(0, 1, 2, 3, 4, 5, 6, 7)] [DATASET_PATH] [PRE_TRAINED]
  144. ```
  145. for example:
  146. ```bash
  147. cd ./scripts
  148. sh run_distribute_train.sh /home/train_dataset ./rank_table_8p.json /home/a.ckpt
  149. ```
  150. You will get the loss value of each step as following in "./output/[TIME]/[TIME].log" or "./scripts/device0/train.log":
  151. ```python
  152. epoch[0], iter[10], loss:43.314265, 8574.83 imgs/sec, lr=0.800000011920929
  153. epoch[0], iter[20], loss:45.121095, 8915.66 imgs/sec, lr=0.800000011920929
  154. epoch[0], iter[30], loss:42.342847, 9162.85 imgs/sec, lr=0.800000011920929
  155. epoch[0], iter[40], loss:39.456583, 9178.83 imgs/sec, lr=0.800000011920929
  156. ...
  157. epoch[179], iter[14900], loss:1.651353, 13001.25 imgs/sec, lr=0.02500000037252903
  158. epoch[179], iter[14910], loss:1.532123, 12669.85 imgs/sec, lr=0.02500000037252903
  159. epoch[179], iter[14920], loss:1.760322, 13457.81 imgs/sec, lr=0.02500000037252903
  160. epoch[179], iter[14930], loss:1.694281, 13417.38 imgs/sec, lr=0.02500000037252903
  161. ```
  162. ### Evaluation
  163. ```bash
  164. Ascend:
  165. cd ./scripts
  166. sh run_eval.sh [EVAL_DIR] [USE_DEVICE_ID] [PRETRAINED_BACKBONE]
  167. ```
  168. ```bash
  169. GPU:
  170. cd ./scripts
  171. sh run_eval_gpu.sh [EVAL_DIR] [PRETRAINED_BACKBONE]
  172. ```
  173. ```bash
  174. CPU:
  175. cd ./scripts
  176. sh run_eval_cpu.sh [EVAL_DIR] [PRETRAINED_BACKBONE]
  177. ```
  178. for example, on Ascend:
  179. ```bash
  180. cd ./scripts
  181. sh run_eval.sh /home/test_dataset 0 /home/a.ckpt
  182. ```
  183. You will get the result as following in "./scripts/device0/eval.log" or txt file in [PRETRAINED_BACKBONE]'s folder:
  184. ```python
  185. 0.5: 0.9273788254649683@0.020893691253149882
  186. 0.3: 0.8393850978779193@0.07438552515516506
  187. 0.1: 0.6220871197028316@0.1523084478903911
  188. 0.01: 0.2683641598437038@0.26217882879427634
  189. 0.001: 0.11060269148211463@0.34509718987101223
  190. 0.0001: 0.05381678898728808@0.4187797093636618
  191. 1e-05: 0.035770748447963394@0.5053771466191392
  192. ```
  193. ### Convert model
  194. If you want to infer the network on Ascend 310, you should convert the model to AIR:
  195. ```bash
  196. Ascend:
  197. cd ./scripts
  198. sh run_export.sh [BATCH_SIZE] [USE_DEVICE_ID] [PRETRAINED_BACKBONE]
  199. ```
  200. Or if you would like to convert your model to MINDIR file on GPU or CPU:
  201. ```bash
  202. GPU:
  203. cd ./scripts
  204. sh run_export_gpu.sh [PRETRAINED_BACKBONE] [BATCH_SIZE] [FILE_NAME](optional)
  205. ```
  206. ```bash
  207. CPU:
  208. cd ./scripts
  209. sh run_export_cpu.sh [PRETRAINED_BACKBONE] [BATCH_SIZE] [FILE_NAME](optional)
  210. ```
  211. # [Model Description](#contents)
  212. ## [Performance](#contents)
  213. ### Training Performance
  214. | Parameters | Ascend |GPU |CPU |
  215. | -------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
  216. | Model Version | V1 | V1 | V1 |
  217. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory, 755G; OS Euler2.8 |Tesla V100-PCIE |Intel(R) Xeon(R) CPU E5-2690 v4 |
  218. | uploaded Date | 09/30/2020 (month/day/year) |04/17/2021 (month/day/year) |04/17/2021 (month/day/year) |
  219. | MindSpore Version | 1.0.0 | 1.2.0 |1.2.0 |
  220. | Dataset | 10K images | 10K images | 10K images |
  221. | Training Parameters | epoch=180, batch_size=16, momentum=0.9 | epoch=40, batch_size=128(1p); 16(8p), momentum=0.9 | epoch=40, batch_size=128, momentum=0.9 |
  222. | Optimizer | SGD | SGD | SGD |
  223. | Loss Function | Softmax Cross Entropy | Softmax Cross Entropy | Softmax Cross Entropy |
  224. | outputs | probability | probability |probability |
  225. | Speed | 1pc: 8-10 ms/step; 8pcs: 9-11 ms/step | 1pc: 30 ms/step; 8pcs: 20 ms/step | 1pc: 2.5 s/step |
  226. | Total time | 1pc: 1 hour; 8pcs: 0.1 hours | 1pc: 2 minutes; 8pcs: 1.5 minutes |1pc: 2 hours |
  227. | Checkpoint for Fine tuning | 17M (.ckpt file) | 17M (.ckpt file) | 17M (.ckpt file) |
  228. ### Evaluation Performance
  229. | Parameters |Ascend |GPU |CPU |
  230. | ------------------- | --------------------------- | --------------------------- | --------------------------- |
  231. | Model Version |V1 |V1 |V1 |
  232. | Resource | Ascend 910; OS Euler2.8 |Tesla V100-PCIE |Intel(R) Xeon(R) CPU E5-2690 v4 |
  233. | Uploaded Date | 09/30/2020 (month/day/year) | 04/17/2021 (month/day/year) | 04/17/2021 (month/day/year) |
  234. | MindSpore Version | 1.0.0 | 1.2.0 |1.2.0 |
  235. | Dataset | 2K images | 2K images | 2K images |
  236. | batch_size | 128 | 128 |128 |
  237. | outputs | recall | recall |recall |
  238. | Recall | 0.62(FAR=0.1) | 0.62(FAR=0.1) | 0.62(FAR=0.1) |
  239. | Model for inference | 17M (.ckpt file) | 17M (.ckpt file) | 17M (.ckpt file) |
  240. # [ModelZoo Homepage](#contents)
  241. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).