Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
81506640
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看板
提交
81506640
编写于
12月 05, 2019
作者:
B
baiyfbupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix demo details
上级
fff7c57b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
31 deletion
+28
-31
demo/distillation/distillation_demo.py
demo/distillation/distillation_demo.py
+28
-31
未找到文件。
demo/distillation/distillation_demo.py
浏览文件 @
81506640
...
...
@@ -140,43 +140,40 @@ def compress(args):
# define teacher program
teacher_program
=
fluid
.
Program
()
t_startup
=
fluid
.
Program
()
teacher_scope
=
fluid
.
Scope
()
with
fluid
.
scope_guard
(
teacher_scope
):
with
fluid
.
program_guard
(
teacher_program
,
t_startup
):
with
fluid
.
unique_name
.
guard
():
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
predict
=
teacher_model
.
net
(
image
,
class_dim
=
class_dim
)
#print("="*50+"teacher_model_params"+"="*50)
#for v in teacher_program.list_vars():
# print(v.name, v.shape)
exe
.
run
(
t_startup
)
_download
(
'http://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_pretrained.tar'
,
'.'
)
_decompress
(
'./ResNet50_pretrained.tar'
)
assert
args
.
teacher_pretrained_model
and
os
.
path
.
exists
(
args
.
teacher_pretrained_model
),
"teacher_pretrained_model should be set when teacher_model is not None."
def
if_exist
(
var
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
teacher_pretrained_model
,
var
.
name
)
)
and
var
.
name
!=
'fc_0.w_0'
and
var
.
name
!=
'fc_0.b_0'
fluid
.
io
.
load_vars
(
exe
,
args
.
teacher_pretrained_model
,
main_program
=
teacher_program
,
predicate
=
if_exist
)
with
fluid
.
program_guard
(
teacher_program
,
t_startup
):
with
fluid
.
unique_name
.
guard
():
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
predict
=
teacher_model
.
net
(
image
,
class_dim
=
class_dim
)
#print("="*50+"teacher_model_params"+"="*50)
#for v in teacher_program.list_vars():
# print(v.name, v.shape)
exe
.
run
(
t_startup
)
_download
(
'http://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_pretrained.tar'
,
'.'
)
_decompress
(
'./ResNet50_pretrained.tar'
)
assert
args
.
teacher_pretrained_model
and
os
.
path
.
exists
(
args
.
teacher_pretrained_model
),
"teacher_pretrained_model should be set when teacher_model is not None."
def
if_exist
(
var
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
teacher_pretrained_model
,
var
.
name
)
)
and
var
.
name
!=
'fc_0.w_0'
and
var
.
name
!=
'fc_0.b_0'
fluid
.
io
.
load_vars
(
exe
,
args
.
teacher_pretrained_model
,
main_program
=
teacher_program
,
predicate
=
if_exist
)
data_name_map
=
{
'image'
:
'image'
}
main
=
merge
(
teacher_program
,
student_program
,
data_name_map
,
place
,
teacher_scope
=
teacher_scope
)
place
)
with
fluid
.
program_guard
(
main
,
s_startup
):
l2_loss_v
=
l2_loss
(
"teacher_fc_0.tmp_0"
,
"fc_0.tmp_0"
,
main
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录