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.5 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. 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.
  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. ```
  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/GPU/CPU)
  43. - Prepare hardware environment with Ascend, GPU, or CPU processor.
  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 script dir, train LeNet
  53. sh run_standalone_train_ascend.sh [DATA_PATH] [CKPT_SAVE_PATH]
  54. # enter script dir, evaluate LeNet
  55. sh run_standalone_eval_ascend.sh [DATA_PATH] [CKPT_NAME]
  56. ```
  57. # [Script Description](#contents)
  58. ## [Script and Sample Code](#contents)
  59. ```
  60. ├── cv
  61. ├── lenet
  62. ├── README.md // descriptions about lenet
  63. ├── requirements.txt // package needed
  64. ├── scripts
  65. │ ├──run_standalone_train_cpu.sh // train in cpu
  66. │ ├──run_standalone_train_gpu.sh // train in gpu
  67. │ ├──run_standalone_train_ascend.sh // train in ascend
  68. │ ├──run_standalone_eval_cpu.sh // evaluate in cpu
  69. │ ├──run_standalone_eval_gpu.sh // evaluate in gpu
  70. │ ├──run_standalone_eval_ascend.sh // evaluate in ascend
  71. ├── src
  72. │ ├──dataset.py // creating dataset
  73. │ ├──lenet.py // lenet architecture
  74. │ ├──config.py // parameter configuration
  75. ├── train.py // training script
  76. ├── eval.py // evaluation script
  77. ```
  78. ## [Script Parameters](#contents)
  79. ```python
  80. Major parameters in train.py and config.py as follows:
  81. --data_path: The absolute full path to the train and evaluation datasets.
  82. --epoch_size: Total training epochs.
  83. --batch_size: Training batch size.
  84. --image_height: Image height used as input to the model.
  85. --image_width: Image width used as input the model.
  86. --device_target: Device where the code will be implemented. Optional values
  87. are "Ascend", "GPU", "CPU".
  88. --checkpoint_path: The absolute full path to the checkpoint file saved
  89. after training.
  90. --data_path: Path where the dataset is saved
  91. ```
  92. ## [Training Process](#contents)
  93. ### Training
  94. ```
  95. python train.py --data_path Data --ckpt_path ckpt > log.txt 2>&1 &
  96. # or enter script dir, and run the script
  97. sh run_standalone_train_ascend.sh Data ckpt
  98. ```
  99. After training, the loss value will be achieved as follows:
  100. ```
  101. # grep "loss is " log.txt
  102. epoch: 1 step: 1, loss is 2.2791853
  103. ...
  104. epoch: 1 step: 1536, loss is 1.9366643
  105. epoch: 1 step: 1537, loss is 1.6983616
  106. epoch: 1 step: 1538, loss is 1.0221305
  107. ...
  108. ```
  109. The model checkpoint will be saved in the current directory.
  110. ## [Evaluation Process](#contents)
  111. ### Evaluation
  112. Before running the command below, please check the checkpoint path used for evaluation.
  113. ```
  114. python eval.py --data_path Data --ckpt_path ckpt/checkpoint_lenet-1_1875.ckpt > log.txt 2>&1 &
  115. # or enter script dir, and run the script
  116. sh run_standalone_eval_ascend.sh Data ckpt/checkpoint_lenet-1_1875.ckpt
  117. ```
  118. You can view the results through the file "log.txt". The accuracy of the test dataset will be as follows:
  119. ```
  120. # grep "Accuracy: " log.txt
  121. 'Accuracy': 0.9842
  122. ```
  123. # [Model Description](#contents)
  124. ## [Performance](#contents)
  125. ### Evaluation Performance
  126. | Parameters | LeNet |
  127. | -------------------------- | ----------------------------------------------------------- |
  128. | Resource | Ascend 910 ;CPU 2.60GHz,192cores;Memory,755G |
  129. | uploaded Date | 09/16/2020 (month/day/year) |
  130. | MindSpore Version | 1.0.0 |
  131. | Dataset | MNIST |
  132. | Training Parameters | epoch=10, steps=1875, batch_size = 32, lr=0.01 |
  133. | Optimizer | Momentum |
  134. | Loss Function | Softmax Cross Entropy |
  135. | outputs | probability |
  136. | Loss | 0.002 |
  137. | Speed | 1.071 ms/step |
  138. | Total time | 32.1s | |
  139. | Checkpoint for Fine tuning | 482k (.ckpt file) |
  140. | Scripts | https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/lenet |
  141. # [Description of Random Situation](#contents)
  142. In dataset.py, we set the seed inside ```create_dataset``` function.
  143. # [ModelZoo Homepage](#contents)
  144. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).