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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Contents
  2. - [LeNet Description](#lenet-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 Process](#training-process)
  11. - [Training](#training)
  12. - [Evaluation Process](#evaluation-process)
  13. - [Evaluation](#evaluation)
  14. - [Model Description](#model-description)
  15. - [Performance](#performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [ModelZoo Homepage](#modelzoo-homepage)
  18. # [LeNet Description](#contents)
  19. LeNet was proposed in 1998, a typical convolutional neural network. It was used for digit recognition and got big success.
  20. [Paper](https://ieeexplore.ieee.org/document/726791): Y.Lecun, L.Bottou, Y.Bengio, P.Haffner. Gradient-Based Learning Applied to Document Recognition. *Proceedings of the IEEE*. 1998.
  21. # [Model Architecture](#contents)
  22. LeNet is very simple, which contains 5 layers. The layer composition consists of 2 convolutional layers and 3 fully connected layers.
  23. # [Dataset](#contents)
  24. Dataset used: [MNIST](<http://yann.lecun.com/exdb/mnist/>)
  25. - Dataset size:52.4M,60,000 28*28 in 10 classes
  26. - Train:60,000 images
  27. - Test:10,000 images
  28. - Data format:binary files
  29. - Note:Data will be processed in dataset.py
  30. - The directory structure is as follows:
  31. ```
  32. └─Data
  33. ├─test
  34. │ t10k-images.idx3-ubyte
  35. │ t10k-labels.idx1-ubyte
  36. └─train
  37. train-images.idx3-ubyte
  38. train-labels.idx1-ubyte
  39. ```
  40. # [Environment Requirements](#contents)
  41. - Hardware(Ascend/GPU/CPU)
  42. - Prepare hardware environment with Ascend, GPU, or CPU processor.
  43. - Framework
  44. - [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
  45. - For more information, please check the resources below:
  46. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
  47. - [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)
  48. # [Quick Start](#contents)
  49. After installing MindSpore via the official website, you can start training and evaluation as follows:
  50. ```python
  51. # enter script dir, train LeNet
  52. sh run_standalone_train_ascend.sh [DATA_PATH] [CKPT_SAVE_PATH]
  53. # enter script dir, evaluate LeNet
  54. sh run_standalone_eval_ascend.sh [DATA_PATH] [CKPT_NAME]
  55. ```
  56. # [Script Description](#contents)
  57. ## [Script and Sample Code](#contents)
  58. ```
  59. ├── cv
  60. ├── lenet
  61. ├── README.md // descriptions about lenet
  62. ├── requirements.txt // package needed
  63. ├── scripts
  64. │ ├──run_standalone_train_cpu.sh // train in cpu
  65. │ ├──run_standalone_train_gpu.sh // train in gpu
  66. │ ├──run_standalone_train_ascend.sh // train in ascend
  67. │ ├──run_standalone_eval_cpu.sh // evaluate in cpu
  68. │ ├──run_standalone_eval_gpu.sh // evaluate in gpu
  69. │ ├──run_standalone_eval_ascend.sh // evaluate in ascend
  70. ├── src
  71. │ ├──dataset.py // creating dataset
  72. │ ├──lenet.py // lenet architecture
  73. │ ├──config.py // parameter configuration
  74. ├── train.py // training script
  75. ├── eval.py // evaluation script
  76. ```
  77. ## [Script Parameters](#contents)
  78. ```python
  79. Major parameters in train.py and config.py as follows:
  80. --data_path: The absolute full path to the train and evaluation datasets.
  81. --epoch_size: Total training epochs.
  82. --batch_size: Training batch size.
  83. --image_height: Image height used as input to the model.
  84. --image_width: Image width used as input the model.
  85. --device_target: Device where the code will be implemented. Optional values
  86. are "Ascend", "GPU", "CPU".
  87. --checkpoint_path: The absolute full path to the checkpoint file saved
  88. after training.
  89. --data_path: Path where the dataset is saved
  90. ```
  91. ## [Training Process](#contents)
  92. ### Training
  93. ```
  94. python train.py --data_path Data --ckpt_path ckpt > log.txt 2>&1 &
  95. or enter script dir, and run the script
  96. sh run_standalone_train_ascend.sh Data ckpt
  97. ```
  98. After training, the loss value will be achieved as follows:
  99. ```
  100. # grep "loss is " log.txt
  101. epoch: 1 step: 1, loss is 2.2791853
  102. ...
  103. epoch: 1 step: 1536, loss is 1.9366643
  104. epoch: 1 step: 1537, loss is 1.6983616
  105. epoch: 1 step: 1538, loss is 1.0221305
  106. ...
  107. ```
  108. The model checkpoint will be saved in the current directory.
  109. ## [Evaluation Process](#contents)
  110. ### Evaluation
  111. Before running the command below, please check the checkpoint path used for evaluation.
  112. ```
  113. python eval.py --data_path Data --ckpt_path ckpt/checkpoint_lenet-1_1875.ckpt > log.txt 2>&1 &
  114. or enter script dir, and run the script
  115. sh run_standalone_eval_ascend.sh Data ckpt/checkpoint_lenet-1_1875.ckpt
  116. ```
  117. You can view the results through the file "log.txt". The accuracy of the test dataset will be as follows:
  118. ```
  119. # grep "Accuracy: " log.txt
  120. 'Accuracy': 0.9842
  121. ```
  122. # [Model Description](#contents)
  123. ## [Performance](#contents)
  124. ### Evaluation Performance
  125. | Parameters | LeNet |
  126. | -------------------------- | ----------------------------------------------------------- |
  127. | Resource | Ascend 910 ;CPU 2.60GHz,56cores;Memory,314G |
  128. | uploaded Date | 06/09/2020 (month/day/year) |
  129. | MindSpore Version | 0.5.0-beta |
  130. | Dataset | MNIST |
  131. | Training Parameters | epoch=10, steps=1875, batch_size = 32, lr=0.01 |
  132. | Optimizer | Momentum |
  133. | Loss Function | Softmax Cross Entropy |
  134. | outputs | probability |
  135. | Loss | 0.002 |
  136. | Speed | 1.70 ms/step |
  137. | Total time | 43.1s | |
  138. | Checkpoint for Fine tuning | 482k (.ckpt file) |
  139. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/lenet |
  140. # [Description of Random Situation](#contents)
  141. In dataset.py, we set the seed inside ```create_dataset``` function.
  142. # [ModelZoo Homepage](#contents)
  143. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).