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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Contents
  2. - [Contents](#contents)
  3. - [CRNN Description](#crnn-description)
  4. - [Model Architecture](#model-architecture)
  5. - [Dataset](#dataset)
  6. - [Dataset Prepare](#dataset-prepare)
  7. - [Environment Requirements](#environment-requirements)
  8. - [Quick Start](#quick-start)
  9. - [Script Description](#script-description)
  10. - [Script and Sample Code](#script-and-sample-code)
  11. - [Script Parameters](#script-parameters)
  12. - [Training Script Parameters](#training-script-parameters)
  13. - [Parameters Configuration](#parameters-configuration)
  14. - [Dataset Preparation](#dataset-preparation)
  15. - [Training Process](#training-process)
  16. - [Training](#training)
  17. - [Distributed Training](#distributed-training)
  18. - [Evaluation Process](#evaluation-process)
  19. - [Evaluation](#evaluation)
  20. - [Model Description](#model-description)
  21. - [Performance](#performance)
  22. - [Training Performance](#training-performance)
  23. - [Evaluation Performance](#evaluation-performance)
  24. - [Description of Random Situation](#description-of-random-situation)
  25. - [ModelZoo Homepage](#modelzoo-homepage)
  26. ## [CRNN Description](#contents)
  27. CRNN was a neural network for image based sequence recognition and its Application to scene text recognition.In this paper, we investigate the problem of scene text recognition, which is among the most important and challenging tasks in image-based sequence recognition. A novel neural network architecture, which integrates feature extraction, sequence modeling and transcription into a unified framework, is proposed. Compared with previous systems for scene text recognition, the proposed architecture possesses four distinctive properties: (1) It is end-to-end trainable, in contrast to most of the existing algorithms whose components are separately trained and tuned. (2) It naturally handles sequences in arbitrary lengths, involving no character segmentation or horizontal scale normalization. (3) It is not confined to any predefined lexicon and achieves remarkable performances in both lexicon-free and lexicon-based scene text recognition tasks. (4) It generates an effective yet much smaller model, which is more practical for real-world application scenarios.
  28. [Paper](https://arxiv.org/abs/1507.05717): Baoguang Shi, Xiang Bai, Cong Yao, "An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition", ArXiv, vol. abs/1507.05717, 2015.
  29. ## [Model Architecture](#content)
  30. CRNN use a vgg16 structure for feature extraction, the appending with two-layer bidirectional LSTM, finally use CTC to calculate loss. See src/crnn.py for details.
  31. ## [Dataset](#content)
  32. 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.
  33. We use five datasets mentioned in the paper.For training, we use the synthetic dataset([MJSynth](https://www.robots.ox.ac.uk/~vgg/data/text/) and [SynthText](https://github.com/ankush-me/SynthText)) released by Jaderberg etal as the training data, which contains 8 millions training images and their corresponding ground truth words.For evaluation, we use four popular benchmarks for scene text recognition, nalely ICDAR 2003([IC03](http://www.iapr-tc11.org/mediawiki/index.php?title=ICDAR_2003_Robust_Reading_Competitions)),ICDAR2013([IC13](https://rrc.cvc.uab.es/?ch=2&com=downloads)),IIIT 5k-word([IIIT5k](https://cvit.iiit.ac.in/research/projects/cvit-projects/the-iiit-5k-word-dataset)),and Street View Text([SVT](http://vision.ucsd.edu/~kai/grocr/)).
  34. ### [Dataset Prepare](#content)
  35. For datset `IC03`, `IIIT5k` and `SVT`, the original dataset from the official website can not be used directly in CRNN.
  36. - `IC03`, the text need to be cropped from the original image according to the words.xml.
  37. - `IIIT5k`, the annotation need to be extracted from the matlib data file.
  38. - `SVT`, the text need to be cropped from the original image according to the `train.xml` or `test.xml`.
  39. We provide `convert_ic03.py`, `convert_iiit5k.py`, `convert_svt.py` as exmples for the aboving preprocessing which you can refer to.
  40. ## [Environment Requirements](#contents)
  41. - Hardware(Ascend)
  42. - Prepare hardware environment with Ascend processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. You will be able to have access to related resources once approved.
  43. - Framework
  44. - [MindSpore](https://gitee.com/mindspore/mindspore)
  45. - For more information, please check the resources below:
  46. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  47. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  48. ## [Quick Start](#contents)
  49. - After the dataset is prepared, you may start running the training or the evaluation scripts as follows:
  50. - Running on Ascend
  51. ```shell
  52. # distribute training example in Ascend
  53. $ bash run_distribute_train.sh [DATASET_NAME] [RANK_TABLE_FILE] [DATASET_PATH]
  54. # evaluation example in Ascend
  55. $ bash run_eval.sh [DATASET_NAME] [DATASET_PATH] [CHECKPOINT_PATH] [PLATFORM]
  56. # standalone training example in Ascend
  57. $ bash run_standalone_train.sh [DATASET_NAME] [DATASET_PATH] [PLATFORM]
  58. ```
  59. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  60. Please follow the instructions in the link below:
  61. [hccl_tools](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools).
  62. ## [Script Description](#contents)
  63. ### [Script and Sample Code](#contents)
  64. ```shell
  65. crnn
  66. ├── README.md # Descriptions about CRNN
  67. ├── convert_ic03.py # Convert the original IC03 daatset
  68. ├── convert_iiit5k.py # Convert the original IIIT5K dataset
  69. ├── convert_svt.py # Convert the original SVT dataset
  70. ├── requirements.txt # Requirements for this dataset
  71. ├── scripts
  72. │   ├── run_distribute_train.sh # Launch distributed training in Ascend(8 pcs)
  73. │   ├── run_eval.sh # Launch evaluation
  74. │   └── run_standalone_train.sh # Launch standalone training(1 pcs)
  75. ├── src
  76. │   ├── config.py # Parameter configuration
  77. │   ├── crnn.py # crnn network definition
  78. │   ├── crnn_for_train.py # crnn network with grad, loss and gradient clip
  79. │   ├── dataset.py # Data preprocessing for training and evaluation
  80. │   ├── ic03_dataset.py # Data preprocessing for IC03
  81. │   ├── ic13_dataset.py # Data preprocessing for IC13
  82. │   ├── iiit5k_dataset.py # Data preprocessing for IIIT5K
  83. │   ├── loss.py # Ctcloss definition
  84. │   ├── metric.py # accuracy metric for crnn network
  85. │   └── svt_dataset.py # Data preprocessing for SVT
  86. └── train.py # Training script
  87. ├── eval.py # Evaluation Script
  88. ```
  89. ### [Script Parameters](#contents)
  90. #### Training Script Parameters
  91. ```shell
  92. # distributed training in Ascend
  93. Usage: bash run_distribute_train.sh [DATASET_NAME] [RANK_TABLE_FILE] [DATASET_PATH]
  94. # standalone training
  95. Usage: bash run_standalone_train.sh [DATASET_NAME] [DATASET_PATH] [PLATFORM]
  96. ```
  97. #### Parameters Configuration
  98. Parameters for both training and evaluation can be set in config.py.
  99. ```shell
  100. max_text_length": 23, # max number of digits in each
  101. "image_width": 100, # width of text images
  102. "image_height": 32, # height of text images
  103. "batch_size": 64, # batch size of input tensor
  104. "epoch_size": 10, # only valid for taining, which is always 1
  105. "hidden_size": 256, # hidden size in LSTM layers
  106. "learning_rate": 0.02, # initial learning rate
  107. "momentum": 0.95, # momentum of SGD optimizer
  108. "nesterov": True, # enable nesterov in SGD optimizer
  109. "save_checkpoint": True, # whether save checkpoint or not
  110. "save_checkpoint_steps": 1000, # the step interval between two checkpoints.
  111. "keep_checkpoint_max": 30, # only keep the last keep_checkpoint_max
  112. "save_checkpoint_path": "./", # path to save checkpoint
  113. "class_num": 37, # dataset class num
  114. "input_size": 512, # input size for LSTM layer
  115. "num_step": 24, # num step for LSTM layer
  116. "use_dropout": True, # whether use dropout
  117. "blank": 36 # add blank for classification
  118. ```
  119. ### [Dataset Preparation](#contents)
  120. - You may refer to "Generate dataset" in [Quick Start](#quick-start) to automatically generate a dataset, or you may choose to generate a text image dataset by yourself.
  121. ## [Training Process](#contents)
  122. - 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.
  123. ### [Training](#contents)
  124. - Run `run_standalone_train.sh` for non-distributed training of CRNN model, either on Ascend or on GPU.
  125. ``` bash
  126. bash run_standalone_train.sh [DATASET_NAME] [DATASET_PATH] [PLATFORM]
  127. ```
  128. #### [Distributed Training](#contents)
  129. - Run `run_distribute_train.sh` for distributed training of WarpCTC model on Ascend.
  130. ``` bash
  131. bash run_distribute_train.sh [DATASET_NAME] [RANK_TABLE_FILE] [DATASET_PATH]
  132. ```
  133. Check the `train_parallel0/log.txt` and you will get outputs as following:
  134. ```shell
  135. epoch: 10 step: 14110, loss is 0.0029097411
  136. Epoch time: 2743.688s, per step time: 0.097s
  137. ```
  138. ## [Evaluation Process](#contents)
  139. ### [Evaluation](#contents)
  140. - Run `run_eval.sh` for evaluation.
  141. ``` bash
  142. bash run_eval.sh [DATASET_NAME] [DATASET_PATH] [CHECKPOINT_PATH] [PLATFORM]
  143. ```
  144. Check the `eval/log.txt` and you will get outputs as following:
  145. ```shell
  146. result: {'CRNNAccuracy': (0.806)}
  147. ```
  148. ## [Model Description](#contents)
  149. ### [Performance](#contents)
  150. #### [Training Performance](#contents)
  151. | Parameters | Ascend 910 |
  152. | -------------------------- | --------------------------------------------------|
  153. | Model Version | v1.0 |
  154. | Resource | Ascend 910, CPU 2.60GHz 192cores, Memory 755G |
  155. | uploaded Date | 12/15/2020 (month/day/year) |
  156. | MindSpore Version | 1.0.1 |
  157. | Dataset | Synth |
  158. | Training Parameters | epoch=10, steps per epoch=14110, batch_size = 64 |
  159. | Optimizer | SGD |
  160. | Loss Function | CTCLoss |
  161. | outputs | probability |
  162. | Loss | 0.0029097411 |
  163. | Speed | 118ms/step(8pcs) |
  164. | Total time | 557 mins |
  165. | Parameters (M) | 83M (.ckpt file) |
  166. | Checkpoint for Fine tuning | 20.3M (.ckpt file) |
  167. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/crnn) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/crnn) |
  168. #### [Evaluation Performance](#contents)
  169. | Parameters | SVT | IIIT5K |
  170. | ------------------- | --------------------------- | --------------------------- |
  171. | Model Version | V1.0 | V1.0 |
  172. | Resource | Ascend 910 | Ascend 910 |
  173. | Uploaded Date | 12/15/2020 (month/day/year) | 12/15/2020 (month/day/year) |
  174. | MindSpore Version | 1.0.1 | 1.0.1 |
  175. | Dataset | SVT | IIIT5K |
  176. | batch_size | 1 | 1 |
  177. | outputs | ACC | ACC |
  178. | Accuracy | 80.9% | 80.6% |
  179. | Model for inference | 83M (.ckpt file) | 83M (.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)