1
- # 目标检测模型自动压缩
1
+ # 目标检测模型自动压缩示例
2
2
3
- 本示例将介绍如何使用PaddleDetection中Inference部署模型进行自动压缩。
3
+ 目录:
4
+ - [ 1.简介] ( #1简介 )
5
+ - [ 2.Benchmark] ( #2Benchmark )
6
+ - [ 3.开始自动压缩] ( #自动压缩流程 )
7
+ - [ 3.1 环境准备] ( #31-准备环境 )
8
+ - [ 3.2 准备数据集] ( #32-准备数据集 )
9
+ - [ 3.3 准备预测模型] ( #33-准备预测模型 )
10
+ - [ 3.4 测试模型精度] ( #34-测试模型精度 )
11
+ - [ 3.5 自动压缩并产出模型] ( #35-自动压缩并产出模型 )
12
+ - [ 4.预测部署] ( #4预测部署 )
13
+ - [ 5.FAQ] ( 5FAQ )
4
14
5
- ## Benchmark
15
+ ## 1. 简介
16
+ 本示例将以目标检测模型PP-YOLOE-l为例,介绍如何使用PaddleDetection中Inference部署模型进行自动压缩。本示例使用的自动压缩策略为量化蒸馏。
6
17
7
- - PP-YOLOE模型:
18
+
19
+ ## 2.Benchmark
20
+
21
+ - PP-YOLOE模型
8
22
9
23
| 模型 | 策略 | 输入尺寸 | mAP<sup >val<br >0.5:0.95 | 预测时延<sup ><small >FP32</small ><sup ><br ><sup >(ms) | 预测时延<sup ><small >FP32</small ><sup ><br ><sup >(ms) | 预测时延<sup ><small >INT8</small ><sup ><br ><sup >(ms) | 配置文件 | Inference模型 |
10
24
| :-------- | :-------- | :--------: | :---------------------: | :----------------: | :----------------: | :---------------: | :-----------------------------: | :-----------------------------: |
11
25
| PP-YOLOE-l | Base模型 | 640* 640 | 50.9 | 11.2 | 7.7ms | - | [ config] ( https://github.com/PaddlePaddle/PaddleDetection/blob/develop/configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml ) | [ Model] ( https://bj.bcebos.com/v1/paddle-slim-models/detection/ppyoloe_crn_l_300e_coco.tar ) |
12
- | PP-YOLOE-l | 量化+蒸馏 | 640* 640 | 49.5 | - | - | 6.7ms | [ config] ( https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/auto_compression/detection/configs/ppyoloe_l_qat_dist.yaml ) | [ Model] ( https://bj.bcebos.com/v1/paddle-slim-models/detection /ppyoloe_crn_l_300e_coco_quant.tar ) |
26
+ | PP-YOLOE-l | 量化+蒸馏 | 640* 640 | 50.6 | - | - | 6.7ms | [ config] ( https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/auto_compression/detection/configs/ppyoloe_l_qat_dist.yaml ) | [ Model] ( https://bj.bcebos.com/v1/paddle-slim-models/act /ppyoloe_crn_l_300e_coco_quant.tar ) |
13
27
14
28
- mAP的指标均在COCO val2017数据集中评测得到。
15
29
- PP-YOLOE模型在Tesla V100的GPU环境下测试,测试脚本是[ benchmark demo] ( https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/python )
16
30
17
- ## 环境准备
18
-
19
- ### 1. 准备数据
31
+ ## 3. 自动压缩流程
20
32
21
- 本案例默认以COCO数据进行自动压缩实验,如果自定义COCO数据,或者其他格式数据,请参考[ PaddleDetection数据准备文档] ( https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/docs/tutorials/PrepareDataSet.md ) 来准备数据。
22
-
23
- 如果数据集为非COCO格式数据,请修改[ configs] ( ./configs ) 中reader配置文件中的Dataset字段。
33
+ #### 3.1 准备环境
34
+ - PaddlePaddle >= 2.2 (可从[ Paddle官网] ( https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html ) 下载安装)
35
+ - PaddleSlim >= 2.3 或者适当develop版本
36
+ - PaddleDet >= 2.4
24
37
25
- ### 2. 准备需要量化的环境
38
+ 安装paddlepaddle:
39
+ ``` shell
40
+ # CPU
41
+ pip install paddlepaddle
42
+ # GPU
43
+ pip install paddlepaddle-gpu
44
+ ```
26
45
27
- - PaddlePaddle >= 2.2
28
- - PaddleDet >= 2.4
46
+ 安装paddleslim:
47
+ ``` shell
48
+ pip install paddleslim
49
+ ```
29
50
51
+ 安装paddledet:
30
52
``` shell
31
53
pip install paddledet
32
54
```
33
55
34
56
注:安装PaddleDet的目的是为了直接使用PaddleDetection中的Dataloader组件。
35
57
36
- ### 3. 准备待量化的部署模型
37
58
38
- 如果已经准备好部署的` model.pdmodel ` 和` model.pdiparams ` 部署模型,跳过此步。
59
+ #### 3.2 准备数据集
60
+
61
+ 本案例默认以COCO数据进行自动压缩实验,如果自定义COCO数据,或者其他格式数据,请参考[ PaddleDetection数据准备文档] ( https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/docs/tutorials/PrepareDataSet.md ) 来准备数据。
62
+
63
+ 如果数据集为非COCO格式数据,请修改[ configs] ( ./configs ) 中reader配置文件中的Dataset字段。
64
+
65
+ #### 3.3 准备预测模型
66
+
67
+ 预测模型的格式为:` model.pdmodel ` 和 ` model.pdiparams ` 两个,带` pdmodel ` 的是模型文件,带` pdiparams ` 后缀的是权重文件。
68
+
69
+ 注:其他像` __model__ ` 和` __params__ ` 分别对应` model.pdmodel ` 和 ` model.pdiparams ` 文件。
70
+
39
71
40
72
根据[ PaddleDetection文档] ( https://github.com/PaddlePaddle/PaddleDetection/blob/develop/docs/tutorials/GETTING_STARTED_cn.md#8-%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA ) 导出Inference模型,具体可参考下方PP-YOLOE模型的导出示例:
41
73
- 下载代码
@@ -59,27 +91,28 @@ wget https://bj.bcebos.com/v1/paddle-slim-models/detection/ppyoloe_crn_l_300e_co
59
91
tar -xf ppyoloe_crn_l_300e_coco.tar
60
92
```
61
93
62
- ### 4. 测试模型精度
94
+ #### 3. 4. 测试模型精度
63
95
64
- 使用 [ run.py ] ( run.py ) 脚本得到模型的mAP :
96
+ 使用run.py脚本得到模型的mAP :
65
97
```
66
98
python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --eval=True
67
99
```
68
100
69
101
** 注意** :TinyPose模型暂不支持精度测试。
70
102
71
- ## 开始自动压缩
103
+ #### 3.5 自动压缩并产出模型
72
104
73
- ### 进行量化蒸馏自动压缩
74
- 蒸馏量化自动压缩示例通过[ run.py] ( run.py ) 脚本启动,会使用接口`` paddleslim.auto_compression.AutoCompression `` 对模型进行量化训练。具体运行命令为:
105
+ 蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口``` paddleslim.auto_compression.AutoCompression ``` 对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为:
75
106
```
76
- python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --save_dir='./output/' --devices='gpu'
107
+ python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --save_dir='./output/'
77
108
```
78
109
79
110
80
- ## 部署
111
+ ## 4.预测部署
81
112
82
113
可以参考[ PaddleDetection部署教程] ( https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy ) :
83
114
- GPU上量化模型开启TensorRT并设置trt_int8模式进行部署;
84
115
- CPU上可参考[ X86 CPU部署量化模型教程] ( https://github.com/PaddlePaddle/Paddle-Inference-Demo/blob/master/docs/optimize/paddle_x86_cpu_int8.md ) ;
85
116
- 移动端请直接使用[ Paddle Lite Demo] ( https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/lite ) 部署。
117
+
118
+ ## 5.FAQ
0 commit comments