Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
d15fca53
P
PaddleOCR
项目概览
s920243400
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d15fca53
编写于
7月 21, 2022
作者:
D
Double_V
提交者:
qq_25193841
8月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #6824 from ChenNima/release/2.5-kie-save-res
[kie]add write_kie_result to kie infer tool
上级
b7d99acd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
26 addition
and
1 deletion
+26
-1
tools/infer_kie.py
tools/infer_kie.py
+26
-1
未找到文件。
tools/infer_kie.py
浏览文件 @
d15fca53
...
@@ -88,6 +88,29 @@ def draw_kie_result(batch, node, idx_to_cls, count):
...
@@ -88,6 +88,29 @@ def draw_kie_result(batch, node, idx_to_cls, count):
cv2
.
imwrite
(
save_path
,
vis_img
)
cv2
.
imwrite
(
save_path
,
vis_img
)
logger
.
info
(
"The Kie Image saved in {}"
.
format
(
save_path
))
logger
.
info
(
"The Kie Image saved in {}"
.
format
(
save_path
))
def
write_kie_result
(
fout
,
node
,
data
):
"""
Write infer result to output file, sorted by the predict label of each line.
The format keeps the same as the input with additional score attribute.
"""
import
json
label
=
data
[
'label'
]
annotations
=
json
.
loads
(
label
)
max_value
,
max_idx
=
paddle
.
max
(
node
,
-
1
),
paddle
.
argmax
(
node
,
-
1
)
node_pred_label
=
max_idx
.
numpy
().
tolist
()
node_pred_score
=
max_value
.
numpy
().
tolist
()
res
=
[]
for
i
,
label
in
enumerate
(
node_pred_label
):
pred_score
=
'{:.2f}'
.
format
(
node_pred_score
[
i
])
pred_res
=
{
'label'
:
label
,
'transcription'
:
annotations
[
i
][
'transcription'
],
'score'
:
pred_score
,
'points'
:
annotations
[
i
][
'points'
],
}
res
.
append
(
pred_res
)
res
.
sort
(
key
=
lambda
x
:
x
[
'label'
])
fout
.
writelines
([
json
.
dumps
(
res
,
ensure_ascii
=
False
)
+
'
\n
'
])
def
main
():
def
main
():
global_config
=
config
[
'Global'
]
global_config
=
config
[
'Global'
]
...
@@ -114,7 +137,7 @@ def main():
...
@@ -114,7 +137,7 @@ def main():
warmup_times
=
0
warmup_times
=
0
count_t
=
[]
count_t
=
[]
with
open
(
save_res_path
,
"w
b
"
)
as
fout
:
with
open
(
save_res_path
,
"w"
)
as
fout
:
with
open
(
config
[
'Global'
][
'infer_img'
],
"rb"
)
as
f
:
with
open
(
config
[
'Global'
][
'infer_img'
],
"rb"
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
for
index
,
data_line
in
enumerate
(
lines
):
for
index
,
data_line
in
enumerate
(
lines
):
...
@@ -139,6 +162,8 @@ def main():
...
@@ -139,6 +162,8 @@ def main():
node
=
F
.
softmax
(
node
,
-
1
)
node
=
F
.
softmax
(
node
,
-
1
)
count_t
.
append
(
time
.
time
()
-
st
)
count_t
.
append
(
time
.
time
()
-
st
)
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
index
)
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
index
)
write_kie_result
(
fout
,
node
,
data
)
fout
.
close
()
logger
.
info
(
"success!"
)
logger
.
info
(
"success!"
)
logger
.
info
(
"It took {} s for predict {} images."
.
format
(
logger
.
info
(
"It took {} s for predict {} images."
.
format
(
np
.
sum
(
count_t
),
len
(
count_t
)))
np
.
sum
(
count_t
),
len
(
count_t
)))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录