Skip to content

Commit 3ef50ac

Browse files
update cpp_trt code & refine docs
1 parent 69b4eaf commit 3ef50ac

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

deploy/cpp_infer/readme.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ PaddleVideo模型部署。
101101

102102
#### 1.2.1 直接下载安装
103103

104-
* [Paddle预测库官网](https://paddleinference.paddlepaddle.org.cn/v2.1/user_guides/download_lib.html) 上提供了不同cuda版本的Linux预测库,可以在官网查看并**选择合适的预测库版本**(建议选择paddle版本>=2.0.1版本的预测库)。
104+
* [Paddle预测库官网](https://paddleinference.paddlepaddle.org.cn/v2.2/user_guides/download_lib.html) 上提供了不同cuda版本的Linux预测库,可以在官网查看并**选择合适的预测库版本**(建议选择paddle版本>=2.0.1版本的预测库)。
105105

106106
* 下载得到一个`paddle_inference.tgz`压缩包,然后将它解压成文件夹,命令如下(以机器环境为gcc8.2为例):
107107

108108
```bash
109-
wget https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.1-cudnn7-mkl-gcc8.2/paddle_inference.tgz
109+
wget https://paddle-inference-lib.bj.bcebos.com/2.2.2/cxx_c/Linux/GPU/x86-64_gcc8.2_avx_mkl_cuda10.1_cudnn7.6.5_trt6.0.1.5/paddle_inference.tgz
110110
tar -xf paddle_inference.tgz
111111
```
112112

@@ -118,7 +118,7 @@ PaddleVideo模型部署。
118118

119119
```shell
120120
git clone https://github.com/PaddlePaddle/Paddle.git
121-
git checkout release/2.1
121+
git checkout release/2.2
122122
```
123123

124124
* 进入Paddle目录后,编译方法如下。
@@ -217,6 +217,14 @@ PaddleVideo模型部署。
217217

218218
其中,`mode`为必选参数,表示选择的功能,取值范围['rec'],表示**视频识别**(更多功能会陆续加入)。
219219

220+
注意:如果要在预测时开启TensorRT优化选项,需要先运行以下命令设置好TensorRT的相关路径。
221+
```bash
222+
export PATH=$PATH:/path/to/cuda/bin
223+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/cuda/bin
224+
export LIBRARY_PATH=$LIBRARY_PATH:/path/to/cuda/bin
225+
export LD_LIBRARY_PATH=/path/to/TensorRT-x.x.x.x/lib:$LD_LIBRARY_PATH
226+
```
227+
220228
##### 1. 调用视频识别:
221229
```bash
222230
# 调用PP-TSM识别
@@ -292,4 +300,4 @@ I1125 08:10:45.834602 13955 autolog.h:67] preprocess_time(ms): 10.6524, inferenc
292300

293301
### 3 注意
294302

295-
* 在使用Paddle预测库时,推荐使用2.1.0版本的预测库
303+
* 在使用Paddle预测库时,推荐使用2.2.2版本的预测库

deploy/cpp_infer/readme_en.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ There are two ways to obtain the Paddle prediction library, which will be descri
101101

102102
#### 1.2.1 Download and install directly
103103

104-
* [Paddle prediction library official website](https://paddleinference.paddlepaddle.org.cn/v2.1/user_guides/download_lib.html) provides different cuda versions of Linux prediction libraries, you can Check and **select the appropriate prediction library version** on the official website (it is recommended to select the prediction library with paddle version>=2.0.1).
104+
* [Paddle prediction library official website](https://paddleinference.paddlepaddle.org.cn/v2.2/user_guides/download_lib.html) provides different cuda versions of Linux prediction libraries, you can Check and **select the appropriate prediction library version** on the official website (it is recommended to select the prediction library with paddle version>=2.0.1).
105105

106106
* Download and get a `paddle_inference.tgz` compressed package, and then unzip it into a folder, the command is as follows (taking the machine environment as gcc8.2 as an example):
107107

108108
```bash
109-
wget https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.1-cudnn7-mkl-gcc8.2/paddle_inference.tgz
109+
wget https://paddle-inference-lib.bj.bcebos.com/2.2.2/cxx_c/Linux/GPU/x86-64_gcc8.2_avx_mkl_cuda10.1_cudnn7.6.5_trt6.0.1.5/paddle_inference.tgz
110110
tar -xf paddle_inference.tgz
111111
```
112112

@@ -118,7 +118,7 @@ There are two ways to obtain the Paddle prediction library, which will be descri
118118

119119
```shell
120120
git clone https://github.com/PaddlePaddle/Paddle.git
121-
git checkout release/2.1
121+
git checkout release/2.2
122122
```
123123

124124
* After entering the Paddle directory, the compilation method is as follows.
@@ -217,7 +217,16 @@ Operation mode:
217217
218218
Among them, `mode` is a required parameter, which means the selected function, and the value range is ['rec'], which means **video recognition** (more functions will be added in succession).
219219
220+
Note: Note: If you want to enable the TensorRT optimization option during prediction, you need to run the following command to set the relevant path of TensorRT.
221+
```bash
222+
export PATH=$PATH:/path/to/cuda/bin
223+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/cuda/bin
224+
export LIBRARY_PATH=$LIBRARY_PATH:/path/to/cuda/bin
225+
export LD_LIBRARY_PATH=/path/to/TensorRT-x.x.x.x/lib:$LD_LIBRARY_PATH
226+
```
227+
220228
##### 1. Call video recognition:
229+
221230
```bash
222231
# run PP-TSM inference
223232
./build/ppvideo rec \
@@ -291,4 +300,4 @@ I1125 08:10:45.834602 13955 autolog.h:67] preprocess_time(ms): 10.6524, inferenc
291300
292301
### 3 Attention
293302
294-
* When using the Paddle prediction library, it is recommended to use the prediction library of version 2.1.0.
303+
* When using the Paddle prediction library, it is recommended to use the prediction library of version 2.2.2.

deploy/cpp_infer/src/video_rec.cpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ namespace PaddleVideo
227227
config.EnableTensorRtEngine(
228228
1 << 30, // workspaceSize
229229
this->rec_batch_num * this->num_seg * 1, // maxBatchSize
230-
30, // minSubgraphSize
230+
3, // minSubgraphSize
231231
precision, // precision
232232
false,// useStatic
233233
false //useCalibMode
@@ -238,7 +238,7 @@ namespace PaddleVideo
238238
config.EnableTensorRtEngine(
239239
1 << 30,
240240
this->rec_batch_num * this->num_seg * 10,
241-
30, // minSubgraphSize
241+
3, // minSubgraphSize
242242
precision,// precision
243243
false,// useStatic
244244
false //useCalibMode
@@ -249,29 +249,33 @@ namespace PaddleVideo
249249
config.EnableTensorRtEngine(
250250
1 << 30, // workspaceSize
251251
this->rec_batch_num, // maxBatchSize
252-
30, // minSubgraphSize
252+
3, // minSubgraphSize
253253
precision,// precision
254254
false,// useStatic
255255
false //useCalibMode
256256
);
257257
}
258258

259-
std::map<std::string, std::vector<int> > min_input_shape =
260-
{
261-
{"data_batch_0", {1, this->num_seg, 3, 1, 1}}
262-
};
263-
std::map<std::string, std::vector<int> > max_input_shape =
264-
{
265-
{"data_batch_0", {1, this->num_seg, 3, 256, 256}}
266-
};
267-
std::map<std::string, std::vector<int> > opt_input_shape =
268-
{
269-
{"data_batch_0", {this->rec_batch_num, this->num_seg, 3, 224, 224}}
270-
};
259+
std::cout << "Enable TensorRT is: " << config.tensorrt_engine_enabled() << std::endl;
271260

272-
config.SetTRTDynamicShapeInfo(min_input_shape, max_input_shape,
273-
opt_input_shape);
274-
std::cout << "Enable TensorRT is: " << config.tensorrt_engine_enabled() << std::endl; }
261+
/* some model dose not suppport dynamic shape with TRT, deactivate it by default */
262+
263+
// std::map<std::string, std::vector<int> > min_input_shape =
264+
// {
265+
// {"data_batch_0", {1, this->num_seg, 3, 1, 1}}
266+
// };
267+
// std::map<std::string, std::vector<int> > max_input_shape =
268+
// {
269+
// {"data_batch_0", {1, this->num_seg, 3, 256, 256}}
270+
// };
271+
// std::map<std::string, std::vector<int> > opt_input_shape =
272+
// {
273+
// {"data_batch_0", {this->rec_batch_num, this->num_seg, 3, 224, 224}}
274+
// };
275+
276+
// config.SetTRTDynamicShapeInfo(min_input_shape, max_input_shape,
277+
// opt_input_shape);
278+
}
275279
}
276280
else
277281
{

0 commit comments

Comments
 (0)