- [Description of Random Situation](#Description-of-Random-Situation)
- [ModelZoo Homepage](#ModelZoo-Homepage)
@ -21,10 +22,13 @@
This is an example of training ResNet-50 V1.5 with ImageNet2012 dataset by second-order optimizer THOR. THOR is a novel approximate seond-order optimization method in MindSpore. With fewer iterations, THOR can finish ResNet-50 V1.5 training in 72 minutes to top-1 accuracy of 75.9% using 8 Ascend 910, which is much faster than SGD with Momentum.
## Model Architecture
The overall network architecture of ResNet-50 is show below:[link](https://arxiv.org/pdf/1512.03385.pdf)
## Dataset
Dataset used: ImageNet2012
- Dataset size 224*224 colorful images in 1000 classes
- Train:1,281,167 images
- Test: 50,000 images
@ -35,18 +39,21 @@ Dataset used: ImageNet2012
- Download the dataset ImageNet2012
> Unzip the ImageNet2012 dataset to any path you want and the folder structure should include train and eval dataset as follows:
> ```
> ├── ilsvrc # train dataset
> └── ilsvrc_eval # infer dataset
> ```
```shell
├── ilsvrc # train dataset
└── ilsvrc_eval # infer dataset
```
## Features
The classical first-order optimization algorithm, such as SGD, has a small amount of computation, but the convergence speed is slow and requires lots of iterations. The second-order optimization algorithm uses the second-order derivative of the target function to accelerate convergence, can converge faster to the optimal value of the model and requires less iterations. But the application of the second-order optimization algorithm in deep neural network training is not common because of the high computation cost. The main computational cost of the second-order optimization algorithm lies in the inverse operation of the second-order information matrix (Hessian matrix, Fisher information matrix, etc.), and the time complexity is about $O (n^3)$. On the basis of the existing natural gradient algorithm, we developed the available second-order optimizer THOR in MindSpore by adopting approximation and shearing of Fisher information matrix to reduce the computational complexity of the inverse matrix. With eight Ascend 910 chips, THOR can complete ResNet50-v1.5-ImageNet training in 72 minutes.
## Environment Requirements
- 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.
After installing MindSpore via the official website, you can start training and evaluation as follows:
- Running on Ascend
```python
# run distributed training example
sh run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH] [DEVICE_NUM]
@ -63,9 +73,11 @@ sh run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH] [DEVICE_NUM]
# run evaluation example
sh run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH]
```
> For distributed training, a hccl configuration file with JSON format needs to be created in advance. About the configuration file, you can refer to the [HCCL_TOOL](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools).
- Running on GPU
```python
# run distributed training example
sh run_distribute_train_gpu.sh [DATASET_PATH] [DEVICE_NUM]
@ -107,7 +119,8 @@ sh run_eval_gpu.sh [DATASET_PATH] [CHECKPOINT_PATH]
Parameters for both training and inference can be set in config.py.
- Parameters for Ascend 910
```
```shell
"class_num": 1001, # dataset class number
"batch_size": 32, # batch size of input tensor(only supports 32)
"loss_scale": 128, # loss scale
@ -127,8 +140,10 @@ Parameters for both training and inference can be set in config.py.
"damping_decay": 0.87, # damping decay rate
"frequency": 834, # the step interval to update second-order information matrix(should be divisor of the steps of per epoch)
```
- Parameters for GPU
```
```shell
"class_num": 1001, # dataset class number
"batch_size": 32, # batch size of input tensor
"loss_scale": 128, # loss scale
@ -148,22 +163,26 @@ Parameters for both training and inference can be set in config.py.
"damping_decay": 0.5467, # damping decay rate
"frequency": 834, # the step interval to update second-order information matrix(should be divisor of the steps of per epoch)
```
> Due to the limitation of operators, the value of batch size only supports 32 in Ascend currently. And the update frequency of second-order information matrix must be set the divisor of the steps of per epoch(for example, 834 is the divisor of 5004). As a word, our algorithm is not very flexible in setting those parameters due to the limitations of the framework and operators. But we will solve these problems in the future versions.
### Training Process
#### Ascend 910
```
```shell
sh run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH] [DEVICE_NUM]
```
We need three parameters for this scripts.
- `RANK_TABLE_FILE`:the path of rank_table.json
- `DATASET_PATH`:the path of train dataset.
- `DEVICE_NUM`: the device number for distributed train.
Training result will be stored in the current path, whose folder name begins with "train_parallel". Under this, you can find checkpoint file together with result like the followings in log.
```
```shell
...
epoch: 1 step: 5004, loss is 4.4182425
epoch: 2 step: 5004, loss is 3.740064
@ -176,12 +195,16 @@ epoch: 41 step: 5004, loss is 1.8217756
epoch: 42 step: 5004, loss is 1.6453942
...
```
#### GPU
```
```shell
sh run_distribute_train_gpu.sh [DATASET_PATH] [DEVICE_NUM]
```
Training result will be stored in the current path, whose folder name begins with "train_parallel". Under this, you can find checkpoint file together with result like the followings in log.
```
```shell
...
epoch: 1 step: 5004, loss is 4.2546034
epoch: 2 step: 5004, loss is 4.0819564
@ -193,16 +216,18 @@ epoch: 36 step: 5004, loss is 1.645802
...
```
### Evaluation Process
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/resnet_thor/train_parallel0/resnet-42_5004.ckpt".
#### Ascend 910
```
```shell
sh run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH]
```
We need two parameters for this scripts.
- `DATASET_PATH`:the path of evaluation dataset.
- `CHECKPOINT_PATH`: the absolute path for checkpoint file.
@ -210,16 +235,19 @@ We need two parameters for this scripts.
Inference result will be stored in the example path, whose folder name is "eval". Under this, you can find result like the followings in log.