Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
974588ea
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看板
提交
974588ea
编写于
9月 07, 2022
作者:
E
Evezerest
提交者:
qq_25193841
9月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #7513 from whjdark/dygraph
new table gt format
上级
cebf3205
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
172 deletion
+54
-172
PPOCRLabel/PPOCRLabel.py
PPOCRLabel/PPOCRLabel.py
+34
-47
PPOCRLabel/libs/dataPartitionDialog.py
PPOCRLabel/libs/dataPartitionDialog.py
+0
-113
PPOCRLabel/libs/utils.py
PPOCRLabel/libs/utils.py
+20
-12
未找到文件。
PPOCRLabel/PPOCRLabel.py
浏览文件 @
974588ea
...
@@ -2449,13 +2449,6 @@ class MainWindow(QMainWindow):
...
@@ -2449,13 +2449,6 @@ class MainWindow(QMainWindow):
export PPLabel and CSV to JSON (PubTabNet)
export PPLabel and CSV to JSON (PubTabNet)
'''
'''
import
pandas
as
pd
import
pandas
as
pd
from
libs.dataPartitionDialog
import
DataPartitionDialog
# data partition user input
partitionDialog
=
DataPartitionDialog
(
parent
=
self
)
partitionDialog
.
exec
()
if
partitionDialog
.
getStatus
()
==
False
:
return
# automatically save annotations
# automatically save annotations
self
.
saveFilestate
()
self
.
saveFilestate
()
...
@@ -2478,28 +2471,19 @@ class MainWindow(QMainWindow):
...
@@ -2478,28 +2471,19 @@ class MainWindow(QMainWindow):
labeldict
[
file
]
=
eval
(
label
)
labeldict
[
file
]
=
eval
(
label
)
else
:
else
:
labeldict
[
file
]
=
[]
labeldict
[
file
]
=
[]
# read table recognition output
TableRec_excel_dir
=
os
.
path
.
join
(
self
.
lastOpenDir
,
'tableRec_excel_output'
)
train_split
,
val_split
,
test_split
=
partitionDialog
.
getDataPartition
()
# save txt
# check validate
fid
=
open
(
if
train_split
+
val_split
+
test_split
>
100
:
"{}/gt.txt"
.
format
(
self
.
lastOpenDir
),
"w"
,
encoding
=
'utf-8'
)
msg
=
"The sum of training, validation and testing data should be less than 100%"
QMessageBox
.
information
(
self
,
"Information"
,
msg
)
return
print
(
train_split
,
val_split
,
test_split
)
train_split
,
val_split
,
test_split
=
float
(
train_split
)
/
100.
,
float
(
val_split
)
/
100.
,
float
(
test_split
)
/
100.
train_id
=
int
(
len
(
labeldict
)
*
train_split
)
val_id
=
int
(
len
(
labeldict
)
*
(
train_split
+
val_split
))
print
(
'Data partition: train:'
,
train_id
,
'validation:'
,
val_id
-
train_id
,
'test:'
,
len
(
labeldict
)
-
val_id
)
TableRec_excel_dir
=
os
.
path
.
join
(
self
.
lastOpenDir
,
'tableRec_excel_output'
)
json_results
=
[]
imgid
=
0
for
image_path
in
labeldict
.
keys
():
for
image_path
in
labeldict
.
keys
():
# load csv annotations
# load csv annotations
filename
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
image_path
))
filename
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
image_path
))
csv_path
=
os
.
path
.
join
(
TableRec_excel_dir
,
filename
+
'.xlsx'
)
csv_path
=
os
.
path
.
join
(
TableRec_excel_dir
,
filename
+
'.xlsx'
)
if
not
os
.
path
.
exists
(
csv_path
):
if
not
os
.
path
.
exists
(
csv_path
):
continue
continue
...
@@ -2518,28 +2502,31 @@ class MainWindow(QMainWindow):
...
@@ -2518,28 +2502,31 @@ class MainWindow(QMainWindow):
cells
=
[]
cells
=
[]
for
anno
in
labeldict
[
image_path
]:
for
anno
in
labeldict
[
image_path
]:
tokens
=
list
(
anno
[
'transcription'
])
tokens
=
list
(
anno
[
'transcription'
])
obb
=
anno
[
'points'
]
cells
.
append
({
hbb
=
OBB2HBB
(
np
.
array
(
obb
)).
tolist
()
'tokens'
:
tokens
,
cells
.
append
({
'tokens'
:
tokens
,
'bbox'
:
hbb
})
'bbox'
:
anno
[
'points'
]
})
# data split
if
imgid
<
train_id
:
# 构造标注信息
split
=
'train'
html
=
{
elif
imgid
<
val_id
:
'structure'
:
{
split
=
'val'
'tokens'
:
token_list
else
:
},
split
=
'test'
'cells'
:
cells
}
# save dict
d
=
{
html
=
{
'structure'
:
{
'tokens'
:
token_list
},
'cells'
:
cells
}
'filename'
:
os
.
path
.
basename
(
image_path
),
json_results
.
append
({
'filename'
:
os
.
path
.
basename
(
image_path
),
'split'
:
split
,
'imgid'
:
imgid
,
'html'
:
html
})
'html'
:
html
imgid
+=
1
}
# 重构HTML
# save json
d
[
'gt'
]
=
rebuild_html_from_ppstructure_label
(
d
)
with
open
(
"{}/annotation.json"
.
format
(
self
.
lastOpenDir
),
"w"
,
encoding
=
'utf-8'
)
as
fid
:
fid
.
write
(
'{}
\n
'
.
format
(
fid
.
write
(
json
.
dumps
(
json_results
,
ensure_ascii
=
False
))
json
.
dumps
(
d
,
ensure_ascii
=
False
)))
msg
=
'JSON sucessfully saved in {}/annotation.json'
.
format
(
self
.
lastOpenDir
)
# convert to PP-Structure label format
fid
.
close
()
msg
=
'JSON sucessfully saved in {}/gt.txt'
.
format
(
self
.
lastOpenDir
)
QMessageBox
.
information
(
self
,
"Information"
,
msg
)
QMessageBox
.
information
(
self
,
"Information"
,
msg
)
def
autolcm
(
self
):
def
autolcm
(
self
):
...
...
PPOCRLabel/libs/dataPartitionDialog.py
已删除
100644 → 0
浏览文件 @
cebf3205
try
:
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
from
PyQt5.QtWidgets
import
*
except
ImportError
:
from
PyQt4.QtGui
import
*
from
PyQt4.QtCore
import
*
from
libs.utils
import
newIcon
import
time
import
datetime
import
json
import
cv2
import
numpy
as
np
BB
=
QDialogButtonBox
class
DataPartitionDialog
(
QDialog
):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
()
self
.
parnet
=
parent
self
.
title
=
'DATA PARTITION'
self
.
train_ratio
=
70
self
.
val_ratio
=
15
self
.
test_ratio
=
15
self
.
initUI
()
def
initUI
(
self
):
self
.
setWindowTitle
(
self
.
title
)
self
.
setWindowModality
(
Qt
.
ApplicationModal
)
self
.
flag_accept
=
True
if
self
.
parnet
.
lang
==
'ch'
:
msg
=
"导出JSON前请保存所有图像的标注且关闭EXCEL!"
else
:
msg
=
"Please save all the annotations and close the EXCEL before exporting JSON!"
info_msg
=
QLabel
(
msg
,
self
)
info_msg
.
setWordWrap
(
True
)
info_msg
.
setStyleSheet
(
"color: red"
)
info_msg
.
setFont
(
QFont
(
'Arial'
,
12
))
train_lbl
=
QLabel
(
'Train split: '
,
self
)
train_lbl
.
setFont
(
QFont
(
'Arial'
,
15
))
val_lbl
=
QLabel
(
'Valid split: '
,
self
)
val_lbl
.
setFont
(
QFont
(
'Arial'
,
15
))
test_lbl
=
QLabel
(
'Test split: '
,
self
)
test_lbl
.
setFont
(
QFont
(
'Arial'
,
15
))
self
.
train_input
=
QLineEdit
(
self
)
self
.
train_input
.
setFont
(
QFont
(
'Arial'
,
15
))
self
.
val_input
=
QLineEdit
(
self
)
self
.
val_input
.
setFont
(
QFont
(
'Arial'
,
15
))
self
.
test_input
=
QLineEdit
(
self
)
self
.
test_input
.
setFont
(
QFont
(
'Arial'
,
15
))
self
.
train_input
.
setText
(
str
(
self
.
train_ratio
))
self
.
val_input
.
setText
(
str
(
self
.
val_ratio
))
self
.
test_input
.
setText
(
str
(
self
.
test_ratio
))
validator
=
QIntValidator
(
0
,
100
)
self
.
train_input
.
setValidator
(
validator
)
self
.
val_input
.
setValidator
(
validator
)
self
.
test_input
.
setValidator
(
validator
)
gridlayout
=
QGridLayout
()
gridlayout
.
addWidget
(
info_msg
,
0
,
0
,
1
,
2
)
gridlayout
.
addWidget
(
train_lbl
,
1
,
0
)
gridlayout
.
addWidget
(
val_lbl
,
2
,
0
)
gridlayout
.
addWidget
(
test_lbl
,
3
,
0
)
gridlayout
.
addWidget
(
self
.
train_input
,
1
,
1
)
gridlayout
.
addWidget
(
self
.
val_input
,
2
,
1
)
gridlayout
.
addWidget
(
self
.
test_input
,
3
,
1
)
bb
=
BB
(
BB
.
Ok
|
BB
.
Cancel
,
Qt
.
Horizontal
,
self
)
bb
.
button
(
BB
.
Ok
).
setIcon
(
newIcon
(
'done'
))
bb
.
button
(
BB
.
Cancel
).
setIcon
(
newIcon
(
'undo'
))
bb
.
accepted
.
connect
(
self
.
validate
)
bb
.
rejected
.
connect
(
self
.
cancel
)
gridlayout
.
addWidget
(
bb
,
4
,
0
,
1
,
2
)
self
.
setLayout
(
gridlayout
)
self
.
show
()
def
validate
(
self
):
self
.
flag_accept
=
True
self
.
accept
()
def
cancel
(
self
):
self
.
flag_accept
=
False
self
.
reject
()
def
getStatus
(
self
):
return
self
.
flag_accept
def
getDataPartition
(
self
):
self
.
train_ratio
=
int
(
self
.
train_input
.
text
())
self
.
val_ratio
=
int
(
self
.
val_input
.
text
())
self
.
test_ratio
=
int
(
self
.
test_input
.
text
())
return
self
.
train_ratio
,
self
.
val_ratio
,
self
.
test_ratio
def
closeEvent
(
self
,
event
):
self
.
flag_accept
=
False
self
.
reject
()
PPOCRLabel/libs/utils.py
浏览文件 @
974588ea
...
@@ -176,18 +176,6 @@ def boxPad(box, imgShape, pad : int) -> np.array:
...
@@ -176,18 +176,6 @@ def boxPad(box, imgShape, pad : int) -> np.array:
return
box
return
box
def
OBB2HBB
(
obb
)
->
np
.
array
:
"""
Convert Oriented Bounding Box to Horizontal Bounding Box.
"""
hbb
=
np
.
zeros
(
4
,
dtype
=
np
.
int32
)
hbb
[
0
]
=
min
(
obb
[:,
0
])
hbb
[
1
]
=
min
(
obb
[:,
1
])
hbb
[
2
]
=
max
(
obb
[:,
0
])
hbb
[
3
]
=
max
(
obb
[:,
1
])
return
hbb
def
expand_list
(
merged
,
html_list
):
def
expand_list
(
merged
,
html_list
):
'''
'''
Fill blanks according to merged cells
Fill blanks according to merged cells
...
@@ -232,6 +220,26 @@ def convert_token(html_list):
...
@@ -232,6 +220,26 @@ def convert_token(html_list):
return
token_list
return
token_list
def
rebuild_html_from_ppstructure_label
(
label_info
):
from
html
import
escape
html_code
=
label_info
[
'html'
][
'structure'
][
'tokens'
].
copy
()
to_insert
=
[
i
for
i
,
tag
in
enumerate
(
html_code
)
if
tag
in
(
'<td>'
,
'>'
)
]
for
i
,
cell
in
zip
(
to_insert
[::
-
1
],
label_info
[
'html'
][
'cells'
][::
-
1
]):
if
cell
[
'tokens'
]:
cell
=
[
escape
(
token
)
if
len
(
token
)
==
1
else
token
for
token
in
cell
[
'tokens'
]
]
cell
=
''
.
join
(
cell
)
html_code
.
insert
(
i
+
1
,
cell
)
html_code
=
''
.
join
(
html_code
)
html_code
=
'<html><body><table>{}</table></body></html>'
.
format
(
html_code
)
return
html_code
def
stepsInfo
(
lang
=
'en'
):
def
stepsInfo
(
lang
=
'en'
):
if
lang
==
'ch'
:
if
lang
==
'ch'
:
msg
=
"1. 安装与运行:使用上述命令安装与运行程序。
\n
"
\
msg
=
"1. 安装与运行:使用上述命令安装与运行程序。
\n
"
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录