Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
d0ecff1b
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看板
未验证
提交
d0ecff1b
编写于
1月 19, 2021
作者:
L
littletomatodonkey
提交者:
GitHub
1月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix save distillation model (#567)
上级
0e6fe6f1
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
18 addition
and
22 deletion
+18
-22
ppcls/utils/save_load.py
ppcls/utils/save_load.py
+18
-22
未找到文件。
ppcls/utils/save_load.py
浏览文件 @
d0ecff1b
...
...
@@ -73,13 +73,13 @@ def load_dygraph_pretrain(model, path=None, load_static_weights=False):
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
))
if
not
isinstance
(
pretrained_model
,
list
):
pretrained_model
=
[
pretrained_model
]
if
not
isinstance
(
load_static_weights
,
list
):
load_static_weights
=
[
load_static_weights
]
teacher
=
model
.
teacher
if
hasattr
(
model
,
"teacher"
)
else
model
.
_layers
.
teacher
student
=
model
.
student
if
hasattr
(
model
,
...
...
@@ -88,16 +88,16 @@ def load_distillation_model(model, pretrained_model, load_static_weights):
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"
))
logger
.
info
(
"Finish initing teacher model from {}"
.
format
(
pretrained_model
))
# load student model
if
len
(
pretrained_model
)
>=
2
:
load_dygraph_pretrain
(
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"
))
logger
.
info
(
"Finish initing student model from {}"
.
format
(
pretrained_model
))
def
init_model
(
config
,
net
,
optimizer
=
None
):
...
...
@@ -123,11 +123,7 @@ 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
isinstance
(
pretrained_model
,
list
):
# load distillation pretrained model
if
not
isinstance
(
load_static_weights
,
list
):
load_static_weights
=
[
load_static_weights
]
*
len
(
pretrained_model
)
if
use_distillation
:
load_distillation_model
(
net
,
pretrained_model
,
load_static_weights
)
else
:
# common load
load_dygraph_pretrain
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录