Skip to content

Commit 456b9fe

Browse files
yghstillceci3
andauthored
update act paddle inference demo (PaddlePaddle#1432)
Co-authored-by: ceci3 <[email protected]>
1 parent fe33833 commit 456b9fe

File tree

15 files changed

+1953
-1169
lines changed

15 files changed

+1953
-1169
lines changed

example/auto_compression/detection/README.md

+42-22
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
- [3.1 环境准备](#31-准备环境)
88
- [3.2 准备数据集](#32-准备数据集)
99
- [3.3 准备预测模型](#33-准备预测模型)
10-
- [3.4 测试模型精度](#34-测试模型精度)
11-
- [3.5 自动压缩并产出模型](#35-自动压缩并产出模型)
10+
- [3.4 自动压缩并产出模型](#34-自动压缩并产出模型)
1211
- [4.预测部署](#4预测部署)
1312
- [5.FAQ](5FAQ)
1413

@@ -110,23 +109,52 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch --log_dir=log -
110109
--config_path=./configs/ppyoloe_l_qat_dis.yaml --save_dir='./output/'
111110
```
112111

113-
#### 3.5 测试模型精度
114112

115-
使用eval.py脚本得到模型的mAP:
116-
```
117-
export CUDA_VISIBLE_DEVICES=0
118-
python eval.py --config_path=./configs/ppyoloe_l_qat_dis.yaml
119-
```
113+
## 4.预测部署
120114

121-
**注意**
122-
- 要测试的模型路径可以在配置文件中`model_dir`字段下进行修改。
115+
#### 4.1 Paddle Inference 验证性能
123116

124-
## 4.预测部署
117+
量化模型在GPU上可以使用TensorRT进行加速,在CPU上可以使用MKLDNN进行加速。
118+
119+
以下字段用于配置预测参数:
125120

126-
- 如果模型包含NMS,可以参考[PaddleDetection部署教程](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy),GPU上量化模型开启TensorRT并设置trt_int8模式进行部署。
121+
| 参数名 | 含义 |
122+
|:------:|:------:|
123+
| model_path | inference 模型文件所在目录,该目录下需要有文件 model.pdmodel 和 model.pdiparams 两个文件 |
124+
| reader_config | eval时模型reader的配置文件路径 |
125+
| image_file | 如果只测试单张图片效果,直接根据image_file指定图片路径 |
126+
| device | 使用GPU或者CPU预测,可选CPU/GPU |
127+
| use_trt | 是否使用 TesorRT 预测引擎 |
128+
| use_mkldnn | 是否启用```MKL-DNN```加速库,注意```use_mkldnn``````use_gpu```同时为```True```时,将忽略```enable_mkldnn```,而使用```GPU```预测 |
129+
| cpu_threads | CPU预测时,使用CPU线程数量,默认10 |
130+
| precision | 预测精度,包括`fp32/fp16/int8` |
127131

128-
- 模型为PPYOLOE,同时不包含NMS,使用以下预测demo进行部署:
129-
- Paddle-TensorRT C++部署
132+
133+
- TensorRT预测:
134+
135+
环境配置:如果使用 TesorRT 预测引擎,需安装 ```WITH_TRT=ON``` 的Paddle,下载地址:[Python预测库](https://paddleinference.paddlepaddle.org.cn/master/user_guides/download_lib.html#python)
136+
137+
```shell
138+
python paddle_inference_eval.py \
139+
--model_path=models/ppyoloe_crn_l_300e_coco_quant \
140+
--reader_config=configs/yoloe_reader.yml \
141+
--use_trt=True \
142+
--precision=int8
143+
```
144+
145+
- MKLDNN预测:
146+
147+
```shell
148+
python paddle_inference_eval.py \
149+
--model_path=models/ppyoloe_crn_l_300e_coco_quant \
150+
--reader_config=configs/yoloe_reader.yml \
151+
--device=CPU \
152+
--use_mkldnn=True \
153+
--cpu_threads=10 \
154+
--precision=int8
155+
```
156+
157+
- 模型为PPYOLOE,同时不包含NMS,可以使用C++预测demo进行测速:
130158

131159
进入[cpp_infer](./cpp_infer_ppyoloe)文件夹内,请按照[C++ TensorRT Benchmark测试教程](./cpp_infer_ppyoloe/README.md)进行准备环境及编译,然后开始测试:
132160
```shell
@@ -136,14 +164,6 @@ python eval.py --config_path=./configs/ppyoloe_l_qat_dis.yaml
136164
./build/trt_run --model_file ppyoloe_s_quant/model.pdmodel --params_file ppyoloe_s_quant/model.pdiparams --run_mode=trt_int8
137165
```
138166

139-
- Paddle-TensorRT Python部署:
140-
141-
首先安装带有TensorRT的[Paddle安装包](https://www.paddlepaddle.org.cn/inference/v2.3/user_guides/download_lib.html#python)。然后使用[paddle_trt_infer.py](./paddle_trt_infer.py)进行部署:
142-
```shell
143-
python paddle_trt_infer.py --model_path=output --image_file=images/000000570688.jpg --benchmark=True --run_mode=trt_int8
144-
```
145-
146167
## 5.FAQ
147168

148-
149169
- 如果想对模型进行离线量化,可进入[Detection模型离线量化示例](https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/post_training_quantization/detection)中进行实验。

0 commit comments

Comments
 (0)