Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c0b1f2ef
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c0b1f2ef
编写于
7月 22, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
7月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support intermediate outputs on python 2.7 platform (#1764)
上级
db5f1aa5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
10 deletion
+32
-10
tools/python/fluidtools/run.py
tools/python/fluidtools/run.py
+32
-10
未找到文件。
tools/python/fluidtools/run.py
浏览文件 @
c0b1f2ef
...
...
@@ -160,7 +160,10 @@ def load_feed_kv():
data
=
data
.
reshape
(
feed_shape
).
astype
(
"float32"
)
if
is_lod
:
data
=
data
.
reshape
((
1
,
*
feed_shape
)).
astype
(
"float32"
)
data_shape
=
[
1
]
for
dim
in
feed_shape
:
data_shape
.
append
(
dim
)
data
=
data
.
reshape
(
data_shape
).
astype
(
"float32"
)
tensor
=
fluid
.
LoDTensor
()
seq_lens
=
[
len
(
seq
)
for
seq
in
data
]
cur_len
=
0
...
...
@@ -203,17 +206,32 @@ def get_feed_var_shape(var_name):
# return [1, 3, 224, 224]
return
get_var_shape
(
var_name
)
persistable_cache
=
[]
# 所有var,全部变成持久化
def
force_all_vars_to_persistable
():
global
persistable_cache
for
var_name
in
vars
.
keys
():
var_name
=
str
(
var_name
)
v
=
fluid
.
framework
.
_get_var
(
var_name
,
prog
)
persistable
=
v
.
persistable
if
not
persistable
:
persistable_cache
.
append
(
var_name
)
v
.
persistable
=
True
# 恢复持久化属性
def
restore_all_vars_persistable
():
global
persistable_cache
for
var_name
in
vars
.
keys
():
var_name
=
str
(
var_name
)
v
=
fluid
.
framework
.
_get_var
(
var_name
,
prog
)
persistable
=
v
.
persistable
if
var_name
in
persistable_cache
:
v
.
persistable
=
False
persistable_cache
=
[]
# 获取var的数据
def
get_var_data
(
var_name
,
feed_kv
=
None
):
# 强制var为可持久化
v
=
fluid
.
framework
.
_get_var
(
var_name
,
prog
)
persistable
=
v
.
persistable
if
not
persistable
:
v
.
persistable
=
True
# outputs = run_model(feed_kv=feed_kv)
output
=
np
.
array
(
fluid
.
global_scope
().
find_var
(
var_name
).
get_tensor
())
# 恢复var的可持久化属性
v
.
persistable
=
persistable
output
=
np
.
array
(
fluid
.
global_scope
().
var
(
var_name
).
get_tensor
())
return
output
output_var_cache
=
{}
...
...
@@ -223,6 +241,7 @@ def tensor_sample(tensor):
else
:
step
=
math
.
floor
(
len
(
tensor
)
/
sample_num
)
step
=
max
(
step
,
1
)
step
=
int
(
step
)
sample
=
[]
for
i
in
range
(
0
,
len
(
tensor
),
step
):
sample
.
append
(
tensor
[
i
])
...
...
@@ -231,6 +250,8 @@ def tensor_sample(tensor):
op_cache
=
{}
# 获取每层输出的数据
def
save_all_op_output
(
feed_kv
=
None
):
force_all_vars_to_persistable
()
outputs
=
run_model
(
feed_kv
=
feed_kv
)
if
not
os
.
path
.
exists
(
output_path
):
os
.
mkdir
(
output_path
)
ops
=
prog
.
current_block
().
ops
...
...
@@ -281,6 +302,7 @@ def save_all_op_output(feed_kv=None):
except
:
pass
pp_green
(
"all the op outputs are saved into directory 【{}】"
.
format
(
output_path
),
1
)
restore_all_vars_persistable
()
ops
=
prog
.
current_block
().
ops
vars
=
prog
.
current_block
().
vars
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录