Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
4382eee6
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 2 年 前同步成功
通知
285
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4382eee6
编写于
12月 29, 2022
作者:
jm_12138
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update ch_pp-ocrv3_det (#2173)
* update ch_pp-ocrv3_det * update
上级
3d13232e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
21 deletion
+32
-21
modules/image/text_recognition/ch_pp-ocrv3_det/module.py
modules/image/text_recognition/ch_pp-ocrv3_det/module.py
+16
-1
modules/image/text_recognition/ch_pp-ocrv3_det/test.py
modules/image/text_recognition/ch_pp-ocrv3_det/test.py
+16
-20
未找到文件。
modules/image/text_recognition/ch_pp-ocrv3_det/module.py
浏览文件 @
4382eee6
...
...
@@ -21,22 +21,36 @@ import ast
import
base64
import
os
import
time
from
io
import
BytesIO
import
cv2
import
numpy
as
np
import
paddle.inference
as
paddle_infer
from
PIL
import
Image
from
paddlehub.utils.utils
import
logger
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
from
paddlehub.utils.utils
import
logger
def
base64_to_cv2
(
b64str
):
data
=
base64
.
b64decode
(
b64str
.
encode
(
'utf8'
))
data
=
np
.
fromstring
(
data
,
np
.
uint8
)
data
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
if
data
is
None
:
buf
=
BytesIO
()
image_decode
=
base64
.
b64decode
(
b64str
.
encode
(
'utf8'
))
image
=
BytesIO
(
image_decode
)
im
=
Image
.
open
(
image
)
rgb
=
im
.
convert
(
'RGB'
)
rgb
.
save
(
buf
,
'jpeg'
)
buf
.
seek
(
0
)
image_bytes
=
buf
.
read
()
data_base64
=
str
(
base64
.
b64encode
(
image_bytes
),
encoding
=
"utf-8"
)
image_decode
=
base64
.
b64decode
(
data_base64
)
img_array
=
np
.
frombuffer
(
image_decode
,
np
.
uint8
)
data
=
cv2
.
imdecode
(
img_array
,
cv2
.
IMREAD_COLOR
)
return
data
...
...
@@ -49,6 +63,7 @@ def base64_to_cv2(b64str):
author_email
=
"paddle-dev@baidu.com"
,
type
=
"cv/text_recognition"
)
class
ChPPOCRv3Det
:
def
__init__
(
self
,
enable_mkldnn
=
False
):
"""
initialize with the necessary elements
...
...
modules/image/text_recognition/ch_pp-ocrv3_det/test.py
浏览文件 @
4382eee6
...
...
@@ -4,13 +4,14 @@ import unittest
import
cv2
import
requests
import
paddlehub
as
hub
import
paddlehub
as
hub
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
)
->
None
:
img_url
=
'https://unsplash.com/photos/KTzZVDjUsXw/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MzM3fHx0ZXh0fGVufDB8fHx8MTY2MzUxMTExMQ&force=true&w=640'
...
...
@@ -34,8 +35,9 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
visualization
=
False
,
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
def
test_detect_text2
(
self
):
results
=
self
.
module
.
detect_text
(
...
...
@@ -43,8 +45,9 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
visualization
=
False
,
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
def
test_detect_text3
(
self
):
results
=
self
.
module
.
detect_text
(
...
...
@@ -52,8 +55,9 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
True
,
visualization
=
False
,
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
def
test_detect_text4
(
self
):
results
=
self
.
module
.
detect_text
(
...
...
@@ -61,22 +65,15 @@ class TestHubModule(unittest.TestCase):
use_gpu
=
False
,
visualization
=
True
,
)
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
self
.
assertEqual
(
results
[
0
][
'data'
],
[[[
261
,
202
],
[
376
,
202
],
[
376
,
239
],
[
261
,
239
]],
[[
283
,
162
],
[
352
,
162
],
[
352
,
202
],
[
283
,
202
]]])
def
test_detect_text5
(
self
):
self
.
assertRaises
(
AttributeError
,
self
.
module
.
detect_text
,
images
=
[
'tests/test.jpg'
]
)
self
.
assertRaises
(
AttributeError
,
self
.
module
.
detect_text
,
images
=
[
'tests/test.jpg'
])
def
test_detect_text6
(
self
):
self
.
assertRaises
(
AssertionError
,
self
.
module
.
detect_text
,
paths
=
[
'no.jpg'
]
)
self
.
assertRaises
(
AssertionError
,
self
.
module
.
detect_text
,
paths
=
[
'no.jpg'
])
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
...
...
@@ -87,4 +84,3 @@ class TestHubModule(unittest.TestCase):
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录