Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
c342b7a0
P
PaddleOCR
项目概览
weixin_41840029
/
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看板
提交
c342b7a0
编写于
10月 09, 2021
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix infer
上级
50020a8e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
12 deletion
+14
-12
tools/infer_kie.py
tools/infer_kie.py
+14
-12
未找到文件。
tools/infer_kie.py
浏览文件 @
c342b7a0
...
...
@@ -47,9 +47,9 @@ def read_class_list(filepath):
return
dict
def
draw_kie_result
(
batch
,
node
,
idx_to_cls
):
img
=
batch
[
-
2
]
boxes
=
batch
[
-
1
]
def
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
count
):
img
=
batch
[
6
].
copy
()
boxes
=
batch
[
7
]
h
,
w
=
img
.
shape
[:
2
]
pred_img
=
np
.
ones
((
h
,
w
*
2
,
3
),
dtype
=
np
.
uint8
)
*
255
max_value
,
max_idx
=
paddle
.
max
(
node
,
-
1
),
paddle
.
argmax
(
node
,
-
1
)
...
...
@@ -77,11 +77,15 @@ def draw_kie_result(batch, node, idx_to_cls):
text
=
pred_label
+
'('
+
pred_score
+
')'
cv2
.
putText
(
pred_img
,
text
,
(
x_min
*
2
,
y_min
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
255
,
0
,
0
),
1
)
vis_img
=
np
.
ones
((
h
,
w
*
3
,
3
),
dtype
=
np
.
uint8
)
*
255
vis_img
[:,
:
w
]
=
img
vis_img
[:,
w
:]
=
pred_img
return
vis_img
save_kie_path
=
os
.
path
.
dirname
(
config
[
'Global'
][
'save_res_path'
])
+
"/kie_results/"
if
not
os
.
path
.
exists
(
save_kie_path
):
os
.
makedirs
(
save_kie_path
)
save_path
=
os
.
path
.
join
(
save_kie_path
,
str
(
count
)
+
".png"
)
cv2
.
imwrite
(
save_path
,
vis_img
)
logger
.
info
(
"The Kie Image saved in {}"
.
format
(
save_path
))
def
main
():
...
...
@@ -89,7 +93,6 @@ def main():
# build model
model
=
build_model
(
config
[
'Architecture'
])
init_model
(
config
,
model
,
logger
)
# create data ops
...
...
@@ -97,6 +100,8 @@ def main():
for
op
in
config
[
'Eval'
][
'dataset'
][
'transforms'
]:
transforms
.
append
(
op
)
data_dir
=
config
[
'Eval'
][
'dataset'
][
'data_dir'
]
ops
=
create_operators
(
transforms
,
global_config
)
save_res_path
=
config
[
'Global'
][
'save_res_path'
]
...
...
@@ -109,11 +114,10 @@ def main():
with
open
(
save_res_path
,
"wb"
)
as
fout
:
with
open
(
config
[
'Global'
][
'infer_img'
],
"rb"
)
as
f
:
lines
=
f
.
readlines
()
for
data_line
in
lines
:
for
index
,
data_line
in
enumerate
(
lines
)
:
data_line
=
data_line
.
decode
(
'utf-8'
)
substr
=
data_line
.
strip
(
"
\n
"
).
split
(
"
\t
"
)
img_path
,
label
=
"/Users/hongyongjie/project/PaddleOCR/train_data/wildreceipt/"
+
substr
[
0
],
substr
[
1
]
img_path
,
label
=
data_dir
+
"/"
+
substr
[
0
],
substr
[
1
]
data
=
{
'img_path'
:
img_path
,
'label'
:
label
}
with
open
(
data
[
'img_path'
],
'rb'
)
as
f
:
img
=
f
.
read
()
...
...
@@ -126,9 +130,7 @@ def main():
batch
[
i
],
axis
=
0
))
node
,
edge
=
model
(
batch_pred
)
node
=
F
.
softmax
(
node
,
-
1
)
img
=
draw_kie_result
(
batch
,
node
,
idx_to_cls
)
cv2
.
imwrite
(
'1.png'
,
img
)
exit
()
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
index
)
logger
.
info
(
"success!"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录