forked from mindspore-Ecosystem/mindspore
!11488 add switch in readme
From: @chen_ying113 Reviewed-by: Signed-off-by:
This commit is contained in:
commit
67a502e689
|
@ -1,4 +1,6 @@
|
|||
# Contents
|
||||
# Contents
|
||||
|
||||
[查看中文](./README_CN.md)
|
||||
|
||||
- [GoogleNet Description](#googlenet-description)
|
||||
- [Model Architecture](#model-architecture)
|
||||
|
@ -6,7 +8,7 @@
|
|||
- [Features](#features)
|
||||
- [Mixed Precision](#mixed-precision)
|
||||
- [Environment Requirements](#environment-requirements)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Script Description](#script-description)
|
||||
- [Script and Sample Code](#script-and-sample-code)
|
||||
- [Script Parameters](#script-parameters)
|
||||
|
@ -20,81 +22,74 @@
|
|||
- [Evaluation Performance](#evaluation-performance)
|
||||
- [Inference Performance](#evaluation-performance)
|
||||
- [How to use](#how-to-use)
|
||||
- [Inference](#inference)
|
||||
- [Inference](#inference)
|
||||
- [Continue Training on the Pretrained Model](#continue-training-on-the-pretrained-model)
|
||||
- [Transfer Learning](#transfer-learning)
|
||||
- [Transfer Learning](#transfer-learning)
|
||||
- [Description of Random Situation](#description-of-random-situation)
|
||||
- [ModelZoo Homepage](#modelzoo-homepage)
|
||||
|
||||
|
||||
# [GoogleNet Description](#contents)
|
||||
|
||||
GoogleNet, a 22 layers deep network, was proposed in 2014 and won the first place in the ImageNet Large-Scale Visual Recognition Challenge 2014 (ILSVRC14). GoogleNet, also called Inception v1, has significant improvement over ZFNet (The winner in 2013) and AlexNet (The winner in 2012), and has relatively lower error rate compared to VGGNet. Typically deeper deep learning network means larger number of parameters, which makes it more prone to overfitting. Furthermore, the increased network size leads to increased use of computational resources. To tackle these issues, GoogleNet adopts 1*1 convolution middle of the network to reduce dimension, and thus further reduce the computation. Global average pooling is used at the end of the network, instead of using fully connected layers. Another technique, called inception module, is to have different sizes of convolutions for the same input and stacking all the outputs.
|
||||
GoogleNet, a 22 layers deep network, was proposed in 2014 and won the first place in the ImageNet Large-Scale Visual Recognition Challenge 2014 (ILSVRC14). GoogleNet, also called Inception v1, has significant improvement over ZFNet (The winner in 2013) and AlexNet (The winner in 2012), and has relatively lower error rate compared to VGGNet. Typically deeper deep learning network means larger number of parameters, which makes it more prone to overfitting. Furthermore, the increased network size leads to increased use of computational resources. To tackle these issues, GoogleNet adopts 1*1 convolution middle of the network to reduce dimension, and thus further reduce the computation. Global average pooling is used at the end of the network, instead of using fully connected layers. Another technique, called inception module, is to have different sizes of convolutions for the same input and stacking all the outputs.
|
||||
|
||||
[Paper](https://arxiv.org/abs/1409.4842): Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed, Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, Andrew Rabinovich. "Going deeper with convolutions." *Proceedings of the IEEE conference on computer vision and pattern recognition*. 2015.
|
||||
|
||||
|
||||
# [Model Architecture](#contents)
|
||||
|
||||
Specifically, the GoogleNet contains numerous inception modules, which are connected together to go deeper. In general, an inception module with dimensionality reduction consists of **1×1 conv**, **3×3 conv**, **5×5 conv**, and **3×3 max pooling**, which are done altogether for the previous input, and stack together again at output. In our model architecture, the kernel size used in inception module is 3×3 instead of 5×5.
|
||||
|
||||
|
||||
|
||||
# [Dataset](#contents)
|
||||
|
||||
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: [CIFAR-10](<http://www.cs.toronto.edu/~kriz/cifar.html>)
|
||||
Dataset used: [CIFAR-10](http://www.cs.toronto.edu/~kriz/cifar.html)
|
||||
|
||||
- Dataset size:175M,60,000 32*32 colorful images in 10 classes
|
||||
- Train:146M,50,000 images
|
||||
- Test:29M,10,000 images
|
||||
- Train:146M,50,000 images
|
||||
- Test:29M,10,000 images
|
||||
- Data format:binary files
|
||||
- Note:Data will be processed in src/dataset.py
|
||||
- Note:Data will be processed in src/dataset.py
|
||||
|
||||
Dataset used can refer to paper.
|
||||
|
||||
- Dataset size: 125G, 1250k colorful images in 1000 classes
|
||||
- Train: 120G, 1200k images
|
||||
- Test: 5G, 50k images
|
||||
- Train: 120G, 1200k images
|
||||
- Test: 5G, 50k images
|
||||
- Data format: RGB images.
|
||||
- Note: Data will be processed in src/dataset.py
|
||||
- Note: Data will be processed in src/dataset.py
|
||||
|
||||
# [Features](#contents)
|
||||
|
||||
## Mixed Precision
|
||||
|
||||
The [mixed precision](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/enable_mixed_precision.html) training method accelerates the deep learning neural network training process by using both the single-precision and half-precision data formats, and maintains the network precision achieved by the single-precision training at the same time. Mixed precision training can accelerate the computation process, reduce memory usage, and enable a larger model or batch size to be trained on specific hardware.
|
||||
The [mixed precision](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/enable_mixed_precision.html) training method accelerates the deep learning neural network training process by using both the single-precision and half-precision data formats, and maintains the network precision achieved by the single-precision training at the same time. Mixed precision training can accelerate the computation process, reduce memory usage, and enable a larger model or batch size to be trained on specific hardware.
|
||||
For FP16 operators, if the input data type is FP32, the backend of MindSpore will automatically handle it with reduced precision. Users could check the reduced-precision operators by enabling INFO log and then searching ‘reduce precision’.
|
||||
|
||||
|
||||
|
||||
# [Environment Requirements](#contents)
|
||||
|
||||
- Hardware(Ascend/GPU)
|
||||
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
|
||||
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
|
||||
- Framework
|
||||
- [MindSpore](https://www.mindspore.cn/install/en)
|
||||
- [MindSpore](https://www.mindspore.cn/install/en)
|
||||
- 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)
|
||||
|
||||
|
||||
- [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)
|
||||
|
||||
# [Quick Start](#contents)
|
||||
|
||||
After installing MindSpore via the official website, you can start training and evaluation as follows:
|
||||
After installing MindSpore via the official website, you can start training and evaluation as follows:
|
||||
|
||||
- runing on Ascend
|
||||
- running on Ascend
|
||||
|
||||
```python
|
||||
# run training example
|
||||
python train.py > train.log 2>&1 &
|
||||
|
||||
python train.py > train.log 2>&1 &
|
||||
|
||||
# run distributed training example
|
||||
sh scripts/run_train.sh rank_table.json
|
||||
|
||||
|
||||
# run evaluation example
|
||||
python eval.py > eval.log 2>&1 &
|
||||
python eval.py > eval.log 2>&1 &
|
||||
OR
|
||||
sh run_eval.sh
|
||||
```
|
||||
|
@ -103,7 +98,7 @@ After installing MindSpore via the official website, you can start training and
|
|||
|
||||
Please follow the instructions in the link below:
|
||||
|
||||
https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools.
|
||||
<https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools>.
|
||||
|
||||
- running on GPU
|
||||
|
||||
|
@ -112,42 +107,40 @@ After installing MindSpore via the official website, you can start training and
|
|||
```python
|
||||
# run training example
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
python train.py > train.log 2>&1 &
|
||||
|
||||
python train.py > train.log 2>&1 &
|
||||
|
||||
# run distributed training example
|
||||
sh scripts/run_train_gpu.sh 8 0,1,2,3,4,5,6,7
|
||||
|
||||
|
||||
# run evaluation example
|
||||
python eval.py --checkpoint_path=[CHECKPOINT_PATH] > eval.log 2>&1 &
|
||||
OR
|
||||
sh run_eval_gpu.sh [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
|
||||
We use CIFAR-10 dataset by default. Your can also pass `$dataset_type` to the scripts so that select different datasets. For more details, please refer the specify script.
|
||||
|
||||
|
||||
# [Script Description](#contents)
|
||||
|
||||
## [Script and Sample Code](#contents)
|
||||
|
||||
```
|
||||
```text
|
||||
├── model_zoo
|
||||
├── README.md // descriptions about all the models
|
||||
├── googlenet
|
||||
├── googlenet
|
||||
├── README.md // descriptions about googlenet
|
||||
├── scripts
|
||||
├── scripts
|
||||
│ ├──run_train.sh // shell script for distributed on Ascend
|
||||
│ ├──run_train_gpu.sh // shell script for distributed on GPU
|
||||
│ ├──run_eval.sh // shell script for evaluation on Ascend
|
||||
│ ├──run_eval_gpu.sh // shell script for evaluation on GPU
|
||||
├── src
|
||||
├── src
|
||||
│ ├──dataset.py // creating dataset
|
||||
│ ├──googlenet.py // googlenet architecture
|
||||
│ ├──config.py // parameter configuration
|
||||
├── train.py // training script
|
||||
├── eval.py // evaluation script
|
||||
├── export.py // export checkpoint files into air/onnx
|
||||
│ ├──config.py // parameter configuration
|
||||
├── train.py // training script
|
||||
├── eval.py // evaluation script
|
||||
├── export.py // export checkpoint files into air/onnx
|
||||
```
|
||||
|
||||
## [Script Parameters](#contents)
|
||||
|
@ -207,55 +200,53 @@ Parameters for both training and evaluation can be set in config.py
|
|||
'use_label_smooth': True # label smooth
|
||||
```
|
||||
|
||||
|
||||
For more configuration details, please refer the script `config.py`.
|
||||
|
||||
## [Training Process](#contents)
|
||||
|
||||
### Training
|
||||
### Training
|
||||
|
||||
- running on Ascend
|
||||
|
||||
```python
|
||||
python train.py > train.log 2>&1 &
|
||||
```
|
||||
python train.py > train.log 2>&1 &
|
||||
```
|
||||
|
||||
|
||||
The python command above will run in the background, you can view the results through the file `train.log`.
|
||||
|
||||
|
||||
After training, you'll get some checkpoint files under the script folder by default. The loss value will be achieved as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "loss is " train.log
|
||||
epoch: 1 step: 390, loss is 1.4842823
|
||||
epcoh: 2 step: 390, loss is 1.0897788
|
||||
...
|
||||
```
|
||||
|
||||
The model checkpoint will be saved in the current directory.
|
||||
|
||||
The model checkpoint will be saved in the current directory.
|
||||
|
||||
- running on GPU
|
||||
|
||||
```
|
||||
```python
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
python train.py > train.log 2>&1 &
|
||||
python train.py > train.log 2>&1 &
|
||||
```
|
||||
|
||||
The python command above will run in the background, you can view the results through the file `train.log`.
|
||||
|
||||
After training, you'll get some checkpoint files under the folder `./ckpt_0/` by default.
|
||||
|
||||
After training, you'll get some checkpoint files under the folder `./ckpt_0/` by default.
|
||||
|
||||
### Distributed Training
|
||||
|
||||
- running on Ascend
|
||||
|
||||
```
|
||||
```bash
|
||||
sh scripts/run_train.sh rank_table.json
|
||||
```
|
||||
|
||||
|
||||
The above shell script will run distribute training in the background. You can view the results through the file `train_parallel[X]/log`. The loss value will be achieved as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "result: " train_parallel*/log
|
||||
train_parallel0/log:epoch: 1 step: 48, loss is 1.4302931
|
||||
train_parallel0/log:epcoh: 2 step: 48, loss is 1.4023874
|
||||
|
@ -268,12 +259,11 @@ For more configuration details, please refer the script `config.py`.
|
|||
|
||||
- running on GPU
|
||||
|
||||
```
|
||||
```bash
|
||||
sh scripts/run_train_gpu.sh 8 0,1,2,3,4,5,6,7
|
||||
```
|
||||
|
||||
The above shell script will run distribute training in the background. You can view the results through the file `train/train.log`.
|
||||
|
||||
The above shell script will run distribute training in the background. You can view the results through the file `train/train.log`.
|
||||
|
||||
## [Evaluation Process](#contents)
|
||||
|
||||
|
@ -282,23 +272,23 @@ For more configuration details, please refer the script `config.py`.
|
|||
- evaluation on CIFAR-10 dataset when running on Ascend
|
||||
|
||||
Before running the command below, please check the checkpoint path used for evaluation. Please set the checkpoint path to be the absolute full path, e.g., "username/googlenet/train_googlenet_cifar10-125_390.ckpt".
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
python eval.py > eval.log 2>&1 &
|
||||
OR
|
||||
sh scripts/run_eval.sh
|
||||
```
|
||||
|
||||
|
||||
The above python command will run in the background. You can view the results through the file "eval.log". The accuracy of the test dataset will be as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "accuracy: " eval.log
|
||||
accuracy: {'acc': 0.934}
|
||||
```
|
||||
|
||||
|
||||
Note that for evaluation after distributed training, please set the checkpoint_path to be the last saved checkpoint file such as "username/googlenet/train_parallel0/train_googlenet_cifar10-125_48.ckpt". The accuracy of the test dataset will be as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "accuracy: " eval.log
|
||||
accuracy: {'acc': 0.9217}
|
||||
```
|
||||
|
@ -306,40 +296,39 @@ For more configuration details, please refer the script `config.py`.
|
|||
- evaluation on CIFAR-10 dataset when running on GPU
|
||||
|
||||
Before running the command below, please check the checkpoint path used for evaluation. Please set the checkpoint path to be the absolute full path, e.g., "username/googlenet/train/ckpt_0/train_googlenet_cifar10-125_390.ckpt".
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
python eval.py --checkpoint_path=[CHECKPOINT_PATH] > eval.log 2>&1 &
|
||||
```
|
||||
|
||||
|
||||
The above python command will run in the background. You can view the results through the file "eval.log". The accuracy of the test dataset will be as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "accuracy: " eval.log
|
||||
accuracy: {'acc': 0.930}
|
||||
```
|
||||
|
||||
OR,
|
||||
|
||||
```
|
||||
```bash
|
||||
sh scripts/run_eval_gpu.sh [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
|
||||
The above python command will run in the background. You can view the results through the file "eval/eval.log". The accuracy of the test dataset will be as follows:
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
# grep "accuracy: " eval/eval.log
|
||||
accuracy: {'acc': 0.930}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
# [Model Description](#contents)
|
||||
|
||||
## [Performance](#contents)
|
||||
|
||||
### Evaluation Performance
|
||||
### Evaluation Performance
|
||||
|
||||
#### GoogleNet on CIFAR-10
|
||||
|
||||
| Parameters | Ascend | GPU |
|
||||
| -------------------------- | ----------------------------------------------------------- | ---------------------- |
|
||||
| Model Version | Inception V1 | Inception V1 |
|
||||
|
@ -353,13 +342,14 @@ For more configuration details, please refer the script `config.py`.
|
|||
| outputs | probability | probobility |
|
||||
| Loss | 0.0016 | 0.0016 |
|
||||
| Speed | 1pc: 79 ms/step; 8pcs: 82 ms/step | 1pc: 150 ms/step; 8pcs: 164 ms/step |
|
||||
| Total time | 1pc: 63.85 mins; 8pcs: 11.28 mins | 1pc: 126.87 mins; 8pcs: 21.65 mins |
|
||||
| Total time | 1pc: 63.85 mins; 8pcs: 11.28 mins | 1pc: 126.87 mins; 8pcs: 21.65 mins |
|
||||
| Parameters (M) | 13.0 | 13.0 |
|
||||
| Checkpoint for Fine tuning | 43.07M (.ckpt file) | 43.07M (.ckpt file) |
|
||||
| Model for inference | 21.50M (.onnx file), 21.60M(.air file) | |
|
||||
| Model for inference | 21.50M (.onnx file), 21.60M(.air file) | |
|
||||
| Scripts | [googlenet script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/googlenet) | [googlenet script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/googlenet) |
|
||||
|
||||
#### GoogleNet on 1200k images
|
||||
|
||||
| Parameters | Ascend |
|
||||
| -------------------------- | ----------------------------------------------------------- |
|
||||
| Model Version | Inception V1 |
|
||||
|
@ -376,12 +366,12 @@ For more configuration details, please refer the script `config.py`.
|
|||
| Total time | 8pcs: 8.8 hours |
|
||||
| Parameters (M) | 13.0 |
|
||||
| Checkpoint for Fine tuning | 52M (.ckpt file) |
|
||||
| Scripts | [googlenet script](https://gitee.com/mindspore/mindspore/tree/r0.7/model_zoo/official/cv/googlenet) |
|
||||
|
||||
| Scripts | [googlenet script](https://gitee.com/mindspore/mindspore/tree/r0.7/model_zoo/official/cv/googlenet) |
|
||||
|
||||
### Inference Performance
|
||||
|
||||
#### GoogleNet on CIFAR-10
|
||||
|
||||
| Parameters | Ascend | GPU |
|
||||
| ------------------- | --------------------------- | --------------------------- |
|
||||
| Model Version | Inception V1 | Inception V1 |
|
||||
|
@ -395,6 +385,7 @@ For more configuration details, please refer the script `config.py`.
|
|||
| Model for inference | 21.50M (.onnx file) | |
|
||||
|
||||
#### GoogleNet on 1200k images
|
||||
|
||||
| Parameters | Ascend |
|
||||
| ------------------- | --------------------------- |
|
||||
| Model Version | Inception V1 |
|
||||
|
@ -407,32 +398,33 @@ For more configuration details, please refer the script `config.py`.
|
|||
| Accuracy | 8pcs: 71.81% |
|
||||
|
||||
## [How to use](#contents)
|
||||
|
||||
### Inference
|
||||
|
||||
If you need to use the trained model to perform inference on multiple hardware platforms, such as GPU, Ascend 910 or Ascend 310, you can refer to this [Link](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/migrate_3rd_scripts.html). Following the steps below, this is a simple example:
|
||||
|
||||
- Running on Ascend
|
||||
|
||||
```
|
||||
```python
|
||||
# Set context
|
||||
context.set_context(mode=context.GRAPH_HOME, device_target=cfg.device_target)
|
||||
context.set_context(device_id=cfg.device_id)
|
||||
|
||||
|
||||
# Load unseen dataset for inference
|
||||
dataset = dataset.create_dataset(cfg.data_path, 1, False)
|
||||
|
||||
# Define model
|
||||
|
||||
# Define model
|
||||
net = GoogleNet(num_classes=cfg.num_classes)
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()), 0.01,
|
||||
cfg.momentum, weight_decay=cfg.weight_decay)
|
||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
|
||||
model = Model(net, loss_fn=loss, optimizer=opt, metrics={'acc'})
|
||||
|
||||
|
||||
# Load pre-trained model
|
||||
param_dict = load_checkpoint(cfg.checkpoint_path)
|
||||
load_param_into_net(net, param_dict)
|
||||
net.set_train(False)
|
||||
|
||||
|
||||
# Make predictions on the unseen dataset
|
||||
acc = model.eval(dataset)
|
||||
print("accuracy: ", acc)
|
||||
|
@ -440,62 +432,62 @@ If you need to use the trained model to perform inference on multiple hardware p
|
|||
|
||||
- Running on GPU:
|
||||
|
||||
```
|
||||
```python
|
||||
# Set context
|
||||
context.set_context(mode=context.GRAPH_HOME, device_target="GPU")
|
||||
|
||||
|
||||
# Load unseen dataset for inference
|
||||
dataset = dataset.create_dataset(cfg.data_path, 1, False)
|
||||
|
||||
# Define model
|
||||
|
||||
# Define model
|
||||
net = GoogleNet(num_classes=cfg.num_classes)
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()), 0.01,
|
||||
cfg.momentum, weight_decay=cfg.weight_decay)
|
||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
|
||||
model = Model(net, loss_fn=loss, optimizer=opt, metrics={'acc'})
|
||||
|
||||
|
||||
# Load pre-trained model
|
||||
param_dict = load_checkpoint(args_opt.checkpoint_path)
|
||||
load_param_into_net(net, param_dict)
|
||||
net.set_train(False)
|
||||
|
||||
|
||||
# Make predictions on the unseen dataset
|
||||
acc = model.eval(dataset)
|
||||
print("accuracy: ", acc)
|
||||
|
||||
```
|
||||
|
||||
### Continue Training on the Pretrained Model
|
||||
### Continue Training on the Pretrained Model
|
||||
|
||||
- running on Ascend
|
||||
|
||||
```
|
||||
```python
|
||||
# Load dataset
|
||||
dataset = create_dataset(cfg.data_path, 1)
|
||||
batch_num = dataset.get_dataset_size()
|
||||
|
||||
|
||||
# Define model
|
||||
net = GoogleNet(num_classes=cfg.num_classes)
|
||||
# Continue training if set pre_trained to be True
|
||||
if cfg.pre_trained:
|
||||
param_dict = load_checkpoint(cfg.checkpoint_path)
|
||||
load_param_into_net(net, param_dict)
|
||||
lr = lr_steps(0, lr_max=cfg.lr_init, total_epochs=cfg.epoch_size,
|
||||
lr = lr_steps(0, lr_max=cfg.lr_init, total_epochs=cfg.epoch_size,
|
||||
steps_per_epoch=batch_num)
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()),
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()),
|
||||
Tensor(lr), cfg.momentum, weight_decay=cfg.weight_decay)
|
||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
|
||||
model = Model(net, loss_fn=loss, optimizer=opt, metrics={'acc'},
|
||||
amp_level="O2", keep_batchnorm_fp32=False, loss_scale_manager=None)
|
||||
|
||||
# Set callbacks
|
||||
config_ck = CheckpointConfig(save_checkpoint_steps=batch_num * 5,
|
||||
|
||||
# Set callbacks
|
||||
config_ck = CheckpointConfig(save_checkpoint_steps=batch_num * 5,
|
||||
keep_checkpoint_max=cfg.keep_checkpoint_max)
|
||||
time_cb = TimeMonitor(data_size=batch_num)
|
||||
ckpoint_cb = ModelCheckpoint(prefix="train_googlenet_cifar10", directory="./",
|
||||
ckpoint_cb = ModelCheckpoint(prefix="train_googlenet_cifar10", directory="./",
|
||||
config=config_ck)
|
||||
loss_cb = LossMonitor()
|
||||
|
||||
|
||||
# Start training
|
||||
model.train(cfg.epoch_size, dataset, callbacks=[time_cb, ckpoint_cb, loss_cb])
|
||||
print("train success")
|
||||
|
@ -503,46 +495,46 @@ If you need to use the trained model to perform inference on multiple hardware p
|
|||
|
||||
- running on GPU
|
||||
|
||||
```
|
||||
```python
|
||||
# Load dataset
|
||||
dataset = create_dataset(cfg.data_path, 1)
|
||||
batch_num = dataset.get_dataset_size()
|
||||
|
||||
|
||||
# Define model
|
||||
net = GoogleNet(num_classes=cfg.num_classes)
|
||||
# Continue training if set pre_trained to be True
|
||||
if cfg.pre_trained:
|
||||
param_dict = load_checkpoint(cfg.checkpoint_path)
|
||||
load_param_into_net(net, param_dict)
|
||||
lr = lr_steps(0, lr_max=cfg.lr_init, total_epochs=cfg.epoch_size,
|
||||
lr = lr_steps(0, lr_max=cfg.lr_init, total_epochs=cfg.epoch_size,
|
||||
steps_per_epoch=batch_num)
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()),
|
||||
opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()),
|
||||
Tensor(lr), cfg.momentum, weight_decay=cfg.weight_decay)
|
||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
|
||||
model = Model(net, loss_fn=loss, optimizer=opt, metrics={'acc'},
|
||||
amp_level="O2", keep_batchnorm_fp32=False, loss_scale_manager=None)
|
||||
|
||||
# Set callbacks
|
||||
config_ck = CheckpointConfig(save_checkpoint_steps=batch_num * 5,
|
||||
|
||||
# Set callbacks
|
||||
config_ck = CheckpointConfig(save_checkpoint_steps=batch_num * 5,
|
||||
keep_checkpoint_max=cfg.keep_checkpoint_max)
|
||||
time_cb = TimeMonitor(data_size=batch_num)
|
||||
ckpoint_cb = ModelCheckpoint(prefix="train_googlenet_cifar10", directory="./ckpt_" + str(get_rank()) + "/",
|
||||
ckpoint_cb = ModelCheckpoint(prefix="train_googlenet_cifar10", directory="./ckpt_" + str(get_rank()) + "/",
|
||||
config=config_ck)
|
||||
loss_cb = LossMonitor()
|
||||
|
||||
|
||||
# Start training
|
||||
model.train(cfg.epoch_size, dataset, callbacks=[time_cb, ckpoint_cb, loss_cb])
|
||||
print("train success")
|
||||
```
|
||||
|
||||
### Transfer Learning
|
||||
To be added.
|
||||
|
||||
To be added.
|
||||
|
||||
# [Description of Random Situation](#contents)
|
||||
|
||||
In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
|
||||
|
||||
In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
|
||||
|
||||
# [ModelZoo Homepage](#contents)
|
||||
|
||||
Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# 目录
|
||||
|
||||
[View English](./README.md)
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [目录](#目录)
|
||||
|
@ -513,4 +515,3 @@ GoogleNet由多个inception模块串联起来,可以更加深入。 降维的
|
|||
# ModelZoo主页
|
||||
|
||||
请浏览官网[主页](https://gitee.com/mindspore/mindspore/tree/master/model_zoo)。
|
||||
|
||||
|
|
Loading…
Reference in New Issue