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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Contents
  2. - [WarpCTC Description](#warpctc-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Quick Start](#quick-start)
  7. - [Script Description](#script-description)
  8. - [Script and Sample Code](#script-and-sample-code)
  9. - [Script Parameters](#script-parameters)
  10. - [Training Script Parameters](#training-script-parameters)
  11. - [Parameters Configuration](#parameters-configuration)
  12. - [Dataset Preparation](#dataset-preparation)
  13. - [Training Process](#training-process)
  14. - [Training](#training)
  15. - [Distributed Training](#distributed-training)
  16. - [Evaluation Process](#evaluation-process)
  17. - [Evaluation](#evaluation)
  18. - [Model Description](#model-description)
  19. - [Performance](#performance)
  20. - [Training Performance](#training-performance)
  21. - [Evaluation Performance](#evaluation-performance)
  22. - [Description of Random Situation](#description-of-random-situation)
  23. - [ModelZoo Homepage](#modelzoo-homepage)
  24. ## [WarpCTC Description](#contents)
  25. This is an example of training WarpCTC with self-generated captcha image dataset in MindSpore.
  26. ## [Model Architecture](#content)
  27. WarpCTC is a two-layer stacked LSTM appending with one-layer FC neural network. See src/warpctc.py for details.
  28. ## [Dataset](#content)
  29. The dataset is self-generated using a third-party library called [captcha](https://github.com/lepture/captcha), which can randomly generate digits from 0 to 9 in image. In this network, we set the length of digits varying from 1 to 4.
  30. ## [Environment Requirements](#contents)
  31. - Hardware(Ascend/GPU)
  32. - Prepare hardware environment with Ascend or GPU processor.
  33. - Framework
  34. - [MindSpore](https://gitee.com/mindspore/mindspore)
  35. - For more information, please check the resources below:
  36. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  37. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  38. ## [Quick Start](#contents)
  39. - Generate dataset.
  40. Run the script `scripts/run_process_data.sh` to generate a dataset. By default, the shell script will generate 10000 test images and 50000 train images separately.
  41. ```bash
  42. $ cd scripts
  43. $ sh run_process_data.sh
  44. # after execution, you will find the dataset like the follows:
  45. .
  46. └─warpctc
  47. └─data
  48. ├─ train # train dataset
  49. └─ test # evaluate dataset
  50. ```
  51. - After the dataset is prepared, you may start running the training or the evaluation scripts as follows:
  52. - Running on Ascend
  53. ```bash
  54. # distribute training example in Ascend
  55. $ bash run_distribute_train.sh rank_table.json ../data/train
  56. # evaluation example in Ascend
  57. $ bash run_eval.sh ../data/test warpctc-30-97.ckpt Ascend
  58. # standalone training example in Ascend
  59. $ bash run_standalone_train.sh ../data/train Ascend
  60. ```
  61. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  62. Please follow the instructions in the link below:
  63. <https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools>.
  64. - Running on GPU
  65. ```bash
  66. # distribute training example in GPU
  67. $ bash run_distribute_train_for_gpu.sh 8 ../data/train
  68. # standalone training example in GPU
  69. $ bash run_standalone_train.sh ../data/train GPU
  70. # evaluation example in GPU
  71. $ bash run_eval.sh ../data/test warpctc-30-97.ckpt GPU
  72. ```
  73. ## [Script Description](#contents)
  74. ### [Script and Sample Code](#contents)
  75. ```shell
  76. .
  77. └──warpctc
  78. ├── README.md
  79. ├── script
  80. ├── run_distribute_train.sh # launch distributed training in Ascend(8 pcs)
  81. ├── run_distribute_train_for_gpu.sh # launch distributed training in GPU
  82. ├── run_eval.sh # launch evaluation
  83. ├── run_process_data.sh # launch dataset generation
  84. └── run_standalone_train.sh # launch standalone training(1 pcs)
  85. ├── src
  86. ├── config.py # parameter configuration
  87. ├── dataset.py # data preprocessing
  88. ├── loss.py # ctcloss definition
  89. ├── lr_generator.py # generate learning rate for each step
  90. ├── metric.py # accuracy metric for warpctc network
  91. ├── warpctc.py # warpctc network definition
  92. └── warpctc_for_train.py # warpctc network with grad, loss and gradient clip
  93. ├── mindspore_hub_conf.py # mindspore hub interface
  94. ├── eval.py # eval net
  95. ├── process_data.py # dataset generation script
  96. └── train.py # train net
  97. ```
  98. ### [Script Parameters](#contents)
  99. #### Training Script Parameters
  100. ```bash
  101. # distributed training in Ascend
  102. Usage: bash run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH]
  103. # distributed training in GPU
  104. Usage: bash run_distribute_train_for_gpu.sh [RANK_SIZE] [DATASET_PATH]
  105. # standalone training
  106. Usage: bash run_standalone_train.sh [DATASET_PATH] [PLATFORM]
  107. ```
  108. #### Parameters Configuration
  109. Parameters for both training and evaluation can be set in config.py.
  110. ```bash
  111. "max_captcha_digits": 4, # max number of digits in each
  112. "captcha_width": 160, # width of captcha images
  113. "captcha_height": 64, # height of capthca images
  114. "batch_size": 64, # batch size of input tensor
  115. "epoch_size": 30, # only valid for taining, which is always 1 for inference
  116. "hidden_size": 512, # hidden size in LSTM layers
  117. "learning_rate": 0.01, # initial learning rate
  118. "momentum": 0.9 # momentum of SGD optimizer
  119. "save_checkpoint": True, # whether save checkpoint or not
  120. "save_checkpoint_steps": 97, # the step interval between two checkpoints. By default, the last checkpoint will be saved after the last step
  121. "keep_checkpoint_max": 30, # only keep the last keep_checkpoint_max checkpoint
  122. "save_checkpoint_path": "./checkpoint", # path to save checkpoint
  123. ```
  124. ## [Dataset Preparation](#contents)
  125. - You may refer to "Generate dataset" in [Quick Start](#quick-start) to automatically generate a dataset, or you may choose to generate a captcha dataset by yourself.
  126. ### [Training Process](#contents)
  127. - Set options in `config.py`, including learning rate and other network hyperparameters. Click [MindSpore dataset preparation tutorial](https://www.mindspore.cn/tutorial/training/zh-CN/master/use/data_preparation.html) for more information about dataset.
  128. #### [Training](#contents)
  129. - Run `run_standalone_train.sh` for non-distributed training of WarpCTC model, either on Ascend or on GPU.
  130. ``` bash
  131. bash run_standalone_train.sh [DATASET_PATH] [PLATFORM]
  132. ```
  133. ##### [Distributed Training](#contents)
  134. - Run `run_distribute_train.sh` for distributed training of WarpCTC model on Ascend.
  135. ``` bash
  136. bash run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH]
  137. ```
  138. - Run `run_distribute_train_gpu.sh` for distributed training of WarpCTC model on GPU.
  139. ``` bash
  140. bash run_distribute_train_gpu.sh [RANK_SIZE] [DATASET_PATH]
  141. ```
  142. ### [Evaluation Process](#contents)
  143. #### [Evaluation](#contents)
  144. - Run `run_eval.sh` for evaluation.
  145. ``` bash
  146. bash run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH] [PLATFORM]
  147. ```
  148. ## [Model Description](#contents)
  149. ### [Performance](#contents)
  150. #### [Training Performance](#contents)
  151. | Parameters | Ascend 910 | GPU |
  152. | -------------------------- | --------------------------------------------- |---------------------------------- |
  153. | Model Version | v1.0 | v1.0 |
  154. | Resource | Ascend 910,CPU 2.60GHz 192cores,Memory 755G | GPU(Tesla V100 SXM2),CPU 2.1GHz 24cores,Memory 128G /
  155. | uploaded Date | 07/01/2020 (month/day/year) | 08/01/2020 (month/day/year) |
  156. | MindSpore Version | 0.5.0-alpha | 0.6.0-alpha |
  157. | Dataset | Captcha | Captcha |
  158. | Training Parameters | epoch=30, steps per epoch=98, batch_size = 64 | epoch=30, steps per epoch=98, batch_size = 64 |
  159. | Optimizer | SGD | SGD |
  160. | Loss Function | CTCLoss | CTCLoss |
  161. | outputs | probability | probability |
  162. | Loss | 0.0000157 | 0.0000246 |
  163. | Speed | 980ms/step(8pcs) | 150ms/step(8pcs)|
  164. | Total time | 30 mins | 5 mins|
  165. | Parameters (M) | 2.75 | 2.75 |
  166. | Checkpoint for Fine tuning | 20.3M (.ckpt file) | 20.3M (.ckpt file) |
  167. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/warpctc) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/warpctc) |
  168. #### [Evaluation Performance](#contents)
  169. | Parameters | WarpCTC |
  170. | ------------------- | --------------------------- |
  171. | Model Version | V1.0 |
  172. | Resource | Ascend 910 |
  173. | Uploaded Date | 08/01/2020 (month/day/year) |
  174. | MindSpore Version | 0.6.0-alpha |
  175. | Dataset | Captcha |
  176. | batch_size | 64 |
  177. | outputs | ACC |
  178. | Accuracy | 99.0% |
  179. | Model for inference | 20.3M (.ckpt file) |
  180. ## [Description of Random Situation](#contents)
  181. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py for weight initialization.
  182. ## [ModelZoo Homepage](#contents)
  183. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).