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
92ad41ce
Unverified
Commit
92ad41ce
authored
Dec 05, 2024
by
Xiaomeng Zhao
Committed by
GitHub
Dec 05, 2024
Browse files
Merge pull request #1193 from myhloli/dev
perf(model): add threading lock for OCR model initialization
parents
41b9cbcd
04478095
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
magic_pdf/model/sub_modules/model_init.py
magic_pdf/model/sub_modules/model_init.py
+10
-2
No files found.
magic_pdf/model/sub_modules/model_init.py
View file @
92ad41ce
...
@@ -82,9 +82,12 @@ def ocr_model_init(show_log: bool = False,
...
@@ -82,9 +82,12 @@ def ocr_model_init(show_log: bool = False,
return
model
return
model
from
threading
import
Lock
class
AtomModelSingleton
:
class
AtomModelSingleton
:
_instance
=
None
_instance
=
None
_models
=
{}
_models
=
{}
_lock
=
Lock
()
def
__new__
(
cls
,
*
args
,
**
kwargs
):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
if
cls
.
_instance
is
None
:
if
cls
.
_instance
is
None
:
...
@@ -95,8 +98,13 @@ class AtomModelSingleton:
...
@@ -95,8 +98,13 @@ class AtomModelSingleton:
lang
=
kwargs
.
get
(
'lang'
,
None
)
lang
=
kwargs
.
get
(
'lang'
,
None
)
layout_model_name
=
kwargs
.
get
(
'layout_model_name'
,
None
)
layout_model_name
=
kwargs
.
get
(
'layout_model_name'
,
None
)
key
=
(
atom_model_name
,
layout_model_name
,
lang
)
key
=
(
atom_model_name
,
layout_model_name
,
lang
)
if
key
not
in
self
.
_models
:
if
atom_model_name
==
AtomicModel
.
OCR
:
self
.
_models
[
key
]
=
atom_model_init
(
model_name
=
atom_model_name
,
**
kwargs
)
with
self
.
_lock
:
if
key
not
in
self
.
_models
:
self
.
_models
[
key
]
=
atom_model_init
(
model_name
=
atom_model_name
,
**
kwargs
)
else
:
if
key
not
in
self
.
_models
:
self
.
_models
[
key
]
=
atom_model_init
(
model_name
=
atom_model_name
,
**
kwargs
)
return
self
.
_models
[
key
]
return
self
.
_models
[
key
]
...
...
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