README.md 4.61 KB
Newer Older
sugon_cxj's avatar
sugon_cxj committed
1
# mobilenet_prune
chenxj's avatar
chenxj committed
2
## 论文
dcuai's avatar
dcuai committed
3
4
5
* EfficientNet https://arxiv.org/pdf/1905.11946.pdf 
* mobilenetv2 https://arxiv.org/pdf/1801.04381.pdf 
* mobilenetv3 https://arxiv.org/pdf/1905.02244.pdf 
sugon_cxj's avatar
sugon_cxj committed
6
## 模型结构
chenxj's avatar
chenxj committed
7
8
mobilenetv2:

chenxj's avatar
chenxj committed
9
![image](https://developer.hpccube.com/codes/modelzoo/mobilenet_prune/-/raw/main/mobilenetv2.png)
chenxj's avatar
chenxj committed
10
11

详细模型结构见官方论文:
dcuai's avatar
dcuai committed
12
13
14
* EfficientNet https://arxiv.org/pdf/1905.11946.pdf 
* mobilenetv2 https://arxiv.org/pdf/1801.04381.pdf 
* mobilenetv3 https://arxiv.org/pdf/1905.02244.pdf 
chenxj's avatar
chenxj committed
15
## 算法原理
dcuai's avatar
dcuai committed
16
mobilenetv2:
dcuai's avatar
dcuai committed
17

dcuai's avatar
dcuai committed
18
具有线性瓶颈的反转残差(inverted residual ):该模块将低维压缩表示作为输入,首先将其扩展为高维度并使用轻量级沿深度卷积(depthwiseconvolution)进行滤波。随后通过线性卷积将特征投射回低维表示。中间层使用轻量级的沿深度卷积来对特征进行滤波作为非线性的来源。
dcuai's avatar
dcuai committed
19
![image](https://developer.hpccube.com/codes/modelzoo/mobilenet_prune/-/raw/main/mobilenetV2.png)
dcuai's avatar
dcuai committed
20

sugon_cxj's avatar
sugon_cxj committed
21
## 数据集
dcuai's avatar
dcuai committed
22
`CIFAR-10`
dengjb's avatar
update  
dengjb committed
23
24
25
26
27
28
- 数据集快速下载中心:
  - [SCNet AIDatasets](http://113.200.138.88:18080/aidatasets)
- 数据集快速通道下载地址:
  - [数据集快速下载地址](http://113.200.138.88:18080/aidatasets/project-dependency/cifar)
- 官方下载通道
  - [https://www.cs.toronto.edu/~kriz/cifar.html](https://www.cs.toronto.edu/~kriz/cifar.html)
dcuai's avatar
dcuai committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42

训练数据目录结构如下,用于正常训练的完整数据集请按此目录结构进行制备:
```
├── cifar-10-batches-py
│   ├── batches.meta
│   ├── data_batch_1
│   ├── data_batch_2
│   ├── data_batch_3
│   ├── data_batch_4
│   ├── data_batch_5
│   ├── readme.html
│   └── test_batch
```
**tips:本模型也会自动下载数据集
chenxj's avatar
chenxj committed
43
## 环境配置
chenxj's avatar
chenxj committed
44
[光源](https://sourcefind.cn/#/main-page)可拉取剪枝及微调的docker镜像,在[光合开发者社区](https://cancon.hpccube.com:65024/4/main/)可下载torch安装包。mobilenet_prune推荐的镜像如下:
sugon_cxj's avatar
sugon_cxj committed
45
```
chenxj's avatar
chenxj committed
46
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py37-latest
chenxj's avatar
chenxj committed
47
48
docker run -d -t --privileged --device=/dev/kfd --device=/dev/dri/ --network=host --group-add video --name prune-test image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py37-latest
docker exec -it prune-test bash
sugon_cxj's avatar
sugon_cxj committed
49
```
chenxj's avatar
chenxj committed
50
安装依赖
sugon_cxj's avatar
sugon_cxj committed
51
52
53
54
```
cd mobilenet_prune
pip3 install -r requirements.txt
```
dcuai's avatar
dcuai committed
55
56
## 训练
### 剪枝
sugon_cxj's avatar
sugon_cxj committed
57
58
59
60
61
62
63
64
65
66
67
68
efficientnet
```
python3 main.py --mode prune --model efficientnet --batch-size 128 --restore ./checkpoints/efficientnet.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
mobilenetv2
```
python3 main.py --mode prune --model mobilenetv2 --batch-size 128 --restore ./checkpoints/mobilenetv2.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
mobilenetv3
```
python3 main.py --mode prune --model mobilenetv3 --batch-size 128 --restore ./checkpoints/mobilenetv3.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
dcuai's avatar
dcuai committed
69
### 测试
sugon_cxj's avatar
sugon_cxj committed
70
71
72
73
74
75
76
77
78
79
80
81
efficientnet
```
python3 main.py --mode test --model efficientnet --batch-size 128 --restore ./run/cifar10/prune/cifar10-global-l1-efficientnet/cifar10_efficientnet_l1.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
mobilenetv2
```
python3 main.py --mode test --model mobilenetv2 --batch-size 128 --restore ./run/cifar10/prune/cifar10-global-l1-mobilenetv2/cifar10_mobilenetv2_l1.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
mobilenetv3
```
python3 main.py --mode test --model mobilenetv3 --batch-size 128 --restore ./run/cifar10/prune/cifar10-global-l1-mobilenetv3/cifar10_mobilenetv3_l1.pt --dataset cifar10  --method l1 --speed-up 2.11 --global-pruning
```
chenxj's avatar
chenxj committed
82
## result
dcuai's avatar
dcuai committed
83
![image](https://developer.hpccube.com/codes/modelzoo/mobilenet_prune/-/raw/main/result.png)
chenxj's avatar
chenxj committed
84
### 精度
sugon_cxj's avatar
sugon_cxj committed
85
method l1
chenxj's avatar
chenxj committed
86
87
88
89
90
| model | Base Acc | Pruned Acc | 
| :------: | :------: |:------: |
| efficientnet | 0.9300 | 0.9248 | 
| mobilenetv2 | 0.9222 | 0.9205 | 
| mobilenetv3 | 0.9034 | 0.8963 | 
sugon_cxj's avatar
sugon_cxj committed
91
92

method lamp
chenxj's avatar
chenxj committed
93
94
95
96
97
| model | Base Acc | Pruned Acc | 
| :------: | :------: |:------: |
| efficientnet | 0.9300 | 0.9256 | 
| mobilenetv2 | 0.9222 | 0.9225 | 
| mobilenetv3 | 0.9034 | 0.9044 | 
sugon_cxj's avatar
sugon_cxj committed
98
99

method group_norm
chenxj's avatar
chenxj committed
100
101
102
103
104
| model | Base Acc | Pruned Acc | 
| :------: | :------: |:------: |
| efficientnet | 0.9300 | 0.8977 | 
| mobilenetv2 | 0.9222 | 0.8953 | 
| mobilenetv3 | 0.9034 | 0.8852 | 
sugon_cxj's avatar
sugon_cxj committed
105

chenxj's avatar
chenxj committed
106
107
108
109
110
## 应用场景
### 算法类别
图像分类
### 热点应用行业
交通,金融,医疗,教育,家居
sugon_cxj's avatar
sugon_cxj committed
111
112
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/mobilenet_prune
chenxj's avatar
chenxj committed
113
## 参考资料
sugon_cxj's avatar
sugon_cxj committed
114
* [Torch-Pruning](https://github.com/VainF/Torch-Pruning)
sugon_cxj's avatar
sugon_cxj committed
115