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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # Contents
  2. - [TinyNet Description](#tinynet-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Script Description](#script-description)
  7. - [Script and Sample Code](#script-and-sample-code)
  8. - [Training Process](#training-process)
  9. - [Evaluation Process](#evaluation-process)
  10. - [Model Description](#model-description)
  11. - [Performance](#performance)
  12. - [Evaluation Performance](#evaluation-performance)
  13. - [Description of Random Situation](#description-of-random-situation)
  14. - [ModelZoo Homepage](#modelzoo-homepage)
  15. # [TinyNet Description](#contents)
  16. TinyNets are a series of lightweight models obtained by twisting resolution, depth and width with a data-driven tiny formula. TinyNet outperforms EfficientNet and MobileNetV3.
  17. [Paper](https://arxiv.org/abs/2010.14819): Kai Han, Yunhe Wang, Qiulin Zhang, Wei Zhang, Chunjing Xu, Tong Zhang. Model Rubik's Cube: Twisting Resolution, Depth and Width for TinyNets. In NeurIPS 2020.
  18. # [Model architecture](#contents)
  19. The overall network architecture of TinyNet is show below:
  20. [Link](https://arxiv.org/abs/2010.14819)
  21. # [Dataset](#contents)
  22. Dataset used: [ImageNet 2012](http://image-net.org/challenges/LSVRC/2012/)
  23. - Dataset size:
  24. - Train: 1.2 million images in 1,000 classes
  25. - Test: 50,000 validation images in 1,000 classes
  26. - Data format: RGB images.
  27. - Note: Data will be processed in src/dataset/dataset.py
  28. # [Environment Requirements](#contents)
  29. - Hardware (GPU)
  30. - Framework
  31. - [MindSpore](https://www.mindspore.cn/install/en)
  32. - For more information, please check the resources below:
  33. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  34. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  35. # [Script Description](#contents)
  36. ## [Script and Sample Code](#contents)
  37. ```markdown
  38. .tinynet
  39. ├── README.md # descriptions about tinynet
  40. ├── script
  41. │ ├── eval.sh # evaluation script
  42. │ ├── train_1p_gpu.sh # training script on single GPU
  43. │ └── train_distributed_gpu.sh # distributed training script on multiple GPUs
  44. ├── src
  45. │ ├── callback.py # loss, ema, and checkpoint callbacks
  46. │ ├── dataset.py # data preprocessing
  47. │ ├── loss.py # label-smoothing cross-entropy loss function
  48. │ ├── tinynet.py # tinynet architecture
  49. │ └── utils.py # utility functions
  50. ├── eval.py # evaluation interface
  51. └── train.py # training interface
  52. ```
  53. ### [Training process](#contents)
  54. #### Launch
  55. ```bash
  56. # training on single GPU
  57. sh train_1p_gpu.sh
  58. # training on multiple GPUs, the number after -n indicates how many GPUs will be used for training
  59. sh train_distributed_gpu.sh -n 8
  60. ```
  61. Inside train.sh, there are hyperparameters that can be adjusted during training, for example:
  62. ```python
  63. --model tinynet_c model to be used for training
  64. --drop 0.2 dropout rate
  65. --drop-connect 0 drop connect rate
  66. --num-classes 1000 number of classes for training
  67. --opt-eps 0.001 optimizer's epsilon
  68. --lr 0.048 learning rate
  69. --batch-size 128 batch size
  70. --decay-epochs 2.4 learning rate decays every 2.4 epoch
  71. --warmup-lr 1e-6 warm up learning rate
  72. --warmup-epochs 3 learning rate warm up epoch
  73. --decay-rate 0.97 learning rate decay rate
  74. --ema-decay 0.9999 decay factor for model weights moving average
  75. --weight-decay 1e-5 optimizer's weight decay
  76. --epochs 450 number of epochs to be trained
  77. --ckpt_save_epoch 1 checkpoint saving interval
  78. --workers 8 number of processes for loading data
  79. --amp_level O0 training auto-mixed precision
  80. --opt rmsprop optimizers, currently we support SGD and RMSProp
  81. --data_path /path_to_ImageNet/
  82. --GPU using GPU for training
  83. --dataset_sink using sink mode
  84. ```
  85. The config above was used to train tinynets on ImageNet (change drop-connect to 0.1 for training tinynet_b)
  86. > checkpoints will be saved in the ./device_{rank_id} folder (single GPU)
  87. or ./device_parallel folder (multiple GPUs)
  88. ### [Evaluation Process](#contents)
  89. #### Launch
  90. ```bash
  91. # infer example
  92. sh eval.sh
  93. ```
  94. Inside the eval.sh, there are configs that can be adjusted during inference, for example:
  95. ```python
  96. --num-classes 1000
  97. --batch-size 128
  98. --workers 8
  99. --data_path /path_to_ImageNet/
  100. --GPU
  101. --ckpt /path_to_EMA_checkpoint/
  102. --dataset_sink > tinynet_c_eval.log 2>&1 &
  103. ```
  104. > checkpoint can be produced in training process.
  105. # [Model Description](#contents)
  106. ## [Performance](#contents)
  107. ### Evaluation Performance
  108. | Model | FLOPs | Latency* | ImageNet Top-1 |
  109. | ------------------- | ----- | -------- | -------------- |
  110. | EfficientNet-B0 | 387M | 99.85 ms | 76.7% |
  111. | TinyNet-A | 339M | 81.30 ms | 76.8% |
  112. | EfficientNet-B^{-4} | 24M | 11.54 ms | 56.7% |
  113. | TinyNet-E | 24M | 9.18 ms | 59.9% |
  114. *Latency is measured using MS Lite on Huawei P40 smartphone.
  115. *More details in [Paper](https://arxiv.org/abs/2010.14819).
  116. # [Description of Random Situation](#contents)
  117. We set the seed inside dataset.py. We also use random seed in train.py.
  118. # [ModelZoo Homepage](#contents)
  119. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).