Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
bd586f4a
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bd586f4a
编写于
7月 29, 2021
作者:
B
Bin Lu
提交者:
GitHub
7月 29, 2021
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix batch predict of cls and rec (#1089)
* fixbug_bs=1 of predict_cls\rec
上级
01ea6f99
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
18 deletion
+64
-18
deploy/python/predict_cls.py
deploy/python/predict_cls.py
+33
-8
deploy/python/predict_rec.py
deploy/python/predict_rec.py
+31
-10
未找到文件。
deploy/python/predict_cls.py
浏览文件 @
bd586f4a
...
...
@@ -27,7 +27,6 @@ from utils.get_image_list import get_image_list
from
python.preprocess
import
create_operators
from
python.postprocess
import
build_postprocess
class
ClsPredictor
(
Predictor
):
def
__init__
(
self
,
config
):
super
().
__init__
(
config
[
"Global"
])
...
...
@@ -59,6 +58,8 @@ class ClsPredictor(Predictor):
input_tensor
.
copy_from_cpu
(
image
)
self
.
paddle_predictor
.
run
()
batch_output
=
output_tensor
.
copy_to_cpu
()
if
self
.
postprocess
is
not
None
:
batch_output
=
self
.
postprocess
(
batch_output
)
return
batch_output
...
...
@@ -66,14 +67,38 @@ def main(config):
cls_predictor
=
ClsPredictor
(
config
)
image_list
=
get_image_list
(
config
[
"Global"
][
"infer_imgs"
])
assert
config
[
"Global"
][
"batch_size"
]
==
1
for
idx
,
image_file
in
enumerate
(
image_list
):
img
=
cv2
.
imread
(
image_file
)[:,
:,
::
-
1
]
output
=
cls_predictor
.
predict
(
img
)
output
=
cls_predictor
.
postprocess
(
output
,
[
image_file
])
print
(
output
)
return
batch_imgs
=
[]
batch_names
=
[]
cnt
=
0
for
idx
,
img_path
in
enumerate
(
image_list
):
img
=
cv2
.
imread
(
img_path
)
if
img
is
None
:
logger
.
warning
(
"Image file failed to read and has been skipped. The path: {}"
.
format
(
img_path
))
else
:
img
=
img
[:,
:,
::
-
1
]
batch_imgs
.
append
(
img
)
img_name
=
os
.
path
.
basename
(
img_path
)
batch_names
.
append
(
img_name
)
cnt
+=
1
if
cnt
%
config
[
"Global"
][
"batch_size"
]
==
0
or
(
idx
+
1
)
==
len
(
image_list
):
if
len
(
batch_imgs
)
==
0
:
continue
batch_results
=
cls_predictor
.
predict
(
batch_imgs
)
for
number
,
result_dict
in
enumerate
(
batch_results
):
filename
=
batch_names
[
number
]
clas_ids
=
result_dict
[
"class_ids"
]
scores_str
=
"[{}]"
.
format
(
", "
.
join
(
"{:.2f}"
.
format
(
r
)
for
r
in
result_dict
[
"scores"
]))
label_names
=
result_dict
[
"label_names"
]
print
(
"{}:
\t
class id(s): {}, score(s): {}, label_name(s): {}"
.
format
(
filename
,
clas_ids
,
scores_str
,
label_names
))
batch_imgs
=
[]
batch_names
=
[]
return
if
__name__
==
"__main__"
:
args
=
config
.
parse_args
()
...
...
deploy/python/predict_rec.py
浏览文件 @
bd586f4a
...
...
@@ -54,12 +54,14 @@ class RecPredictor(Predictor):
input_tensor
.
copy_from_cpu
(
image
)
self
.
paddle_predictor
.
run
()
batch_output
=
output_tensor
.
copy_to_cpu
()
if
feature_normalize
:
feas_norm
=
np
.
sqrt
(
np
.
sum
(
np
.
square
(
batch_output
),
axis
=
1
,
keepdims
=
True
))
batch_output
=
np
.
divide
(
batch_output
,
feas_norm
)
if
self
.
postprocess
is
not
None
:
batch_output
=
self
.
postprocess
(
batch_output
)
return
batch_output
...
...
@@ -67,14 +69,33 @@ def main(config):
rec_predictor
=
RecPredictor
(
config
)
image_list
=
get_image_list
(
config
[
"Global"
][
"infer_imgs"
])
assert
config
[
"Global"
][
"batch_size"
]
==
1
for
idx
,
image_file
in
enumerate
(
image_list
):
batch_input
=
[]
img
=
cv2
.
imread
(
image_file
)[:,
:,
::
-
1
]
output
=
rec_predictor
.
predict
(
img
)
if
rec_predictor
.
postprocess
is
not
None
:
output
=
rec_predictor
.
postprocess
(
output
)
print
(
output
)
batch_imgs
=
[]
batch_names
=
[]
cnt
=
0
for
idx
,
img_path
in
enumerate
(
image_list
):
img
=
cv2
.
imread
(
img_path
)
if
img
is
None
:
logger
.
warning
(
"Image file failed to read and has been skipped. The path: {}"
.
format
(
img_path
))
else
:
img
=
img
[:,
:,
::
-
1
]
batch_imgs
.
append
(
img
)
img_name
=
os
.
path
.
basename
(
img_path
)
batch_names
.
append
(
img_name
)
cnt
+=
1
if
cnt
%
config
[
"Global"
][
"batch_size"
]
==
0
or
(
idx
+
1
)
==
len
(
image_list
):
if
len
(
batch_imgs
)
==
0
:
continue
batch_results
=
rec_predictor
.
predict
(
batch_imgs
)
for
number
,
result_dict
in
enumerate
(
batch_results
):
filename
=
batch_names
[
number
]
print
(
"{}:
\t
{}"
.
format
(
filename
,
result_dict
))
batch_imgs
=
[]
batch_names
=
[]
return
...
...
saxon_zh
@saxon_zh
mentioned in commit
0efcf0b6
·
12月 15, 2021
mentioned in commit
0efcf0b6
mentioned in commit 0efcf0b67d79599297b1b0298ef53c4a1da81983
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录