Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
7d5380fd
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7d5380fd
编写于
4月 02, 2020
作者:
W
wangguanzhong
提交者:
GitHub
4月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update cpp_infer for paddle latest (#424)
* update cpp_infer for paddle latest * polish code
上级
ca199f73
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
21 addition
and
16 deletion
+21
-16
tools/cpp_infer.py
tools/cpp_infer.py
+14
-12
tools/export_model.py
tools/export_model.py
+7
-4
未找到文件。
tools/cpp_infer.py
浏览文件 @
7d5380fd
...
...
@@ -104,14 +104,16 @@ class Resize(object):
target_size
,
max_size
=
0
,
interp
=
cv2
.
INTER_LINEAR
,
use_cv2
=
True
):
use_cv2
=
True
,
image_shape
=
None
):
super
(
Resize
,
self
).
__init__
()
self
.
target_size
=
target_size
self
.
max_size
=
max_size
self
.
interp
=
interp
self
.
use_cv2
=
use_cv2
self
.
image_shape
=
image_shape
def
__call__
(
self
,
im
,
use_trt
=
False
):
def
__call__
(
self
,
im
):
origin_shape
=
im
.
shape
[:
2
]
im_c
=
im
.
shape
[
2
]
if
self
.
max_size
!=
0
:
...
...
@@ -147,10 +149,7 @@ class Resize(object):
im
=
im
.
resize
((
int
(
resize_w
),
int
(
resize_h
)),
self
.
interp
)
im
=
np
.
array
(
im
)
# padding im
if
self
.
max_size
!=
0
and
use_trt
:
logger
.
warning
(
'Due to the limitation of tensorRT, padding the '
'image shape to {} * {}'
.
format
(
self
.
max_size
,
self
.
max_size
))
if
self
.
max_size
!=
0
and
self
.
image_shape
is
not
None
:
padding_im
=
np
.
zeros
(
(
self
.
max_size
,
self
.
max_size
,
im_c
),
dtype
=
np
.
float32
)
im_h
,
im_w
=
im
.
shape
[:
2
]
...
...
@@ -189,10 +188,10 @@ class Permute(object):
def
__call__
(
self
,
im
):
if
self
.
channel_first
:
im
=
im
.
transpose
((
2
,
0
,
1
))
.
copy
()
im
=
im
.
transpose
((
2
,
0
,
1
))
if
self
.
to_bgr
:
im
=
im
[[
2
,
1
,
0
],
:,
:]
return
im
return
im
.
copy
()
class
PadStride
(
object
):
...
...
@@ -214,7 +213,7 @@ class PadStride(object):
return
padding_im
def
Preprocess
(
img_path
,
arch
,
config
,
use_trt
):
def
Preprocess
(
img_path
,
arch
,
config
):
img
=
DecodeImage
(
img_path
)
orig_shape
=
img
.
shape
scale
=
1.
...
...
@@ -224,7 +223,7 @@ def Preprocess(img_path, arch, config, use_trt):
obj
=
data_aug_conf
.
pop
(
'type'
)
preprocess
=
eval
(
obj
)(
**
data_aug_conf
)
if
obj
==
'Resize'
:
img
,
scale
=
preprocess
(
img
,
use_trt
)
img
,
scale
=
preprocess
(
img
)
else
:
img
=
preprocess
(
img
)
...
...
@@ -509,8 +508,11 @@ def infer():
conf
=
yaml
.
safe_load
(
f
)
use_trt
=
not
conf
[
'use_python_inference'
]
and
'trt'
in
conf
[
'mode'
]
img_data
=
Preprocess
(
FLAGS
.
infer_img
,
conf
[
'arch'
],
conf
[
'Preprocess'
],
use_trt
)
if
use_trt
:
logger
.
warning
(
"Due to the limitation of tensorRT, the image shape needs to set in export_model"
)
img_data
=
Preprocess
(
FLAGS
.
infer_img
,
conf
[
'arch'
],
conf
[
'Preprocess'
])
if
'SSD'
in
conf
[
'arch'
]:
img_data
,
res
[
'im_shape'
]
=
img_data
img_data
=
[
img_data
]
...
...
tools/export_model.py
浏览文件 @
7d5380fd
...
...
@@ -34,7 +34,7 @@ logger = logging.getLogger(__name__)
def
parse_reader
(
reader_cfg
,
metric
,
arch
):
preprocess_list
=
[]
image_shape
=
reader_cfg
[
'inputs_def'
].
get
(
'image_shape'
,
[
None
])
image_shape
=
reader_cfg
[
'inputs_def'
].
get
(
'image_shape'
,
[
3
,
None
,
None
])
has_shape_def
=
not
None
in
image_shape
scale_set
=
{
'RCNN'
,
'RetinaNet'
}
...
...
@@ -58,9 +58,11 @@ def parse_reader(reader_cfg, metric, arch):
params
=
st
.
__dict__
params
.
pop
(
'_id'
)
if
p
[
'type'
]
==
'Resize'
and
has_shape_def
:
params
[
'target_size'
]
=
image_shape
[
1
]
params
[
'max_size'
]
=
image_shape
[
2
]
if
arch
in
scale_set
else
0
params
[
'target_size'
]
=
min
(
image_shape
[
1
:])
if
arch
in
scale_set
else
image_shape
[
1
]
params
[
'max_size'
]
=
max
(
image_shape
[
1
:])
if
arch
in
scale_set
else
0
params
[
'image_shape'
]
=
image_shape
[
1
:]
p
.
update
(
params
)
preprocess_list
.
append
(
p
)
batch_transforms
=
reader_cfg
.
get
(
'batch_transforms'
,
None
)
...
...
@@ -102,6 +104,7 @@ def dump_infer_config(config):
infer_cfg
[
'with_background'
],
infer_cfg
[
'Preprocess'
],
infer_cfg
[
'label_list'
]
=
parse_reader
(
config
[
'TestReader'
],
config
[
'metric'
],
infer_cfg
[
'arch'
])
yaml
.
dump
(
infer_cfg
,
open
(
os
.
path
.
join
(
save_dir
,
'infer_cfg.yml'
),
'w'
))
logger
.
info
(
"Export inference config file to {}"
.
format
(
os
.
path
.
join
(
save_dir
,
'infer_cfg.yml'
)))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录