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
paddle_dbnet
Commits
8ffa50fe
Commit
8ffa50fe
authored
Nov 26, 2021
by
WenmuZhou
Browse files
opt load model
parent
134e7070
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
ppocr/utils/save_load.py
ppocr/utils/save_load.py
+10
-4
No files found.
ppocr/utils/save_load.py
View file @
8ffa50fe
...
...
@@ -57,7 +57,7 @@ def load_model(config, model, optimizer=None):
if
checkpoints
.
endswith
(
'.pdparams'
):
checkpoints
=
checkpoints
.
replace
(
'.pdparams'
,
''
)
assert
os
.
path
.
exists
(
checkpoints
+
".pdparams"
),
\
"The {}.pdparams
doe
s not exists!"
.
format
(
checkpoints
)
"The {}.pdparams
i
s not exists!"
.
format
(
checkpoints
)
# load params from trained model
params
=
paddle
.
load
(
checkpoints
+
'.pdparams'
)
...
...
@@ -67,6 +67,7 @@ def load_model(config, model, optimizer=None):
if
key
not
in
params
:
logger
.
warning
(
"{} not in loaded params {} !"
.
format
(
key
,
params
.
keys
()))
continue
pre_value
=
params
[
key
]
if
list
(
value
.
shape
)
==
list
(
pre_value
.
shape
):
new_state_dict
[
key
]
=
pre_value
...
...
@@ -76,9 +77,14 @@ def load_model(config, model, optimizer=None):
format
(
key
,
value
.
shape
,
pre_value
.
shape
))
model
.
set_state_dict
(
new_state_dict
)
optim_dict
=
paddle
.
load
(
checkpoints
+
'.pdopt'
)
if
optimizer
is
not
None
:
optimizer
.
set_state_dict
(
optim_dict
)
if
os
.
path
.
exists
(
checkpoints
+
'.pdopt'
):
optim_dict
=
paddle
.
load
(
checkpoints
+
'.pdopt'
)
optimizer
.
set_state_dict
(
optim_dict
)
else
:
logger
.
warning
(
"{}.pdopt is not exists, params of optimizer is not loaded"
.
format
(
checkpoints
))
if
os
.
path
.
exists
(
checkpoints
+
'.states'
):
with
open
(
checkpoints
+
'.states'
,
'rb'
)
as
f
:
...
...
@@ -100,7 +106,7 @@ def load_pretrained_params(model, path):
if
path
.
endswith
(
'.pdparams'
):
path
=
path
.
replace
(
'.pdparams'
,
''
)
assert
os
.
path
.
exists
(
path
+
".pdparams"
),
\
"The {}.pdparams
doe
s not exists!"
.
format
(
path
)
"The {}.pdparams
i
s not exists!"
.
format
(
path
)
params
=
paddle
.
load
(
path
+
'.pdparams'
)
state_dict
=
model
.
state_dict
()
...
...
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