Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
b367361e
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b367361e
编写于
1月 05, 2022
作者:
J
joanna.wozna.intel
提交者:
GitHub
1月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add enable_mkldnn to static/deploy/python/infer.py (#5049)
* Add enable_mkldnn to infer.py
上级
0978885e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
10 deletion
+27
-10
static/deploy/python/infer.py
static/deploy/python/infer.py
+27
-10
未找到文件。
static/deploy/python/infer.py
浏览文件 @
b367361e
...
...
@@ -59,6 +59,7 @@ class Detector(object):
device (str): Choose the device you want to run, it can be: CPU/GPU/XPU, default is CPU
run_mode (str): mode of running(fluid/trt_fp32/trt_fp16)
threshold (float): threshold to reserve the result for output.
enable_mkldnn (bool): whether use mkldnn with CPU.
"""
def
__init__
(
self
,
...
...
@@ -67,7 +68,8 @@ class Detector(object):
device
=
'CPU'
,
run_mode
=
'fluid'
,
threshold
=
0.5
,
trt_calib_mode
=
False
):
trt_calib_mode
=
False
,
enable_mkldnn
=
False
):
self
.
config
=
config
if
self
.
config
.
use_python_inference
:
self
.
executor
,
self
.
program
,
self
.
fecth_targets
=
load_executor
(
...
...
@@ -78,7 +80,8 @@ class Detector(object):
run_mode
=
run_mode
,
min_subgraph_size
=
self
.
config
.
min_subgraph_size
,
device
=
device
,
trt_calib_mode
=
trt_calib_mode
)
trt_calib_mode
=
trt_calib_mode
,
enable_mkldnn
=
enable_mkldnn
)
def
preprocess
(
self
,
im
):
preprocess_ops
=
[]
...
...
@@ -225,14 +228,16 @@ class DetectorSOLOv2(Detector):
device
=
'CPU'
,
run_mode
=
'fluid'
,
threshold
=
0.5
,
trt_calib_mode
=
False
):
trt_calib_mode
=
False
,
enable_mkldnn
=
False
):
super
(
DetectorSOLOv2
,
self
).
__init__
(
config
=
config
,
model_dir
=
model_dir
,
device
=
device
,
run_mode
=
run_mode
,
threshold
=
threshold
,
trt_calib_mode
=
trt_calib_mode
)
trt_calib_mode
=
trt_calib_mode
,
enable_mkldn
=
enable_mkldnn
)
def
predict
(
self
,
image
,
...
...
@@ -385,13 +390,15 @@ def load_predictor(model_dir,
batch_size
=
1
,
device
=
'CPU'
,
min_subgraph_size
=
3
,
trt_calib_mode
=
False
):
trt_calib_mode
=
False
,
enable_mkldnn
=
False
):
"""set AnalysisConfig, generate AnalysisPredictor
Args:
model_dir (str): root path of __model__ and __params__
device (str): Choose the device you want to run, it can be: CPU/GPU/XPU, default is CPU
trt_calib_mode (bool): If the model is produced by TRT offline quantitative
calibration, trt_calib_mode need to set True
enable_mkldnn (bool): Whether use mkldnn with CPU, default is False
Returns:
predictor (PaddlePredictor): AnalysisPredictor
Raises:
...
...
@@ -419,7 +426,10 @@ def load_predictor(model_dir,
config
.
enable_xpu
(
10
*
1024
*
1024
)
else
:
config
.
disable_gpu
()
if
enable_mkldnn
:
config
.
set_mkldnn_cache_capacity
(
0
)
config
.
enable_mkldnn
()
config
.
pass_builder
().
append_pass
(
"interpolate_mkldnn_pass"
)
if
run_mode
in
precision_map
.
keys
():
config
.
enable_tensorrt_engine
(
workspace_size
=
1
<<
10
,
...
...
@@ -432,7 +442,8 @@ def load_predictor(model_dir,
# disable print log when predict
config
.
disable_glog_info
()
# enable shared memory
config
.
enable_memory_optim
()
if
(
not
enable_mkldnn
):
config
.
enable_memory_optim
()
# disable feed, fetch OP, needed by zero_copy_run
config
.
switch_use_feed_fetch_ops
(
False
)
predictor
=
fluid
.
core
.
create_paddle_predictor
(
config
)
...
...
@@ -545,14 +556,16 @@ def main():
FLAGS
.
model_dir
,
device
=
FLAGS
.
device
,
run_mode
=
FLAGS
.
run_mode
,
trt_calib_mode
=
FLAGS
.
trt_calib_mode
)
trt_calib_mode
=
FLAGS
.
trt_calib_mode
,
enable_mkldnn
=
FLAGS
.
enable_mkldnn
)
if
config
.
arch
==
'SOLOv2'
:
detector
=
DetectorSOLOv2
(
config
,
FLAGS
.
model_dir
,
device
=
FLAGS
.
device
,
run_mode
=
FLAGS
.
run_mode
,
trt_calib_mode
=
FLAGS
.
trt_calib_mode
)
trt_calib_mode
=
FLAGS
.
trt_calib_mode
,
enable_mkldnn
=
FLAGS
.
enable_mkldnn
)
# predict from image
if
FLAGS
.
image_file
!=
''
:
predict_image
(
detector
)
...
...
@@ -618,7 +631,11 @@ if __name__ == '__main__':
default
=
False
,
help
=
"If the model is produced by TRT offline quantitative "
"calibration, trt_calib_mode need to set True."
)
parser
.
add_argument
(
"--enable_mkldnn"
,
type
=
ast
.
literal_eval
,
default
=
False
,
help
=
"Whether use mkldnn with CPU."
)
FLAGS
=
parser
.
parse_args
()
print_arguments
(
FLAGS
)
if
FLAGS
.
image_file
!=
''
and
FLAGS
.
video_file
!=
''
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录