Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
092ab674
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看板
提交
092ab674
编写于
1月 17, 2020
作者:
L
LielinJiang
提交者:
whs
1月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix save load bug (#47)
上级
d95da67b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
13 deletion
+11
-13
paddleslim/prune/io.py
paddleslim/prune/io.py
+11
-13
未找到文件。
paddleslim/prune/io.py
浏览文件 @
092ab674
...
...
@@ -10,11 +10,11 @@ __all__ = ["save_model", "load_model"]
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
PARAMS_FILE
=
"__params__"
SHAPES_FILE
=
"__shapes__"
_
PARAMS_FILE
=
"__params__"
_
SHAPES_FILE
=
"__shapes__"
def
save_model
(
graph
,
dirname
):
def
save_model
(
exe
,
graph
,
dirname
):
"""
Save weights of model and information of shapes into filesystem.
...
...
@@ -24,24 +24,24 @@ def save_model(graph, dirname):
"""
assert
graph
is
not
None
and
dirname
is
not
None
graph
=
GraphWrapper
(
graph
)
if
isinstance
(
graph
,
Program
)
else
graph
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
fluid
.
io
.
save_params
(
executor
=
exe
,
dirname
=
dirname
,
main_program
=
graph
.
program
,
filename
=
PARAMS_FILE
)
weights_file
=
os
.
path
.
join
(
dirname
,
PARAMS_FILE
)
filename
=
_
PARAMS_FILE
)
weights_file
=
os
.
path
.
join
(
dirname
,
_
PARAMS_FILE
)
_logger
.
info
(
"Save model weights into {}"
.
format
(
weights_file
))
shapes
=
{}
for
var
in
graph
.
all_parameters
():
shapes
[
var
.
name
()]
=
var
.
shape
()
SHAPES_FILE
=
os
.
path
.
join
(
dirname
,
SHAPES_FILE
)
SHAPES_FILE
=
os
.
path
.
join
(
dirname
,
_
SHAPES_FILE
)
with
open
(
SHAPES_FILE
,
"w"
)
as
f
:
json
.
dump
(
shapes
,
f
)
_logger
.
info
(
"Save shapes of weights into {}"
.
format
(
SHAPES_FILE
))
def
load_model
(
graph
,
dirname
):
def
load_model
(
exe
,
graph
,
dirname
):
"""
Load weights of model and information of shapes from filesystem.
...
...
@@ -51,9 +51,8 @@ def load_model(graph, dirname):
"""
assert
graph
is
not
None
and
dirname
is
not
None
graph
=
GraphWrapper
(
graph
)
if
isinstance
(
graph
,
Program
)
else
graph
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
SHAPES_FILE
=
os
.
path
.
join
(
dirname
,
SHAPES_FILE
)
SHAPES_FILE
=
os
.
path
.
join
(
dirname
,
_
SHAPES_FILE
)
_logger
.
info
(
"Load shapes of weights from {}"
.
format
(
SHAPES_FILE
))
with
open
(
SHAPES_FILE
,
"r"
)
as
f
:
shapes
=
json
.
load
(
f
)
...
...
@@ -62,13 +61,12 @@ def load_model(graph, dirname):
_logger
.
info
(
"Load shapes of weights from {}"
.
format
(
SHAPES_FILE
))
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
fluid
.
io
.
load_params
(
executor
=
exe
,
dirname
=
dirname
,
main_program
=
graph
.
program
,
filename
=
PARAMS_FILE
)
filename
=
_
PARAMS_FILE
)
graph
.
update_groups_of_conv
()
graph
.
infer_shape
()
_logger
.
info
(
"Load weights from {}"
.
format
(
os
.
path
.
join
(
dirname
,
PARAMS_FILE
)))
os
.
path
.
join
(
dirname
,
_
PARAMS_FILE
)))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录