Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
f18ddffa
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f18ddffa
编写于
11月 16, 2022
作者:
文幕地方
提交者:
GitHub
11月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update inference of PP-OCRv2 to paddlecv (#5587)
* add install of paddleclas * update inference with paddlecv
上级
71792d0e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
37 deletion
+24
-37
modelcenter/PP-OCRv2/APP/app.py
modelcenter/PP-OCRv2/APP/app.py
+10
-16
modelcenter/PP-OCRv3/APP/app.py
modelcenter/PP-OCRv3/APP/app.py
+10
-16
modelcenter/PP-StructureV2/APP/app.py
modelcenter/PP-StructureV2/APP/app.py
+4
-5
未找到文件。
modelcenter/PP-OCRv2/APP/app.py
浏览文件 @
f18ddffa
...
@@ -3,10 +3,8 @@ import base64
...
@@ -3,10 +3,8 @@ import base64
from
io
import
BytesIO
from
io
import
BytesIO
from
PIL
import
Image
from
PIL
import
Image
import
paddleocr
from
paddlecv
import
PaddleCV
from
paddleocr
import
PaddleOCR
,
draw_ocr
ocr
=
PaddleCV
(
task_name
=
"PP-OCRv2"
)
ocr
=
PaddleOCR
(
ocr_version
=
'PP-OCRv2'
,
use_angle_cls
=
True
,
lang
=
"ch"
)
def
image_to_base64
(
image
):
def
image_to_base64
(
image
):
...
@@ -20,20 +18,16 @@ def image_to_base64(image):
...
@@ -20,20 +18,16 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models
# UGC: Define the inference fn() for your models
def
model_inference
(
image
):
def
model_inference
(
image
):
result
=
ocr
.
ocr
(
image
,
cls
=
True
)
result
=
ocr
(
image
)[
0
]
# 显示结果
if
paddleocr
.
__version__
>=
"2.6.0.2"
:
result
=
result
[
0
]
boxes
=
[
line
[
0
]
for
line
in
result
]
txts
=
[
line
[
1
][
0
]
for
line
in
result
]
scores
=
[
line
[
1
][
1
]
for
line
in
result
]
im_show
=
draw_ocr
(
image
,
boxes
,
txts
=
None
,
scores
=
None
)
im_show
=
Image
.
fromarray
(
im_show
)
im_show
=
Image
.
open
(
'output/tmp.jpg'
)
res
=
[]
res
=
[]
for
i
in
range
(
len
(
boxes
)):
for
i
in
range
(
len
(
result
[
'dt_polys'
])):
res
.
append
(
dict
(
boxes
=
boxes
[
i
],
txt
=
txts
[
i
],
score
=
scores
[
i
]))
res
.
append
(
dict
(
boxes
=
result
[
'dt_polys'
][
i
],
txt
=
result
[
'rec_text'
][
i
],
score
=
result
[
'rec_score'
][
i
]))
json_out
=
{
"base64"
:
image_to_base64
(
im_show
),
"result"
:
res
}
json_out
=
{
"base64"
:
image_to_base64
(
im_show
),
"result"
:
res
}
return
im_show
,
json_out
return
im_show
,
json_out
...
...
modelcenter/PP-OCRv3/APP/app.py
浏览文件 @
f18ddffa
...
@@ -3,10 +3,8 @@ import base64
...
@@ -3,10 +3,8 @@ import base64
from
io
import
BytesIO
from
io
import
BytesIO
from
PIL
import
Image
from
PIL
import
Image
import
paddleocr
from
paddlecv
import
PaddleCV
from
paddleocr
import
PaddleOCR
,
draw_ocr
ocr
=
PaddleCV
(
task_name
=
"PP-OCRv3"
)
ocr
=
PaddleOCR
(
use_angle_cls
=
True
,
lang
=
"ch"
)
def
image_to_base64
(
image
):
def
image_to_base64
(
image
):
...
@@ -20,20 +18,16 @@ def image_to_base64(image):
...
@@ -20,20 +18,16 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models
# UGC: Define the inference fn() for your models
def
model_inference
(
image
):
def
model_inference
(
image
):
result
=
ocr
.
ocr
(
image
,
cls
=
True
)
result
=
ocr
(
image
)[
0
]
# 显示结果
if
paddleocr
.
__version__
>=
"2.6.0.2"
:
result
=
result
[
0
]
boxes
=
[
line
[
0
]
for
line
in
result
]
txts
=
[
line
[
1
][
0
]
for
line
in
result
]
scores
=
[
line
[
1
][
1
]
for
line
in
result
]
im_show
=
draw_ocr
(
image
,
boxes
,
txts
=
None
,
scores
=
None
)
im_show
=
Image
.
fromarray
(
im_show
)
im_show
=
Image
.
open
(
'output/tmp.jpg'
)
res
=
[]
res
=
[]
for
i
in
range
(
len
(
boxes
)):
for
i
in
range
(
len
(
result
[
'dt_polys'
])):
res
.
append
(
dict
(
boxes
=
boxes
[
i
],
txt
=
txts
[
i
],
score
=
scores
[
i
]))
res
.
append
(
dict
(
boxes
=
result
[
'dt_polys'
][
i
],
txt
=
result
[
'rec_text'
][
i
],
score
=
result
[
'rec_score'
][
i
]))
json_out
=
{
"base64"
:
image_to_base64
(
im_show
),
"result"
:
res
}
json_out
=
{
"base64"
:
image_to_base64
(
im_show
),
"result"
:
res
}
return
im_show
,
json_out
return
im_show
,
json_out
...
...
modelcenter/PP-StructureV2/APP/app.py
浏览文件 @
f18ddffa
...
@@ -3,9 +3,8 @@ import base64
...
@@ -3,9 +3,8 @@ import base64
from
io
import
BytesIO
from
io
import
BytesIO
from
PIL
import
Image
from
PIL
import
Image
from
paddleocr
import
PPStructure
from
paddlecv
import
PaddleCV
table_engine
=
PaddleCV
(
task_name
=
"PP-StructureV2-table"
)
table_engine
=
PPStructure
(
layout
=
False
,
show_log
=
True
)
def
image_to_base64
(
image
):
def
image_to_base64
(
image
):
...
@@ -19,8 +18,8 @@ def image_to_base64(image):
...
@@ -19,8 +18,8 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models
# UGC: Define the inference fn() for your models
def
model_inference
(
image
):
def
model_inference
(
image
):
result
=
table_engine
(
image
)
result
=
table_engine
(
image
)
[
0
]
res
=
result
[
0
][
'res'
][
'html'
]
res
=
result
[
'html'
]
json_out
=
{
"result"
:
res
}
json_out
=
{
"result"
:
res
}
return
res
,
json_out
return
res
,
json_out
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录