Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
ee02b6c4
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ee02b6c4
编写于
11月 21, 2019
作者:
Y
yangfukui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the name problem
上级
49a17a25
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
12 deletion
+14
-12
paddleslim/dist/single_distiller.py
paddleslim/dist/single_distiller.py
+14
-12
未找到文件。
paddleslim/dist/single_distiller.py
浏览文件 @
ee02b6c4
...
@@ -38,21 +38,25 @@ def merge(teacher_program,
...
@@ -38,21 +38,25 @@ def merge(teacher_program,
name_prefix(str): Name prefix added for all vars of the teacher program.
name_prefix(str): Name prefix added for all vars of the teacher program.
Return(Program): Merged program.
Return(Program): Merged program.
"""
"""
teacher_program
=
teacher_program
.
clone
(
for_test
=
True
)
teacher_program
=
teacher_program
.
clone
(
for_test
=
True
)
for
teacher_var
in
teacher_program
.
list_vars
():
for
teacher_var
in
teacher_program
.
list_vars
():
skip_rename
=
False
if
teacher_var
.
name
!=
'fetch'
and
teacher_var
.
name
!=
'feed'
:
if
teacher_var
.
name
!=
'fetch'
and
teacher_var
.
name
!=
'feed'
:
if
teacher_var
.
name
in
data_name_map
.
keys
():
if
teacher_var
.
name
in
data_name_map
.
keys
():
new_name
=
data_name_map
[
teacher_var
.
name
]
new_name
=
data_name_map
[
teacher_var
.
name
]
if
new_name
==
teacher_var
.
name
:
skip_rename
=
True
else
:
else
:
new_name
=
name_prefix
+
teacher_var
.
name
new_name
=
name_prefix
+
teacher_var
.
name
# scope var rename
if
not
skip_rename
:
scope_var
=
teacher_scope
.
var
(
teacher_var
.
name
).
get_tensor
()
# scope var rename
renamed_scope_var
=
teacher_scope
.
var
(
new_name
).
get_tensor
()
scope_var
=
teacher_scope
.
var
(
teacher_var
.
name
).
get_tensor
()
renamed_scope_var
.
set
(
np
.
array
(
scope_var
),
place
)
renamed_scope_var
=
teacher_scope
.
var
(
new_name
).
get_tensor
()
renamed_scope_var
.
set
(
np
.
array
(
scope_var
),
place
)
# program var rename
renamed_var
=
teacher_program
.
global_block
().
_rename_var
(
# program var rename
teacher_var
.
name
,
new_name
)
renamed_var
=
teacher_program
.
global_block
().
_rename_var
(
teacher_var
.
name
,
new_name
)
for
teacher_var
in
teacher_program
.
list_vars
():
for
teacher_var
in
teacher_program
.
list_vars
():
if
teacher_var
.
name
!=
'fetch'
and
teacher_var
.
name
!=
'feed'
:
if
teacher_var
.
name
!=
'fetch'
and
teacher_var
.
name
!=
'feed'
:
...
@@ -148,7 +152,6 @@ def soft_label_loss(teacher_var_name,
...
@@ -148,7 +152,6 @@ def soft_label_loss(teacher_var_name,
teacher_feature_map before softmax. default: 1.0
teacher_feature_map before softmax. default: 1.0
student_temperature(float): Temperature used to divide
student_temperature(float): Temperature used to divide
student_feature_map before softmax. default: 1.0
student_feature_map before softmax. default: 1.0
Return(Variable): l2 distiller loss.
Return(Variable): l2 distiller loss.
"""
"""
student_var
=
program
.
global_block
().
var
(
student_var_name
)
student_var
=
program
.
global_block
().
var
(
student_var_name
)
...
@@ -162,13 +165,12 @@ def soft_label_loss(teacher_var_name,
...
@@ -162,13 +165,12 @@ def soft_label_loss(teacher_var_name,
return
soft_label_loss
return
soft_label_loss
def
self_defined_
loss
(
program
,
loss_func
,
**
kwargs
):
def
loss
(
program
,
loss_func
,
**
kwargs
):
"""
"""
Combine variables from student model and teacher model by self defined loss.
Combine variables from student model and teacher model by self defined loss.
Args:
Args:
program(Program): The input distiller program.
program(Program): The input distiller program.
loss_func(function): The user self defined loss function.
loss_func(function): The user self defined loss function.
Return(Variable): self defined distiller loss.
Return(Variable): self defined distiller loss.
"""
"""
func_parameters
=
{}
func_parameters
=
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录