Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
927a7887
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看板
提交
927a7887
编写于
9月 03, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix distillation load
上级
4f5e494a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
12 deletion
+27
-12
ppcls/utils/save_load.py
ppcls/utils/save_load.py
+27
-12
未找到文件。
ppcls/utils/save_load.py
浏览文件 @
927a7887
...
...
@@ -48,7 +48,7 @@ def _mkdir_if_not_exist(path):
def
load_dygraph_pretrain
(
model
,
path
=
None
,
load_static_weights
=
False
,
):
load_static_weights
=
False
):
if
not
(
os
.
path
.
isdir
(
path
)
or
os
.
path
.
exists
(
path
+
'.pdparams'
)):
raise
ValueError
(
"Model pretrain path {} does not "
"exists."
.
format
(
path
))
...
...
@@ -72,6 +72,26 @@ def load_dygraph_pretrain(
return
def
load_distillation_model
(
model
,
pretrained_model
,
load_static_weights
):
logger
.
info
(
"In distillation mode, teacher model will be "
"loaded firstly before student model."
)
assert
len
(
pretrained_model
)
==
2
,
"pretrained_model length should be 2 but got {}"
.
format
(
len
(
pretrained_model
))
assert
len
(
load_static_weights
)
==
2
,
"load_static_weights length should be 2 but got {}"
.
format
(
len
(
load_static_weights
))
load_dygraph_pretrain
(
model
.
teacher
,
path
=
pretrained_model
[
0
],
load_static_weights
=
load_static_weights
[
0
])
logger
.
info
(
logger
.
coloring
(
"Finish initing teacher model from {}"
.
format
(
pretrained_model
),
"HEADER"
))
load_dygraph_pretrain
(
model
.
student
,
path
=
pretrained_model
[
1
],
load_static_weights
=
load_static_weights
[
1
])
logger
.
info
(
logger
.
coloring
(
"Finish initing student model from {}"
.
format
(
pretrained_model
),
"HEADER"
))
def
init_model
(
config
,
net
,
optimizer
=
None
):
"""
load model from checkpoint or pretrained_model
...
...
@@ -94,18 +114,13 @@ def init_model(config, net, optimizer=None):
load_static_weights
=
config
.
get
(
'load_static_weights'
,
False
)
use_distillation
=
config
.
get
(
'use_distillation'
,
False
)
if
pretrained_model
:
if
not
isinstance
(
pretrained_model
,
list
):
pretrained_model
=
[
pretrained_model
]
if
not
isinstance
(
load_static_weights
,
list
):
load_static_weights
=
[
load_static_weights
]
*
len
(
pretrained_model
)
for
idx
,
pretrained
in
enumerate
(
pretrained_model
):
load_static
=
load_static_weights
[
idx
]
model
=
net
if
use_distillation
and
not
load_static
:
model
=
net
.
teacher
if
isinstance
(
pretrained_model
,
list
):
# load distillation pretrained model
if
not
isinstance
(
load_static_weights
,
list
):
load_static_weights
=
[
load_static_weights
]
*
len
(
pretrained_model
)
load_distillation_model
(
net
,
pretrained_model
,
load_static_weights
)
else
:
# common load
load_dygraph_pretrain
(
model
,
path
=
pretrained
,
load_static_weights
=
load_static
)
net
,
path
=
pretrained_model
,
load_static_weights
=
load_static_weights
)
logger
.
info
(
logger
.
coloring
(
"Finish initing model from {}"
.
format
(
pretrained_model
),
"HEADER"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录