Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
3b93ffa0
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3b93ffa0
编写于
6月 22, 2020
作者:
D
dyning
提交者:
GitHub
6月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #167 from WuHaobo/dynamic
Polish Dynamic Graph
上级
b14207f3
0d3e2818
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
10 deletion
+29
-10
ppcls/utils/misc.py
ppcls/utils/misc.py
+1
-1
ppcls/utils/save_load.py
ppcls/utils/save_load.py
+28
-9
未找到文件。
ppcls/utils/misc.py
浏览文件 @
3b93ffa0
...
...
@@ -20,7 +20,7 @@ class AverageMeter(object):
Computes and stores the average and current value
"""
def
__init__
(
self
,
name
=
''
,
fmt
=
'f'
,
need_avg
=
Fals
e
):
def
__init__
(
self
,
name
=
''
,
fmt
=
'f'
,
need_avg
=
Tru
e
):
self
.
name
=
name
self
.
fmt
=
fmt
self
.
need_avg
=
need_avg
...
...
ppcls/utils/save_load.py
浏览文件 @
3b93ffa0
...
...
@@ -74,7 +74,9 @@ def load_params(exe, prog, path, ignore_params=None):
raise
ValueError
(
"Model pretrain path {} does not "
"exists."
.
format
(
path
))
logger
.
info
(
logger
.
coloring
(
'Loading parameters from {}...'
.
format
(
path
),
'HEADER'
))
logger
.
info
(
logger
.
coloring
(
'Loading parameters from {}...'
.
format
(
path
),
'HEADER'
))
ignore_set
=
set
()
state
=
_load_state
(
path
)
...
...
@@ -100,37 +102,54 @@ def load_params(exe, prog, path, ignore_params=None):
if
len
(
ignore_set
)
>
0
:
for
k
in
ignore_set
:
if
k
in
state
:
logger
.
warning
(
'variable {} is already excluded automatically'
.
format
(
k
))
logger
.
warning
(
'variable {} is already excluded automatically'
.
format
(
k
))
del
state
[
k
]
fluid
.
io
.
set_program_state
(
prog
,
state
)
def
init_model
(
config
,
program
,
exe
):
def
init_model
(
config
,
net
,
optimizer
):
"""
load model from checkpoint or pretrained_model
"""
checkpoints
=
config
.
get
(
'checkpoints'
)
if
checkpoints
:
fluid
.
load
(
program
,
checkpoints
,
exe
)
logger
.
info
(
logger
.
coloring
(
"Finish initing model from {}"
.
format
(
checkpoints
),
"HEADER"
))
assert
os
.
path
.
exists
(
checkpoints
+
".pdparams"
),
\
"Given dir {}.pdparams not exist."
.
format
(
checkpoints
)
assert
os
.
path
.
exists
(
checkpoints
+
".pdopt"
),
\
"Given dir {}.pdopt not exist."
.
format
(
checkpoints
)
para_dict
,
opti_dict
=
fluid
.
dygraph
.
load_dygraph
(
checkpoints
)
net
.
set_dict
(
para_dict
)
optimizer
.
set_dict
(
opti_dict
)
logger
.
info
(
logger
.
coloring
(
"Finish initing model from {}"
.
format
(
checkpoints
),
"HEADER"
))
return
pretrained_model
=
config
.
get
(
'pretrained_model'
)
if
pretrained_model
:
if
not
isinstance
(
pretrained_model
,
list
):
pretrained_model
=
[
pretrained_model
]
# TODO: load pretrained_model
raise
NotImplementedError
for
pretrain
in
pretrained_model
:
load_params
(
exe
,
program
,
pretrain
)
logger
.
info
(
logger
.
coloring
(
"Finish initing model from {}"
.
format
(
pretrained_model
),
"HEADER"
))
logger
.
info
(
logger
.
coloring
(
"Finish initing model from {}"
.
format
(
pretrained_model
),
"HEADER"
))
def
save_model
(
program
,
model_path
,
epoch_id
,
prefix
=
'ppcls'
):
def
save_model
(
net
,
optimizer
,
model_path
,
epoch_id
,
prefix
=
'ppcls'
):
"""
save model to the target path
"""
model_path
=
os
.
path
.
join
(
model_path
,
str
(
epoch_id
))
_mkdir_if_not_exist
(
model_path
)
model_prefix
=
os
.
path
.
join
(
model_path
,
prefix
)
fluid
.
save
(
program
,
model_prefix
)
logger
.
info
(
logger
.
coloring
(
"Already save model in {}"
.
format
(
model_path
),
"HEADER"
))
fluid
.
dygraph
.
save_dygraph
(
net
.
state_dict
(),
model_prefix
)
fluid
.
dygraph
.
save_dygraph
(
optimizer
.
state_dict
(),
model_prefix
)
logger
.
info
(
logger
.
coloring
(
"Already save model in {}"
.
format
(
model_path
),
"HEADER"
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录