Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
c703a589
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看板
提交
c703a589
编写于
1月 12, 2022
作者:
文幕地方
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix re infer bug
上级
99de0353
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
31 deletion
+34
-31
ppocr/data/imaug/label_ops.py
ppocr/data/imaug/label_ops.py
+34
-31
未找到文件。
ppocr/data/imaug/label_ops.py
浏览文件 @
c703a589
...
...
@@ -833,19 +833,20 @@ class VQATokenLabelEncode(object):
segment_offset_id
=
[]
gt_label_list
=
[]
if
self
.
contains_re
:
# for re
entities
=
[]
if
not
self
.
infer_mode
:
relations
=
[]
id2label
=
{}
entity_id_to_index_map
=
{}
empty_entity
=
set
()
entities
=
[]
# for re
train_re
=
self
.
contains_re
and
not
self
.
infer_mode
if
train_re
:
relations
=
[]
id2label
=
{}
entity_id_to_index_map
=
{}
empty_entity
=
set
()
data
[
'ocr_info'
]
=
copy
.
deepcopy
(
ocr_info
)
for
info
in
ocr_info
:
if
self
.
contains_re
and
not
self
.
infer_mod
e
:
if
train_r
e
:
# for re
if
len
(
info
[
"text"
])
==
0
:
empty_entity
.
add
(
info
[
"id"
])
...
...
@@ -872,24 +873,22 @@ class VQATokenLabelEncode(object):
gt_label
=
self
.
_parse_label
(
label
,
encode_res
)
# construct entities for re
if
self
.
contains_re
:
if
not
self
.
infer_mode
:
if
gt_label
[
0
]
!=
self
.
label2id_map
[
"O"
]:
entity_id_to_index_map
[
info
[
"id"
]]
=
len
(
entities
)
label
=
label
.
upper
()
entities
.
append
({
"start"
:
len
(
input_ids_list
),
"end"
:
len
(
input_ids_list
)
+
len
(
encode_res
[
"input_ids"
]),
"label"
:
label
.
upper
(),
})
else
:
if
train_re
:
if
gt_label
[
0
]
!=
self
.
label2id_map
[
"O"
]:
entity_id_to_index_map
[
info
[
"id"
]]
=
len
(
entities
)
label
=
label
.
upper
()
entities
.
append
({
"start"
:
len
(
input_ids_list
),
"end"
:
len
(
input_ids_list
)
+
len
(
encode_res
[
"input_ids"
]),
"label"
:
'O'
,
"label"
:
label
.
upper
()
,
})
else
:
entities
.
append
({
"start"
:
len
(
input_ids_list
),
"end"
:
len
(
input_ids_list
)
+
len
(
encode_res
[
"input_ids"
]),
"label"
:
'O'
,
})
input_ids_list
.
extend
(
encode_res
[
"input_ids"
])
token_type_ids_list
.
extend
(
encode_res
[
"token_type_ids"
])
bbox_list
.
extend
([
bbox
]
*
len
(
encode_res
[
"input_ids"
]))
...
...
@@ -908,19 +907,23 @@ class VQATokenLabelEncode(object):
padding_side
=
self
.
tokenizer
.
padding_side
,
pad_token_type_id
=
self
.
tokenizer
.
pad_token_type_id
,
pad_token_id
=
self
.
tokenizer
.
pad_token_id
)
data
[
'entities'
]
=
entities
if
self
.
contains_re
:
data
[
'entities'
]
=
entities
if
self
.
infer_mode
:
data
[
'ocr_info'
]
=
ocr_info
else
:
data
[
'relations'
]
=
relations
data
[
'id2label'
]
=
id2label
data
[
'empty_entity'
]
=
empty_entity
data
[
'entity_id_to_index_map'
]
=
entity_id_to_index_map
if
train_re
:
data
[
'relations'
]
=
relations
data
[
'id2label'
]
=
id2label
data
[
'empty_entity'
]
=
empty_entity
data
[
'entity_id_to_index_map'
]
=
entity_id_to_index_map
return
data
def
_load_ocr_info
(
self
,
data
):
def
trans_poly_to_bbox
(
poly
):
x1
=
np
.
min
([
p
[
0
]
for
p
in
poly
])
x2
=
np
.
max
([
p
[
0
]
for
p
in
poly
])
y1
=
np
.
min
([
p
[
1
]
for
p
in
poly
])
y2
=
np
.
max
([
p
[
1
]
for
p
in
poly
])
return
[
x1
,
y1
,
x2
,
y2
]
if
self
.
infer_mode
:
ocr_result
=
self
.
ocr_engine
.
ocr
(
data
[
'image'
],
cls
=
False
)
ocr_info
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录