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
45e7fbd2
Commit
45e7fbd2
authored
Jul 12, 2024
by
myhloli
Browse files
feat(model-config): Unify all device selections through a single YAML file
parent
bc0f6932
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
7 deletions
+13
-7
magic_pdf/model/pdf_extract_kit.py
magic_pdf/model/pdf_extract_kit.py
+4
-3
magic_pdf/model/pek_sub_modules/layoutlmv3/model_init.py
magic_pdf/model/pek_sub_modules/layoutlmv3/model_init.py
+8
-3
magic_pdf/resources/model_config/layoutlmv3/layoutlmv3_base_inference.yaml
...es/model_config/layoutlmv3/layoutlmv3_base_inference.yaml
+1
-1
No files found.
magic_pdf/model/pdf_extract_kit.py
View file @
45e7fbd2
...
...
@@ -19,8 +19,8 @@ from magic_pdf.model.pek_sub_modules.post_process import get_croped_image, latex
from
magic_pdf.model.pek_sub_modules.self_modify
import
ModifiedPaddleOCR
def
layout_model_init
(
weight
,
config_file
):
model
=
Layoutlmv3_Predictor
(
weight
,
config_file
)
def
layout_model_init
(
weight
,
config_file
,
device
):
model
=
Layoutlmv3_Predictor
(
weight
,
config_file
,
device
)
return
model
...
...
@@ -89,7 +89,8 @@ class CustomPEKModel:
# 初始化layout模型
self
.
layout_model
=
layout_model_init
(
os
.
path
.
join
(
root_dir
,
self
.
configs
[
'weights'
][
'layout'
]),
os
.
path
.
join
(
model_config_dir
,
"layoutlmv3"
,
"layoutlmv3_base_inference.yaml"
)
os
.
path
.
join
(
model_config_dir
,
"layoutlmv3"
,
"layoutlmv3_base_inference.yaml"
),
device
=
self
.
device
)
# 初始化公式识别
if
self
.
apply_formula
:
...
...
magic_pdf/model/pek_sub_modules/layoutlmv3/model_init.py
View file @
45e7fbd2
...
...
@@ -61,16 +61,21 @@ def add_vit_config(cfg):
_C
.
SOLVER
.
GRADIENT_ACCUMULATION_STEPS
=
1
def
setup
(
args
):
def
setup
(
args
,
device
):
"""
Create configs and perform basic setups.
"""
cfg
=
get_cfg
()
# add_coat_config(cfg)
add_vit_config
(
cfg
)
cfg
.
merge_from_file
(
args
.
config_file
)
cfg
.
MODEL
.
ROI_HEADS
.
SCORE_THRESH_TEST
=
0.2
# set threshold for this model
cfg
.
merge_from_list
(
args
.
opts
)
# 使用统一的device配置
cfg
.
MODEL
.
DEVICE
=
device
cfg
.
freeze
()
default_setup
(
cfg
,
args
)
...
...
@@ -101,7 +106,7 @@ class DotDict(dict):
class
Layoutlmv3_Predictor
(
object
):
def
__init__
(
self
,
weights
,
config_file
):
def
__init__
(
self
,
weights
,
config_file
,
device
):
layout_args
=
{
"config_file"
:
config_file
,
"resume"
:
False
,
...
...
@@ -114,7 +119,7 @@ class Layoutlmv3_Predictor(object):
}
layout_args
=
DotDict
(
layout_args
)
cfg
=
setup
(
layout_args
)
cfg
=
setup
(
layout_args
,
device
)
self
.
mapping
=
[
"title"
,
"plain text"
,
"abandon"
,
"figure"
,
"figure_caption"
,
"table"
,
"table_caption"
,
"table_footnote"
,
"isolate_formula"
,
"formula_caption"
]
MetadataCatalog
.
get
(
cfg
.
DATASETS
.
TRAIN
[
0
]).
thing_classes
=
self
.
mapping
...
...
magic_pdf/resources/model_config/layoutlmv3/layoutlmv3_base_inference.yaml
View file @
45e7fbd2
...
...
@@ -69,7 +69,7 @@ MODEL:
FREEZE_AT
:
2
NAME
:
build_vit_fpn_backbone
CONFIG_PATH
:
'
'
DEVICE
:
c
p
u
DEVICE
:
cu
da
FPN
:
FUSE_TYPE
:
sum
IN_FEATURES
:
...
...
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