You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mindspore/model_zoo/official/cv/lenet/README.md

189 lines
7.4 KiB

5 years ago
# Contents
- [LeNet Description](#lenet-description)
- [Model Architecture](#model-architecture)
- [Dataset](#dataset)
- [Environment Requirements](#environment-requirements)
- [Quick Start](#quick-start)
5 years ago
- [Script Description](#script-description)
- [Script and Sample Code](#script-and-sample-code)
- [Script Parameters](#script-parameters)
- [Training Process](#training-process)
- [Training](#training)
- [Evaluation Process](#evaluation-process)
- [Evaluation](#evaluation)
- [Model Description](#model-description)
- [Performance](#performance)
- [Evaluation Performance](#evaluation-performance)
- [ModelZoo Homepage](#modelzoo-homepage)
## [LeNet Description](#contents)
5 years ago
LeNet was proposed in 1998, a typical convolutional neural network. It was used for digit recognition and got big success.
5 years ago
[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.
## [Model Architecture](#contents)
5 years ago
LeNet is very simple, which contains 5 layers. The layer composition consists of 2 convolutional layers and 3 fully connected layers.
## [Dataset](#contents)
5 years ago
4 years ago
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.
Dataset used: [MNIST](<http://yann.lecun.com/exdb/mnist/>)
5 years ago
- Dataset size52.4M60,000 28*28 in 10 classes
- Train60,000 images
- Test10,000 images
5 years ago
- Data formatbinary files
- NoteData will be processed in dataset.py
5 years ago
- The directory structure is as follows:
```bash
5 years ago
└─Data
├─test
│ t10k-images.idx3-ubyte
│ t10k-labels.idx1-ubyte
└─train
train-images.idx3-ubyte
train-labels.idx1-ubyte
```
## [Environment Requirements](#contents)
5 years ago
- HardwareAscend/GPU/CPU
- Prepare hardware environment with Ascend, GPU, or CPU processor.
5 years ago
- Framework
- [MindSpore](https://www.mindspore.cn/install/en)
5 years ago
- For more information, please check the resources below
- [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
- [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
5 years ago
## [Quick Start](#contents)
5 years ago
After installing MindSpore via the official website, you can start training and evaluation as follows:
5 years ago
```python
# enter script dir, train LeNet
sh run_standalone_train_ascend.sh [DATA_PATH] [CKPT_SAVE_PATH]
# enter script dir, evaluate LeNet
sh run_standalone_eval_ascend.sh [DATA_PATH] [CKPT_NAME]
```
## [Script Description](#contents)
5 years ago
### [Script and Sample Code](#contents)
5 years ago
```bash
5 years ago
├── cv
├── lenet
5 years ago
├── README.md // descriptions about lenet
├── requirements.txt // package needed
├── scripts
│ ├──run_standalone_train_cpu.sh // train in cpu
│ ├──run_standalone_train_gpu.sh // train in gpu
│ ├──run_standalone_train_ascend.sh // train in ascend
│ ├──run_standalone_eval_cpu.sh // evaluate in cpu
│ ├──run_standalone_eval_gpu.sh // evaluate in gpu
│ ├──run_standalone_eval_ascend.sh // evaluate in ascend
├── src
5 years ago
│ ├──dataset.py // creating dataset
│ ├──lenet.py // lenet architecture
│ ├──config.py // parameter configuration
├── train.py // training script
├── eval.py // evaluation script
5 years ago
```
## [Script Parameters](#contents)
```python
Major parameters in train.py and config.py as follows:
--data_path: The absolute full path to the train and evaluation datasets.
--epoch_size: Total training epochs.
--batch_size: Training batch size.
5 years ago
--image_height: Image height used as input to the model.
--image_width: Image width used as input the model.
5 years ago
--device_target: Device where the code will be implemented. Optional values
are "Ascend", "GPU", "CPU".
5 years ago
--checkpoint_path: The absolute full path to the checkpoint file saved
after training.
--data_path: Path where the dataset is saved
5 years ago
```
## [Training Process](#contents)
### Training
5 years ago
```bash
5 years ago
python train.py --data_path Data --ckpt_path ckpt > log.txt 2>&1 &
4 years ago
# or enter script dir, and run the script
5 years ago
sh run_standalone_train_ascend.sh Data ckpt
```
After training, the loss value will be achieved as follows:
```bash
5 years ago
# grep "loss is " log.txt
epoch: 1 step: 1, loss is 2.2791853
...
epoch: 1 step: 1536, loss is 1.9366643
epoch: 1 step: 1537, loss is 1.6983616
epoch: 1 step: 1538, loss is 1.0221305
...
```
The model checkpoint will be saved in the current directory.
5 years ago
## [Evaluation Process](#contents)
### Evaluation
Before running the command below, please check the checkpoint path used for evaluation.
```bash
5 years ago
python eval.py --data_path Data --ckpt_path ckpt/checkpoint_lenet-1_1875.ckpt > log.txt 2>&1 &
4 years ago
# or enter script dir, and run the script
5 years ago
sh run_standalone_eval_ascend.sh Data ckpt/checkpoint_lenet-1_1875.ckpt
```
You can view the results through the file "log.txt". The accuracy of the test dataset will be as follows:
```bash
5 years ago
# grep "Accuracy: " log.txt
'Accuracy': 0.9842
5 years ago
```
## [Model Description](#contents)
5 years ago
### [Performance](#contents)
5 years ago
#### Evaluation Performance
5 years ago
| Parameters | LeNet |
| -------------------------- | ----------------------------------------------------------- |
| Resource | Ascend 910 CPU 2.60GHz192coresMemory755G |
4 years ago
| uploaded Date | 09/16/2020 (month/day/year) |
| MindSpore Version | 1.0.0 |
5 years ago
| Dataset | MNIST |
| Training Parameters | epoch=10, steps=1875, batch_size = 32, lr=0.01 |
| Optimizer | Momentum |
| Loss Function | Softmax Cross Entropy |
| outputs | probability |
| Loss | 0.002 |
4 years ago
| Speed | 1.071 ms/step |
| Total time | 32.1s | |
5 years ago
| Checkpoint for Fine tuning | 482k (.ckpt file) |
| Scripts | [LeNet Script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/lenet)s |
5 years ago
## [Description of Random Situation](#contents)
5 years ago
5 years ago
In dataset.py, we set the seed inside ```create_dataset``` function.
5 years ago
## [ModelZoo Homepage](#contents)
Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).