Skip to content

Commit 04e3316

Browse files
authored
add PP-YOLOE auto commpression (PaddlePaddle#1090)
1 parent d2bd7c1 commit 04e3316

File tree

19 files changed

+195
-90
lines changed

19 files changed

+195
-90
lines changed

demo/auto-compression/detection/README.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

demo/auto-compression/README.md renamed to demo/auto_compression/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ python tools/export_model.py \
5050
-o Global.save_inference_dir=infermodel_mobilenetv2
5151
```
5252
#### 2.4 测试模型精度
53-
拷贝``infermodel_mobilenetv2``文件夹到``PaddleSlim/demo/auto-compression/``文件夹。
53+
拷贝``infermodel_mobilenetv2``文件夹到``PaddleSlim/demo/auto_compression/``文件夹。
5454
```
55-
cd PaddleSlim/demo/auto-compression/
55+
cd PaddleSlim/demo/auto_compression/
5656
```
5757
使用[eval.py](../quant/quant_post/eval.py)脚本得到模型的分类精度,压缩后的模型也可以使用同一个脚本测试精度:
5858
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# 目标检测模型自动压缩
2+
3+
本示例将介绍如何使用PaddleDetection中Inference部署模型进行自动压缩。
4+
5+
## Benchmark
6+
7+
- PP-YOLOE模型:
8+
9+
| 模型 | 策略 | 输入尺寸 | 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+
| :-------- |:-------- |:--------: | :---------------------: | :----------------: | :----------------: | :---------------: | :-----------------------------: | :-----------------------------: |
11+
| 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) |
13+
14+
- mAP的指标均在COCO val2017数据集中评测得到。
15+
- PP-YOLOE模型在Tesla V100的GPU环境下测试,测试脚本是[benchmark demo](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/python)
16+
17+
## 环境准备
18+
19+
### 1. 准备数据
20+
21+
本案例默认以COCO数据进行自动压缩实验,如果自定义COCO数据,或者其他格式数据,请参考[PaddleDetection数据准备文档](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/docs/tutorials/PrepareDataSet.md) 来准备数据。
22+
23+
如果数据集为非COCO格式数据,请修改[configs](./configs)中reader配置文件中的Dataset字段。
24+
25+
### 2. 准备需要量化的环境
26+
27+
- PaddlePaddle >= 2.2
28+
- PaddleDet >= 2.4
29+
30+
```shell
31+
pip install paddledet
32+
```
33+
34+
注:安装PaddleDet的目的是为了直接使用PaddleDetection中的Dataloader组件。
35+
36+
### 3. 准备待量化的部署模型
37+
38+
如果已经准备好部署的`model.pdmodel``model.pdiparams`部署模型,跳过此步。
39+
40+
根据[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+
- 下载代码
42+
```
43+
git clone https://github.com/PaddlePaddle/PaddleDetection.git
44+
```
45+
- 导出预测模型
46+
47+
```shell
48+
python tools/export_model.py \
49+
-c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml \
50+
-o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams \
51+
trt=True \
52+
```
53+
54+
**注意**:PP-YOLOE导出时设置`trt=True`旨在优化在TensorRT上的性能,其他模型不需要设置`trt=True`
55+
56+
或直接下载:
57+
```shell
58+
wget https://bj.bcebos.com/v1/paddle-slim-models/detection/ppyoloe_crn_l_300e_coco.tar
59+
tar -xf ppyoloe_crn_l_300e_coco.tar
60+
```
61+
62+
### 4. 测试模型精度
63+
64+
使用[run_main.py](run_main.py)脚本得到模型的mAP:
65+
```
66+
python3.7 run_main.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --eval=True
67+
```
68+
69+
**注意**:TinyPose模型暂不支持精度测试。
70+
71+
## 开始自动压缩
72+
73+
### 进行量化蒸馏自动压缩
74+
蒸馏量化自动压缩示例通过[run_main.py](run_main.py)脚本启动,会使用接口``paddleslim.auto_compression.AutoCompression``对模型进行量化训练。具体运行命令为:
75+
```
76+
python run_main.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --save_dir='./output/' --devices='gpu'
77+
```
78+
79+
80+
## 部署
81+
82+
可以参考[PaddleDetection部署教程](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy)
83+
- GPU上量化模型开启TensorRT并设置trt_int8模式进行部署;
84+
- CPU上可参考[X86 CPU部署量化模型教程](https://github.com/PaddlePaddle/Paddle-Inference-Demo/blob/master/docs/optimize/paddle_x86_cpu_int8.md)
85+
- 移动端请直接使用[Paddle Lite Demo](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/lite)部署。

0 commit comments

Comments
 (0)