Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
jeffding ce74a2ab6f | 1 year ago | |
---|---|---|
.. | ||
ascend310_infer | 1 year ago | |
src | 1 year ago | |
README.md | 1 year ago | |
README_CN.md | 1 year ago | |
default_config.yaml | 1 year ago | |
eval.py | 1 year ago | |
export.py | 1 year ago | |
mindspore_hub_conf.py | 1 year ago | |
postprocess.py | 1 year ago | |
preprocess.py | 1 year ago | |
requirements.txt | 1 year ago | |
train.py | 1 year ago |
LeNet was proposed in 1998, a typical convolutional neural network. It was used for digit recognition and got big success.
Paper: Y.Lecun, L.Bottou, Y.Bengio, P.Haffner. Gradient-Based Learning Applied to Document Recognition. Proceedings of the IEEE. 1998.
LeNet is very simple, which contains 5 layers. The layer composition consists of 2 convolutional layers and 3 fully connected layers.
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
Dataset size:52.4M,60,000 28*28 in 10 classes
Data format:binary files
The directory structure is as follows:
└─Data
├─test
│ t10k-images.idx3-ubyte
│ t10k-labels.idx1-ubyte
│
└─train
train-images.idx3-ubyte
train-labels.idx1-ubyte
After installing MindSpore via the official website, you can start training and evaluation as follows:
# 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]
Running on ModelArts
# Train 8p with Ascend
# (1) Perform a or b.
# a. Set "enable_modelarts=True" on default_config.yaml file.
# Set "distribute=True" on default_config.yaml file.
# Set "data_path='/cache/data'" on default_config.yaml file.
# Set "ckpt_path='/cache/data'" on default_config.yaml file.
# (optional)Set "checkpoint_url='s3://dir_to_your_pretrained/'" on default_config.yaml file.
# Set other parameters on default_config.yaml file you need.
# b. Add "enable_modelarts=True" on the website UI interface.
# Add "need_modelarts_dataset_unzip=True" on the website UI interface.
# Add "data_path='/cache/data'" on the website UI interface.
# Add "ckpt_path='/cache/data'" on the website UI interface.
# (optional)Add "checkpoint_url='s3://dir_to_your_pretrained/'" on the website UI interface.
# Add other parameters on the website UI interface.
# (2) Prepare model code.
# (3) Upload or copy your pretrained model to S3 bucket if you want to finetune.
# (4) Upload the original mnist_data dataset to S3 bucket.
# (5) Set the code directory to "/path/lenet" on the website UI interface.
# (6) Set the startup file to "train.py" on the website UI interface.
# (7) Set the "Dataset path" and "Output file path" and "Job log path" to your path on the website UI interface.
# (8) Create your job.
#
# Train 1p with Ascend
# (1) Perform a or b.
# a. Set "enable_modelarts=True" on default_config.yaml file.
# Set "data_path='/cache/data'" on default_config.yaml file.
# Set "ckpt_path='/cache/data'" on default_config.yaml file.
# (optional)Set "checkpoint_url='s3://dir_to_your_pretrained/'" on default_config.yaml file.
# Set other parameters on default_config.yaml file you need.
# b. Add "enable_modelarts=True" on the website UI interface.
# Add "data_path='/cache/data'" on the website UI interface.
# Add "ckpt_path='/cache/data'" on the website UI interface.
# (optional)Add "checkpoint_url='s3://dir_to_your_pretrained/'" on the website UI interface.
# Add other parameters on the website UI interface.
# (2) Prepare model code.
# (3) Upload or copy your pretrained model to S3 bucket if you want to finetune.
# (4) Upload the original mnist_data dataset to S3 bucket.
# (5) Set the code directory to "/path/lenet" on the website UI interface.
# (6) Set the startup file to "train.py" on the website UI interface.
# (7) Set the "Dataset path" and "Output file path" and "Job log path" to your path on the website UI interface.
# (8) Create your job.
#
# Eval 1p with Ascend
# (1) Perform a or b.
# a. Set "enable_modelarts=True" on default_config.yaml file.
# Set "data_path='/cache/data'" on default_config.yaml file.
# Set "checkpoint_url='s3://dir_to_your_trained_model/'" on base_config.yaml file.
# Set "ckpt_file='/cache/data/checkpoint_lenet-10_1875.ckpt'" on default_config.yaml file.
# Set other parameters on default_config.yaml file you need.
# b. Add "enable_modelarts=True" on the website UI interface.
# Add "data_path='/cache/data'" on the website UI interface.
# Add "checkpoint_url='s3://dir_to_your_trained_model/'" on the website UI interface.
# Add "ckpt_file='/cache/data/checkpoint_lenet-10_1875.ckpt'" on the website UI interface.
# Add other parameters on the website UI interface.
# (2) Prepare model code.
# (3) Upload or copy your trained model to S3 bucket.
# (4) Upload the original mnist_data dataset to S3 bucket.
# (5) Set the code directory to "/path/lenet" on the website UI interface.
# (6) Set the startup file to "eval.py" on the website UI interface.
# (7) Set the "Dataset path" and "Output file path" and "Job log path" to your path on the website UI interface.
# (8) Create your job.
├── cv
├── lenet
├── README.md // descriptions about lenet
├── requirements.txt // package needed
├── ascend310_infer // application for 310 inference
├── scripts
│ ├──run_infer_310.sh // infer in 310
│ ├──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
│ ├──aipp.cfg // aipp config
│ ├──dataset.py // creating dataset
│ ├──lenet.py // lenet architecture
│ └──model_utils
│ ├──config.py // Processing configuration parameters
│ ├──device_adapter.py // Get cloud ID
│ ├──local_adapter.py // Get local ID
│ └──moxing_adapter.py // Parameter processing
├── default_config.yaml // Training parameter profile(ascend)
├── train.py // training script
├── eval.py // evaluation script
├── postprocess.py // postprocess script
├── preprocess.py // preprocess script
Major parameters in train.py and default_config.yaml as follows:
--data_path: The absolute full path to the train and evaluation datasets.
--epoch_size: Total training epochs.
--batch_size: Training batch size.
--image_height: Image height used as input to the model.
--image_width: Image width used as input the model.
--device_target: Device where the code will be implemented. Optional values
are "Ascend", "GPU", "CPU".
--checkpoint_path: The absolute full path to the checkpoint file saved
after training.
--data_path: Path where the dataset is saved
python train.py --config_path CONFIG_PATH --data_path Data --ckpt_path ckpt > log.txt 2>&1 &
# or enter script dir, and run the script
sh run_standalone_train_ascend.sh Data ckpt
After training, the loss value will be achieved as follows:
# 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.
Before running the command below, please check the checkpoint path used for evaluation.
python eval.py --config_path CONFIG_PATH --data_path Data --ckpt_path ckpt/checkpoint_lenet-1_1875.ckpt > log.txt 2>&1 &
# or enter script dir, and run the script
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:
# grep "Accuracy: " log.txt
'Accuracy': 0.9842
python export.py --config_path [CONFIG_PATH] --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
The ckpt_file parameter is required,
EXPORT_FORMAT
should be in ["AIR", "MINDIR"]
Before performing inference, the mindir file must be exported by export.py
script. We only provide an example of inference using MINDIR model.
Current batch_size can only be set to 1.
# Ascend310 inference
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [DEVICE_ID]
DVPP
is mandatory, and must choose from ["DVPP", "CPU"], it's case-insensitive.The size of the picture that Lenet performs inference is [32, 32], the DVPP hardware limits the width of divisible by 16, and the height is divisible by 2. The network conforms to the standard, and the network can pre-process the image through DVPP.DEVICE_ID
is optional, default value is 0.Inference result is saved in current path, you can find result like this in acc.log file.
'Accuracy': 0.9843
Parameters | LeNet |
---|---|
Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
uploaded Date | 09/16/2020 (month/day/year) |
MindSpore Version | 1.0.0 |
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 |
Speed | 1.071 ms/step |
Total time | 32.1s |
Checkpoint for Fine tuning | 482k (.ckpt file) |
Scripts | LeNet Scripts |
Parameters | Ascend |
---|---|
Model Version | LeNet |
Resource | Ascend 310; CentOS 3.10 |
Uploaded Date | 07/05/2021 (month/day/year) |
MindSpore Version | 1.2.0 |
Dataset | Mnist |
batch_size | 1 |
outputs | Accuracy |
Accuracy | Accuracy=0.9843 |
Model for inference | 482K(.ckpt file) |
In dataset.py, we set the seed inside create_dataset
function.
Please check the official homepage.
Huwei Ascend 910 Code
Text Unity3D Asset nesC Python Jupyter Notebook other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》