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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # ResNet101 Example
  2. ## Description
  3. This is an example of training ResNet101 with ImageNet dataset in MindSpore.
  4. ## Requirements
  5. - Install [MindSpore](https://www.mindspore.cn/install/en).
  6. - Download the dataset [ImageNet](http://image-net.org/download).
  7. > Unzip the ImageNet dataset to any path you want, the folder should include train and eval dataset as follows:
  8. ```
  9. .
  10. └─dataset
  11. ├─ilsvrc
  12. └─validation_preprocess
  13. ```
  14. ## Example structure
  15. ```shell
  16. .
  17. ├── crossentropy.py # CrossEntropy loss function
  18. ├── var_init.py # weight initial
  19. ├── config.py # parameter configuration
  20. ├── dataset.py # data preprocessing
  21. ├── eval.py # eval net
  22. ├── lr_generator.py # generate learning rate
  23. ├── run_distribute_train.sh # launch distributed training(8p)
  24. ├── run_infer.sh # launch evaluating
  25. ├── run_standalone_train.sh # launch standalone training(1p)
  26. └── train.py # train net
  27. ```
  28. ## Parameter configuration
  29. Parameters for both training and evaluating can be set in config.py.
  30. ```
  31. "class_num": 1001, # dataset class number
  32. "batch_size": 32, # batch size of input tensor
  33. "loss_scale": 1024, # loss scale
  34. "momentum": 0.9, # momentum optimizer
  35. "weight_decay": 1e-4, # weight decay
  36. "epoch_size": 120, # epoch sizes for training
  37. "buffer_size": 1000, # number of queue size in data preprocessing
  38. "image_height": 224, # image height
  39. "image_width": 224, # image width
  40. "save_checkpoint": True, # whether save checkpoint or not
  41. "save_checkpoint_epochs": 1, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
  42. "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint
  43. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  44. "warmup_epochs": 0, # number of warmup epoch
  45. "lr_decay_mode": "cosine" # decay mode for generating learning rate
  46. "label_smooth": 1, # label_smooth
  47. "label_smooth_factor": 0.1, # label_smooth_factor
  48. "lr": 0.1 # base learning rate
  49. ```
  50. ## Running the example
  51. ### Train
  52. #### Usage
  53. ```
  54. # distributed training
  55. sh run_distribute_train.sh [MINDSPORE_HCCL_CONFIG_PATH] [DATASET_PATH]
  56. # standalone training
  57. sh run_standalone_train.sh [DATASET_PATH]
  58. ```
  59. #### Launch
  60. ```bash
  61. # distributed training example(8p)
  62. sh run_distribute_train.sh rank_table_8p.json dataset/ilsvrc
  63. # standalone training example(1p)
  64. sh run_standalone_train.sh dataset/ilsvrc
  65. ```
  66. > About rank_table.json, you can refer to the [distributed training tutorial](https://www.mindspore.cn/tutorial/en/master/advanced_use/distributed_training.html).
  67. #### Result
  68. Training result will be stored in the example path, whose folder name begins with "train" or "train_parallel". You can find checkpoint file together with result like the followings in log.
  69. ```
  70. # distribute training result(8p)
  71. epoch: 1 step: 5004, loss is 4.805483
  72. epoch: 2 step: 5004, loss is 3.2121816
  73. epoch: 3 step: 5004, loss is 3.429647
  74. epoch: 4 step: 5004, loss is 3.3667371
  75. epoch: 5 step: 5004, loss is 3.1718972
  76. ...
  77. epoch: 67 step: 5004, loss is 2.2768745
  78. epoch: 68 step: 5004, loss is 1.7223864
  79. epoch: 69 step: 5004, loss is 2.0665488
  80. epoch: 70 step: 5004, loss is 1.8717369
  81. ...
  82. ```
  83. ### Infer
  84. #### Usage
  85. ```
  86. # infer
  87. sh run_infer.sh [VALIDATION_DATASET_PATH] [CHECKPOINT_PATH]
  88. ```
  89. #### Launch
  90. ```bash
  91. # infer with checkpoint
  92. sh run_infer.sh dataset/validation_preprocess/ train_parallel0/resnet-120_5004.ckpt
  93. ```
  94. > checkpoint can be produced in training process.
  95. #### Result
  96. 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.
  97. ```
  98. result: {'top_5_accuracy': 0.9429417413572343, 'top_1_accuracy': 0.7853513124199744} ckpt=train_parallel0/resnet-120_5004.ckpt
  99. ```