Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
0e487626
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0e487626
编写于
8月 23, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
8月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix paddle_trt infer (#1387)
上级
aa122039
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
17 deletion
+31
-17
example/auto_compression/pytorch_yolo_series/paddle_trt_infer.py
.../auto_compression/pytorch_yolo_series/paddle_trt_infer.py
+31
-17
未找到文件。
example/auto_compression/pytorch_yolo_series/paddle_trt_infer.py
浏览文件 @
0e487626
...
...
@@ -21,7 +21,7 @@ import time
from
paddle.inference
import
Config
from
paddle.inference
import
create_predictor
from
post_process
import
YOLO
v7
PostProcess
from
post_process
import
YOLOPostProcess
CLASS_LABEL
=
[
'person'
,
'bicycle'
,
'car'
,
'motorcycle'
,
'airplane'
,
'bus'
,
'train'
,
...
...
@@ -165,6 +165,7 @@ def load_predictor(model_dir,
Raises:
ValueError: predict by TensorRT need device == 'GPU'.
"""
rerun_flag
=
False
if
device
!=
'GPU'
and
run_mode
!=
'paddle'
:
raise
ValueError
(
"Predict by TensorRT mode: {}, expect device=='GPU', but device == {}"
...
...
@@ -211,18 +212,16 @@ def load_predictor(model_dir,
use_calib_mode
=
trt_calib_mode
)
if
use_dynamic_shape
:
min_input_shape
=
{
'image'
:
[
batch_size
,
3
,
trt_min_shape
,
trt_min_shape
]
}
max_input_shape
=
{
'image'
:
[
batch_size
,
3
,
trt_max_shape
,
trt_max_shape
]
}
opt_input_shape
=
{
'image'
:
[
batch_size
,
3
,
trt_opt_shape
,
trt_opt_shape
]
}
config
.
set_trt_dynamic_shape_info
(
min_input_shape
,
max_input_shape
,
opt_input_shape
)
print
(
'trt set dynamic shape done!'
)
dynamic_shape_file
=
os
.
path
.
join
(
args
.
model_path
,
'dynamic_shape.txt'
)
if
os
.
path
.
exists
(
dynamic_shape_file
):
config
.
enable_tuned_tensorrt_dynamic_shape
(
dynamic_shape_file
,
True
)
print
(
'trt set dynamic shape done!'
)
else
:
config
.
collect_shape_range_info
(
dynamic_shape_file
)
print
(
'Start collect dynamic shape...'
)
rerun_flag
=
True
# disable print log when predict
config
.
disable_glog_info
()
...
...
@@ -233,7 +232,7 @@ def load_predictor(model_dir,
if
delete_shuffle_pass
:
config
.
delete_pass
(
"shuffle_channel_detect_pass"
)
predictor
=
create_predictor
(
config
)
return
predictor
return
predictor
,
rerun_flag
def
predict_image
(
predictor
,
...
...
@@ -244,6 +243,7 @@ def predict_image(predictor,
threshold
=
0.5
,
arch
=
'YOLOv5'
):
img
,
scale_factor
=
image_preprocess
(
image_file
,
image_shape
)
inputs
=
{}
if
arch
==
'YOLOv6'
:
inputs
[
'x2paddle_image_arrays'
]
=
img
else
:
...
...
@@ -276,7 +276,7 @@ def predict_image(predictor,
print
(
'Inference time(ms): min={}, max={}, avg={}'
.
format
(
round
(
time_min
*
1000
,
2
),
round
(
time_max
*
1000
,
1
),
round
(
time_avg
*
1000
,
1
)))
postprocess
=
YOLO
v7
PostProcess
(
postprocess
=
YOLOPostProcess
(
score_threshold
=
0.001
,
nms_threshold
=
0.65
,
multi_label
=
True
)
res
=
postprocess
(
np_boxes
,
scale_factor
)
res_img
=
draw_box
(
...
...
@@ -296,6 +296,11 @@ if __name__ == '__main__':
type
=
bool
,
default
=
False
,
help
=
"Whether run benchmark or not."
)
parser
.
add_argument
(
'--use_dynamic_shape'
,
type
=
bool
,
default
=
True
,
help
=
"Whether use dynamic shape or not."
)
parser
.
add_argument
(
'--run_mode'
,
type
=
str
,
...
...
@@ -312,11 +317,15 @@ if __name__ == '__main__':
parser
.
add_argument
(
'--img_shape'
,
type
=
int
,
default
=
640
,
help
=
"input_size"
)
args
=
parser
.
parse_args
()
predictor
=
load_predictor
(
args
.
model_path
,
run_mode
=
args
.
run_mode
,
device
=
args
.
device
)
warmup
,
repeats
=
1
,
1
if
args
.
benchmark
:
warmup
,
repeats
=
50
,
100
predictor
,
rerun_flag
=
load_predictor
(
args
.
model_path
,
run_mode
=
args
.
run_mode
,
device
=
args
.
device
,
use_dynamic_shape
=
args
.
use_dynamic_shape
)
predict_image
(
predictor
,
args
.
image_file
,
...
...
@@ -324,3 +333,8 @@ if __name__ == '__main__':
warmup
=
warmup
,
repeats
=
repeats
,
arch
=
args
.
arch
)
if
rerun_flag
:
print
(
"***** Collect dynamic shape done, Please rerun the program to get correct results. *****"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录