Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
9dd50e6a
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看板
提交
9dd50e6a
编写于
12月 19, 2021
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ips
上级
3312d624
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
3 deletion
+17
-3
tools/infer_kie.py
tools/infer_kie.py
+17
-3
未找到文件。
tools/infer_kie.py
浏览文件 @
9dd50e6a
...
@@ -33,8 +33,9 @@ import paddle
...
@@ -33,8 +33,9 @@ import paddle
from
ppocr.data
import
create_operators
,
transform
from
ppocr.data
import
create_operators
,
transform
from
ppocr.modeling.architectures
import
build_model
from
ppocr.modeling.architectures
import
build_model
from
ppocr.utils.save_load
import
init
_model
from
ppocr.utils.save_load
import
load
_model
import
tools.program
as
program
import
tools.program
as
program
import
time
def
read_class_list
(
filepath
):
def
read_class_list
(
filepath
):
...
@@ -80,7 +81,8 @@ def draw_kie_result(batch, node, idx_to_cls, count):
...
@@ -80,7 +81,8 @@ def draw_kie_result(batch, node, idx_to_cls, count):
vis_img
=
np
.
ones
((
h
,
w
*
3
,
3
),
dtype
=
np
.
uint8
)
*
255
vis_img
=
np
.
ones
((
h
,
w
*
3
,
3
),
dtype
=
np
.
uint8
)
*
255
vis_img
[:,
:
w
]
=
img
vis_img
[:,
:
w
]
=
img
vis_img
[:,
w
:]
=
pred_img
vis_img
[:,
w
:]
=
pred_img
save_kie_path
=
os
.
path
.
dirname
(
config
[
'Global'
][
'save_res_path'
])
+
"/kie_results/"
save_kie_path
=
os
.
path
.
dirname
(
config
[
'Global'
][
'save_res_path'
])
+
"/kie_results/"
if
not
os
.
path
.
exists
(
save_kie_path
):
if
not
os
.
path
.
exists
(
save_kie_path
):
os
.
makedirs
(
save_kie_path
)
os
.
makedirs
(
save_kie_path
)
save_path
=
os
.
path
.
join
(
save_kie_path
,
str
(
count
)
+
".png"
)
save_path
=
os
.
path
.
join
(
save_kie_path
,
str
(
count
)
+
".png"
)
...
@@ -93,7 +95,7 @@ def main():
...
@@ -93,7 +95,7 @@ def main():
# build model
# build model
model
=
build_model
(
config
[
'Architecture'
])
model
=
build_model
(
config
[
'Architecture'
])
init_model
(
config
,
model
,
logger
)
load_model
(
config
,
model
)
# create data ops
# create data ops
transforms
=
[]
transforms
=
[]
...
@@ -111,10 +113,15 @@ def main():
...
@@ -111,10 +113,15 @@ def main():
os
.
makedirs
(
os
.
path
.
dirname
(
save_res_path
))
os
.
makedirs
(
os
.
path
.
dirname
(
save_res_path
))
model
.
eval
()
model
.
eval
()
warmup_times
=
0
count_t
=
[]
with
open
(
save_res_path
,
"wb"
)
as
fout
:
with
open
(
save_res_path
,
"wb"
)
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
):
if
index
==
10
:
warmup_t
=
time
.
time
()
data_line
=
data_line
.
decode
(
'utf-8'
)
data_line
=
data_line
.
decode
(
'utf-8'
)
substr
=
data_line
.
strip
(
"
\n
"
).
split
(
"
\t
"
)
substr
=
data_line
.
strip
(
"
\n
"
).
split
(
"
\t
"
)
img_path
,
label
=
data_dir
+
"/"
+
substr
[
0
],
substr
[
1
]
img_path
,
label
=
data_dir
+
"/"
+
substr
[
0
],
substr
[
1
]
...
@@ -122,16 +129,23 @@ def main():
...
@@ -122,16 +129,23 @@ def main():
with
open
(
data
[
'img_path'
],
'rb'
)
as
f
:
with
open
(
data
[
'img_path'
],
'rb'
)
as
f
:
img
=
f
.
read
()
img
=
f
.
read
()
data
[
'image'
]
=
img
data
[
'image'
]
=
img
st
=
time
.
time
()
batch
=
transform
(
data
,
ops
)
batch
=
transform
(
data
,
ops
)
batch_pred
=
[
0
]
*
len
(
batch
)
batch_pred
=
[
0
]
*
len
(
batch
)
for
i
in
range
(
len
(
batch
)):
for
i
in
range
(
len
(
batch
)):
batch_pred
[
i
]
=
paddle
.
to_tensor
(
batch_pred
[
i
]
=
paddle
.
to_tensor
(
np
.
expand_dims
(
np
.
expand_dims
(
batch
[
i
],
axis
=
0
))
batch
[
i
],
axis
=
0
))
st
=
time
.
time
()
node
,
edge
=
model
(
batch_pred
)
node
,
edge
=
model
(
batch_pred
)
node
=
F
.
softmax
(
node
,
-
1
)
node
=
F
.
softmax
(
node
,
-
1
)
count_t
.
append
(
time
.
time
()
-
st
)
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
index
)
draw_kie_result
(
batch
,
node
,
idx_to_cls
,
index
)
logger
.
info
(
"success!"
)
logger
.
info
(
"success!"
)
logger
.
info
(
"It took {} s for predict {} images."
.
format
(
np
.
sum
(
count_t
),
len
(
count_t
)))
ips
=
np
.
sum
(
count_t
[
warmup_times
:])
/
len
(
count_t
[
warmup_times
:])
logger
.
info
(
"The ips is {} images/s"
.
format
(
ips
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录