Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
znstj
PaddleOCR
提交
44840726
P
PaddleOCR
项目概览
znstj
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
44840726
编写于
11月 09, 2020
作者:
W
WenmuZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
后处理添加类型判断
上级
4402e629
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
16 addition
and
10 deletion
+16
-10
ppocr/postprocess/db_postprocess.py
ppocr/postprocess/db_postprocess.py
+5
-2
ppocr/postprocess/db_postprocess_torch.py
ppocr/postprocess/db_postprocess_torch.py
+5
-2
ppocr/postprocess/rec_postprocess.py
ppocr/postprocess/rec_postprocess.py
+6
-6
未找到文件。
ppocr/postprocess/db_postprocess.py
浏览文件 @
44840726
...
@@ -18,6 +18,7 @@ from __future__ import print_function
...
@@ -18,6 +18,7 @@ from __future__ import print_function
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
paddle
from
shapely.geometry
import
Polygon
from
shapely.geometry
import
Polygon
import
pyclipper
import
pyclipper
...
@@ -130,7 +131,9 @@ class DBPostProcess(object):
...
@@ -130,7 +131,9 @@ class DBPostProcess(object):
return
cv2
.
mean
(
bitmap
[
ymin
:
ymax
+
1
,
xmin
:
xmax
+
1
],
mask
)[
0
]
return
cv2
.
mean
(
bitmap
[
ymin
:
ymax
+
1
,
xmin
:
xmax
+
1
],
mask
)[
0
]
def
__call__
(
self
,
pred
,
shape_list
):
def
__call__
(
self
,
pred
,
shape_list
):
pred
=
pred
.
numpy
()[:,
0
,
:,
:]
if
isinstance
(
pred
,
paddle
.
Tensor
):
pred
=
pred
.
numpy
()
pred
=
pred
[:,
0
,
:,
:]
segmentation
=
pred
>
self
.
thresh
segmentation
=
pred
>
self
.
thresh
boxes_batch
=
[]
boxes_batch
=
[]
...
...
ppocr/postprocess/db_postprocess_torch.py
浏览文件 @
44840726
import
cv2
import
cv2
import
paddle
import
numpy
as
np
import
numpy
as
np
import
pyclipper
import
pyclipper
from
shapely.geometry
import
Polygon
from
shapely.geometry
import
Polygon
...
@@ -23,7 +24,9 @@ class DBPostProcess():
...
@@ -23,7 +24,9 @@ class DBPostProcess():
pred:
pred:
binary: text region segmentation map, with shape (N, 1,H, W)
binary: text region segmentation map, with shape (N, 1,H, W)
'''
'''
pred
=
pred
.
numpy
()[:,
0
,
:,
:]
if
isinstance
(
pred
,
paddle
.
Tensor
):
pred
=
pred
.
numpy
()
pred
=
pred
[:,
0
,
:,
:]
segmentation
=
self
.
binarize
(
pred
)
segmentation
=
self
.
binarize
(
pred
)
batch_out
=
[]
batch_out
=
[]
for
batch_index
in
range
(
pred
.
shape
[
0
]):
for
batch_index
in
range
(
pred
.
shape
[
0
]):
...
...
ppocr/postprocess/rec_postprocess.py
浏览文件 @
44840726
...
@@ -100,9 +100,10 @@ class CTCLabelDecode(BaseRecLabelDecode):
...
@@ -100,9 +100,10 @@ class CTCLabelDecode(BaseRecLabelDecode):
character_type
,
use_space_char
)
character_type
,
use_space_char
)
def
__call__
(
self
,
preds
,
label
=
None
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
preds
,
label
=
None
,
*
args
,
**
kwargs
):
if
isinstance
(
preds
,
paddle
.
Tensor
):
preds
=
preds
.
numpy
()
# out = self.decode_preds(preds)
# out = self.decode_preds(preds)
preds
=
F
.
softmax
(
preds
,
axis
=
2
).
numpy
()
preds_idx
=
preds
.
argmax
(
axis
=
2
)
preds_idx
=
preds
.
argmax
(
axis
=
2
)
preds_prob
=
preds
.
max
(
axis
=
2
)
preds_prob
=
preds
.
max
(
axis
=
2
)
text
=
self
.
decode
(
preds_idx
,
preds_prob
)
text
=
self
.
decode
(
preds_idx
,
preds_prob
)
...
@@ -116,19 +117,18 @@ class CTCLabelDecode(BaseRecLabelDecode):
...
@@ -116,19 +117,18 @@ class CTCLabelDecode(BaseRecLabelDecode):
return
dict_character
return
dict_character
def
decode_preds
(
self
,
preds
):
def
decode_preds
(
self
,
preds
):
probs
=
F
.
softmax
(
preds
,
axis
=
2
).
numpy
()
probs_ind
=
np
.
argmax
(
preds
,
axis
=
2
)
probs_ind
=
np
.
argmax
(
probs
,
axis
=
2
)
B
,
N
,
_
=
preds
.
shape
B
,
N
,
_
=
preds
.
shape
l
=
np
.
ones
(
B
).
astype
(
np
.
int64
)
*
N
l
=
np
.
ones
(
B
).
astype
(
np
.
int64
)
*
N
length
=
paddle
.
to_
variable
(
l
)
length
=
paddle
.
to_
tensor
(
l
)
out
=
paddle
.
fluid
.
layers
.
ctc_greedy_decoder
(
preds
,
0
,
length
)
out
=
paddle
.
fluid
.
layers
.
ctc_greedy_decoder
(
preds
,
0
,
length
)
batch_res
=
[
batch_res
=
[
x
[:
idx
[
0
]]
for
x
,
idx
in
zip
(
out
[
0
].
numpy
(),
out
[
1
].
numpy
())
x
[:
idx
[
0
]]
for
x
,
idx
in
zip
(
out
[
0
].
numpy
(),
out
[
1
].
numpy
())
]
]
result_list
=
[]
result_list
=
[]
for
sample_idx
,
ind
,
prob
in
zip
(
batch_res
,
probs_ind
,
pr
ob
s
):
for
sample_idx
,
ind
,
prob
in
zip
(
batch_res
,
probs_ind
,
pr
ed
s
):
char_list
=
[
self
.
character
[
idx
]
for
idx
in
sample_idx
]
char_list
=
[
self
.
character
[
idx
]
for
idx
in
sample_idx
]
valid_ind
=
np
.
where
(
ind
!=
0
)[
0
]
valid_ind
=
np
.
where
(
ind
!=
0
)[
0
]
if
len
(
valid_ind
)
==
0
:
if
len
(
valid_ind
)
==
0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录