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 4.0 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # ResNet-50-THOR Example
  2. ## Description
  3. 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.
  4. ## Requirements
  5. - Install [MindSpore](https://www.mindspore.cn/install/en).
  6. - Download the dataset ImageNet2012
  7. > Unzip the ImageNet2012 dataset to any path you want and the folder structure should include train and eval dataset as follows:
  8. > ```
  9. > .
  10. > ├── ilsvrc # train dataset
  11. > └── ilsvrc_eval # infer dataset
  12. > ```
  13. ## Example structure
  14. ```shell
  15. .
  16. ├── crossentropy.py # CrossEntropy loss function
  17. ├── config.py # parameter configuration
  18. ├── dataset_imagenet.py # data preprocessing
  19. ├── eval.py # infer script
  20. ├── model # include model file of the optimizer
  21. ├── run_distribute_train.sh # launch distributed training(8 pcs)
  22. ├── run_infer.sh # launch infering
  23. └── train.py # train script
  24. ```
  25. ## Parameter configuration
  26. Parameters for both training and inference can be set in config.py.
  27. ```
  28. "class_num": 1000, # dataset class number
  29. "batch_size": 32, # batch size of input tensor
  30. "loss_scale": 128, # loss scale
  31. "momentum": 0.9, # momentum of THOR optimizer
  32. "weight_decay": 5e-4, # weight decay
  33. "epoch_size": 45, # only valid for taining, which is always 1 for inference
  34. "buffer_size": 1000, # number of queue size in data preprocessing
  35. "image_height": 224, # image height
  36. "image_width": 224, # image width
  37. "save_checkpoint": True, # whether save checkpoint or not
  38. "save_checkpoint_steps": 5004, # the step interval between two checkpoints. By default, the checkpoint will be saved every epoch
  39. "keep_checkpoint_max": 20, # only keep the last keep_checkpoint_max checkpoint
  40. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  41. "label_smooth": True, # label smooth
  42. "label_smooth_factor": 0.1, # label smooth factor
  43. "frequency": 834, # the step interval to update second-order information matrix
  44. ```
  45. ## Running the example
  46. ### Train
  47. #### Usage
  48. ```
  49. # distributed training
  50. Usage: sh run_distribute_train.sh [MINDSPORE_HCCL_CONFIG_PATH] [DATASET_PATH] [DEVICE_NUM]
  51. ```
  52. #### Launch
  53. ```bash
  54. # distributed training example(8 pcs)
  55. sh run_distribute_train.sh rank_table_8p.json dataset/ilsvrc
  56. ```
  57. > About rank_table.json, you can refer to the [distributed training tutorial](https://www.mindspore.cn/tutorial/en/master/advanced_use/distributed_training.html).
  58. #### Result
  59. Training result will be stored in the example path, whose folder name begins with "train_parallel". Under this, you can find checkpoint file together with result like the followings in log.
  60. ```
  61. # distribute training result(8 pcs)
  62. epoch: 1 step: 5004, loss is 4.4182425
  63. epoch: 2 step: 5004, loss is 3.740064
  64. epoch: 3 step: 5004, loss is 4.0546017
  65. epoch: 4 step: 5004, loss is 3.7598825
  66. epoch: 5 step: 5004, loss is 3.3744206
  67. ......
  68. ```
  69. ### Infer
  70. #### Usage
  71. ```
  72. # infer
  73. Usage: sh run_infer.sh [DATASET_PATH] [CHECKPOINT_PATH]
  74. ```
  75. #### Launch
  76. ```bash
  77. # infer with checkpoint
  78. sh run_infer.sh dataset/ilsvrc_eval train_parallel0/resnet-42_5004.ckpt
  79. ```
  80. > checkpoint can be produced in training process.
  81. #### Result
  82. Inference result will be stored in the example path, whose folder name is "infer". Under this, you can find result like the followings in log.
  83. ```
  84. result: {'acc': 0.759503041} ckpt=train_parallel0/resnet-42_5004.ckpt
  85. ```