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.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. This is the quantitative network of LeNet.
  22. ## [Model Architecture](#contents)
  23. LeNet is very simple, which contains 5 layers. The layer composition consists of 2 convolutional layers and 3 fully connected layers.
  24. ## [Dataset](#contents)
  25. Dataset used: [MNIST](<http://yann.lecun.com/exdb/mnist/>)
  26. - Dataset size 52.4M 60,000 28*28 in 10 classes
  27. - Train 60,000 images
  28. - Test 10,000 images
  29. - Data format binary files
  30. - Note Data will be processed in dataset.py
  31. - The directory structure is as follows:
  32. ```bash
  33. └─Data
  34. ├─test
  35. │ t10k-images.idx3-ubyte
  36. │ t10k-labels.idx1-ubyte
  37. └─train
  38. train-images.idx3-ubyte
  39. train-labels.idx1-ubyte
  40. ```
  41. ## [Environment Requirements](#contents)
  42. - Hardware:Ascend
  43. - Prepare hardware environment with Ascend
  44. - Framework
  45. - [MindSpore](https://www.mindspore.cn/install/en)
  46. - For more information, please check the resources below:
  47. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  48. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  49. ## [Quick Start](#contents)
  50. After installing MindSpore via the official website, you can start training and evaluation as follows:
  51. ```python
  52. # enter ../lenet directory and train lenet network,then a '.ckpt' file will be generated.
  53. sh run_standalone_train_ascend.sh [DATA_PATH]
  54. # enter lenet dir, train LeNet-Quant
  55. python train.py --device_target=Ascend --data_path=[DATA_PATH] --ckpt_path=[CKPT_PATH] --dataset_sink_mode=True
  56. #evaluate LeNet-Quant
  57. python eval.py --device_target=Ascend --data_path=[DATA_PATH] --ckpt_path=[CKPT_PATH] --dataset_sink_mode=True
  58. ```
  59. ## [Script Description](#contents)
  60. ## [Script and Sample Code](#contents)
  61. ```bash
  62. ├── model_zoo
  63. ├── README.md // descriptions about all the models
  64. ├── lenet_quant
  65. ├── README.md // descriptions about LeNet-Quant
  66. ├── src
  67. │ ├── config.py // parameter configuration
  68. │ ├── dataset.py // creating dataset
  69. │ ├── lenet_fusion.py // auto constructed quantitative network model of LeNet-Quant
  70. │ ├── lenet_quant.py // manual constructed quantitative network model of LeNet-Quant
  71. │ ├── loss_monitor.py //monitor of network's loss and other data
  72. ├── requirements.txt // package needed
  73. ├── train.py // training LeNet-Quant network with device Ascend
  74. ├── eval.py // evaluating LeNet-Quant network with device Ascend
  75. ```
  76. ## [Script Parameters](#contents)
  77. ```python
  78. Major parameters in train.py and config.py as follows:
  79. --data_path: The absolute full path to the train and evaluation datasets.
  80. --epoch_size: Total training epochs.
  81. --batch_size: Training batch size.
  82. --image_height: Image height used as input to the model.
  83. --image_width: Image width used as input the model.
  84. --device_target: Device where the code will be implemented. Optional values
  85. are "Ascend", "GPU", "CPU".Only "Ascend" is supported now.
  86. --ckpt_path: The absolute full path to the checkpoint file saved
  87. after training.
  88. --data_path: Path where the dataset is saved
  89. ```
  90. ## [Training Process](#contents)
  91. ### Training
  92. ```bash
  93. python train.py --device_target=Ascend --dataset_path=/home/datasets/MNIST --dataset_sink_mode=True > log.txt 2>&1 &
  94. ```
  95. After training, the loss value will be achieved as follows:
  96. ```bash
  97. # grep "Epoch " log.txt
  98. Epoch: [ 1/ 10], step: [ 937/ 937], loss: [0.0081], avg loss: [0.0081], time: [11268.6832ms]
  99. Epoch time: 11269.352, per step time: 12.027, avg loss: 0.008
  100. Epoch: [ 2/ 10], step: [ 937/ 937], loss: [0.0496], avg loss: [0.0496], time: [3085.2389ms]
  101. Epoch time: 3085.641, per step time: 3.293, avg loss: 0.050
  102. Epoch: [ 3/ 10], step: [ 937/ 937], loss: [0.0017], avg loss: [0.0017], time: [3085.3510ms]
  103. ...
  104. ...
  105. ```
  106. The model checkpoint will be saved in the current directory.
  107. ## [Evaluation Process](#contents)
  108. ### Evaluation
  109. Before running the command below, please check the checkpoint path used for evaluation.
  110. ```bash
  111. python eval.py --data_path Data --ckpt_path ckpt/checkpoint_lenet-1_937.ckpt > log.txt 2>&1 &
  112. ```
  113. You can view the results through the file "log.txt". The accuracy of the test dataset will be as follows:
  114. ```bash
  115. # grep "Accuracy: " log.txt
  116. 'Accuracy': 0.9842
  117. ```
  118. ## [Model Description](#contents)
  119. ### [Performance](#contents)
  120. #### Evaluation Performance
  121. | Parameters | LeNet |
  122. | -------------------------- | ----------------------------------------------------------- |
  123. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  124. | uploaded Date | 06/09/2020 (month/day/year) |
  125. | MindSpore Version | 0.5.0-beta |
  126. | Dataset | MNIST |
  127. | Training Parameters | epoch=10, steps=937, batch_size = 64, lr=0.01 |
  128. | Optimizer | Momentum |
  129. | Loss Function | Softmax Cross Entropy |
  130. | outputs | probability |
  131. | Loss | 0.002 |
  132. | Speed |3.29 ms/step |
  133. | Total time | 40s |
  134. | Checkpoint for Fine tuning | 482k (.ckpt file) |
  135. | Scripts | [scripts](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/lenet) |
  136. ## [Description of Random Situation](#contents)
  137. In dataset.py, we set the seed inside “create_dataset" function.
  138. ## [ModelZoo Homepage](#contents)
  139. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).