Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
0a3a31dc
Unverified
Commit
0a3a31dc
authored
Aug 07, 2024
by
Xiaomeng Zhao
Committed by
GitHub
Aug 07, 2024
Browse files
Merge pull request #350 from papayalove/master
feat: add table recognition success detect
parents
c7067c85
a38c2a88
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
magic_pdf/libs/Constants.py
magic_pdf/libs/Constants.py
+4
-1
magic_pdf/model/pdf_extract_kit.py
magic_pdf/model/pdf_extract_kit.py
+11
-4
No files found.
magic_pdf/libs/Constants.py
View file @
0a3a31dc
...
@@ -9,3 +9,6 @@ block维度自定义字段
...
@@ -9,3 +9,6 @@ block维度自定义字段
"""
"""
# block中lines是否被删除
# block中lines是否被删除
LINES_DELETED
=
"lines_deleted"
LINES_DELETED
=
"lines_deleted"
# table recognition max time default value
TABLE_MAX_TIME_VALUE
=
400
\ No newline at end of file
magic_pdf/model/pdf_extract_kit.py
View file @
0a3a31dc
...
@@ -2,6 +2,7 @@ from loguru import logger
...
@@ -2,6 +2,7 @@ from loguru import logger
import
os
import
os
import
time
import
time
from
magic_pdf.libs.Constants
import
TABLE_MAX_TIME_VALUE
os
.
environ
[
'NO_ALBUMENTATIONS_UPDATE'
]
=
'1'
# 禁止albumentations检查更新
os
.
environ
[
'NO_ALBUMENTATIONS_UPDATE'
]
=
'1'
# 禁止albumentations检查更新
try
:
try
:
...
@@ -105,6 +106,7 @@ class CustomPEKModel:
...
@@ -105,6 +106,7 @@ class CustomPEKModel:
self
.
apply_formula
=
kwargs
.
get
(
"apply_formula"
,
self
.
configs
[
"config"
][
"formula"
])
self
.
apply_formula
=
kwargs
.
get
(
"apply_formula"
,
self
.
configs
[
"config"
][
"formula"
])
self
.
table_config
=
kwargs
.
get
(
"table_config"
,
self
.
configs
[
"config"
][
"table_config"
])
self
.
table_config
=
kwargs
.
get
(
"table_config"
,
self
.
configs
[
"config"
][
"table_config"
])
self
.
apply_table
=
self
.
table_config
.
get
(
"is_table_recog_enable"
,
False
)
self
.
apply_table
=
self
.
table_config
.
get
(
"is_table_recog_enable"
,
False
)
self
.
table_max_time
=
self
.
table_config
.
get
(
"max_time"
,
TABLE_MAX_TIME_VALUE
)
self
.
apply_ocr
=
ocr
self
.
apply_ocr
=
ocr
logger
.
info
(
logger
.
info
(
"DocAnalysis init, this may take some times. apply_layout: {}, apply_formula: {}, apply_ocr: {}, apply_table: {}"
.
format
(
"DocAnalysis init, this may take some times. apply_layout: {}, apply_formula: {}, apply_ocr: {}, apply_table: {}"
.
format
(
...
@@ -141,9 +143,8 @@ class CustomPEKModel:
...
@@ -141,9 +143,8 @@ class CustomPEKModel:
# init structeqtable
# init structeqtable
if
self
.
apply_table
:
if
self
.
apply_table
:
max_time
=
self
.
table_config
.
get
(
"max_time"
,
400
)
self
.
table_model
=
table_model_init
(
str
(
os
.
path
.
join
(
models_dir
,
self
.
configs
[
"weights"
][
"table"
])),
self
.
table_model
=
table_model_init
(
str
(
os
.
path
.
join
(
models_dir
,
self
.
configs
[
"weights"
][
"table"
])),
max_time
=
max_time
,
_device_
=
self
.
device
)
max_time
=
self
.
table_
max_time
,
_device_
=
self
.
device
)
logger
.
info
(
'DocAnalysis init done!'
)
logger
.
info
(
'DocAnalysis init done!'
)
def
__call__
(
self
,
image
):
def
__call__
(
self
,
image
):
...
@@ -290,6 +291,12 @@ class CustomPEKModel:
...
@@ -290,6 +291,12 @@ class CustomPEKModel:
end_time
=
time
.
time
()
end_time
=
time
.
time
()
run_time
=
end_time
-
start_time
run_time
=
end_time
-
start_time
logger
.
info
(
f
"------------table recognition processing ends within
{
run_time
}
s-----"
)
logger
.
info
(
f
"------------table recognition processing ends within
{
run_time
}
s-----"
)
if
run_time
>
self
.
table_max_time
:
logger
.
warning
(
f
"------------table recognition processing exceeds max time
{
self
.
table_max_time
}
s----------"
)
# 判断是否返回正常
if
latex_code
and
latex_code
.
strip
().
endswith
(
'end{tabular}'
):
layout
[
"latex"
]
=
latex_code
layout
[
"latex"
]
=
latex_code
else
:
print
(
latex_code
)
logger
.
warning
(
f
"------------table recognition processing fails----------"
)
return
layout_res
return
layout_res
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment