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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # ResNet-50_quant Example
  2. ## Description
  3. This is an example of training ResNet-50_quant with ImageNet2012 dataset in MindSpore.
  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: images should be classified into 1000 directories firstly, just like train images
  12. > ```
  13. ## Example structure
  14. ```shell
  15. .
  16. ├── Resnet50_quant
  17. ├── Readme.md
  18. ├── scripts
  19. │ ├──run_train.sh
  20. │ ├──run_eval.sh
  21. ├── src
  22. │ ├──config.py
  23. │ ├──crossentropy.py
  24. │ ├──dataset.py
  25. │ ├──luanch.py
  26. │ ├──lr_generator.py
  27. │ ├──utils.py
  28. ├── models
  29. │ ├──resnet_quant.py
  30. ├── train.py
  31. ├── eval.py
  32. ```
  33. ## Parameter configuration
  34. Parameters for both training and inference can be set in config.py.
  35. ```
  36. "class_num": 1001, # dataset class number
  37. "batch_size": 32, # batch size of input tensor
  38. "loss_scale": 1024, # loss scale
  39. "momentum": 0.9, # momentum optimizer
  40. "weight_decay": 1e-4, # weight decay
  41. "epoch_size": 120, # only valid for taining, which is always 1 for inference
  42. "pretrained_epoch_size": 90, # epoch size that model has been trained before load pretrained checkpoint
  43. "buffer_size": 1000, # number of queue size in data preprocessing
  44. "image_height": 224, # image height
  45. "image_width": 224, # image width
  46. "save_checkpoint": True, # whether save checkpoint or not
  47. "save_checkpoint_epochs": 1, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
  48. "keep_checkpoint_max": 50, # only keep the last keep_checkpoint_max checkpoint
  49. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  50. "warmup_epochs": 0, # number of warmup epoch
  51. "lr_decay_mode": "cosine", # decay mode for generating learning rate
  52. "label_smooth": True, # label smooth
  53. "label_smooth_factor": 0.1, # label smooth factor
  54. "lr_init": 0, # initial learning rate
  55. "lr_max": 0.005, # maximum learning rate
  56. ```
  57. ## Running the example
  58. ### Train
  59. ### Usage
  60. - Ascend: sh run_train.sh Ascend [DEVICE_NUM] [SERVER_IP(x.x.x.x)] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH]
  61. ### Launch
  62. ```
  63. # training example
  64. Ascend: sh run_train.sh Ascend 8 192.168.0.1 0,1,2,3,4,5,6,7 ~/imagenet/train/
  65. ```
  66. ### Result
  67. Training result will be stored in the example path. Checkpoints will be stored at `. /checkpoint` by default, and training log will be redirected to `./train/train.log` like followings.
  68. ```
  69. epoch: 1 step: 5004, loss is 4.8995576
  70. epoch: 2 step: 5004, loss is 3.9235563
  71. epoch: 3 step: 5004, loss is 3.833077
  72. epoch: 4 step: 5004, loss is 3.2795618
  73. epoch: 5 step: 5004, loss is 3.1978393
  74. ```
  75. ## Eval process
  76. ### Usage
  77. - Ascend: sh run_infer.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]
  78. ### Launch
  79. ```
  80. # infer example
  81. Ascend: sh run_infer.sh Ascend ~/imagenet/val/ ~/checkpoint/resnet50-110_5004.ckpt
  82. ```
  83. > checkpoint can be produced in training process.
  84. #### Result
  85. 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.
  86. ```
  87. result: {'acc': 0.75.252054737516005} ckpt=train_parallel0/resnet-110_5004.ckpt
  88. ```