Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
0b9acb49
P
Paddle
项目概览
OPTHREE
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0b9acb49
编写于
7月 19, 2019
作者:
T
tangwei12
提交者:
GitHub
7月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add check of executor (#17986)
* add check of executor, test=develop
上级
ec1000cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
2 deletion
+41
-2
python/paddle/fluid/io.py
python/paddle/fluid/io.py
+9
-2
python/paddle/fluid/tests/unittests/test_inference_model_io.py
...n/paddle/fluid/tests/unittests/test_inference_model_io.py
+32
-0
未找到文件。
python/paddle/fluid/io.py
浏览文件 @
0b9acb49
...
...
@@ -25,6 +25,7 @@ from paddle.fluid import layers
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.evaluator
import
Evaluator
from
paddle.fluid.framework
import
Program
,
Parameter
,
default_main_program
,
default_startup_program
,
Variable
,
program_guard
from
paddle.fluid.compiler
import
CompiledProgram
from
paddle.fluid.log_helper
import
get_logger
from
.
import
reader
from
.reader
import
*
...
...
@@ -187,6 +188,7 @@ def save_vars(executor,
# saved in the same file named 'var_file' in the path "./my_paddle_vars".
"""
save_dirname
=
os
.
path
.
normpath
(
dirname
)
if
vars
is
None
:
if
main_program
is
None
:
main_program
=
default_main_program
()
...
...
@@ -438,7 +440,7 @@ def _save_distributed_persistables(executor, dirname, main_program):
return
is_valid
if
not
isinstance
(
main_program
,
Program
):
raise
Valu
eError
(
"'main_program' should be an instance of Program."
)
raise
Typ
eError
(
"'main_program' should be an instance of Program."
)
if
not
main_program
.
_is_distributed
:
raise
ValueError
(
...
...
@@ -609,6 +611,7 @@ def load_vars(executor,
# been saved in the same file named 'var_file' in the path "./my_paddle_vars".
"""
load_dirname
=
os
.
path
.
normpath
(
dirname
)
if
vars
is
None
:
if
main_program
is
None
:
main_program
=
default_main_program
()
...
...
@@ -627,6 +630,7 @@ def load_vars(executor,
if
main_program
is
None
:
main_program
=
default_main_program
()
if
not
isinstance
(
main_program
,
Program
):
raise
TypeError
(
"program should be as Program type or None"
)
...
...
@@ -863,7 +867,7 @@ def _load_distributed_persistables(executor, dirname, main_program=None):
executor
.
run
(
load_prog
)
if
not
isinstance
(
main_program
,
Program
):
raise
Valu
eError
(
"'main_program' should be an instance of Program."
)
raise
Typ
eError
(
"'main_program' should be an instance of Program."
)
if
not
main_program
.
_is_distributed
:
raise
ValueError
(
...
...
@@ -1027,6 +1031,9 @@ def save_inference_model(dirname,
we save the original program as inference model."
,
RuntimeWarning
)
elif
not
isinstance
(
main_program
,
Program
):
raise
TypeError
(
"program should be as Program type or None"
)
# fix the bug that the activation op's output as target will be pruned.
# will affect the inference performance.
# TODO(Superjomn) add an IR pass to remove 1-scale op.
...
...
python/paddle/fluid/tests/unittests/test_inference_model_io.py
浏览文件 @
0b9acb49
...
...
@@ -23,6 +23,7 @@ import paddle.fluid.core as core
import
paddle.fluid.executor
as
executor
import
paddle.fluid.layers
as
layers
import
paddle.fluid.optimizer
as
optimizer
from
paddle.fluid.compiler
import
CompiledProgram
from
paddle.fluid.framework
import
Program
,
program_guard
from
paddle.fluid.io
import
save_inference_model
,
load_inference_model
from
paddle.fluid.transpiler
import
memory_optimize
...
...
@@ -114,5 +115,36 @@ class TestSaveInferenceModel(unittest.TestCase):
save_inference_model
(
MODEL_DIR
,
[
"x"
,
"y"
],
[
avg_cost
],
exe
,
program
)
class
TestInstance
(
unittest
.
TestCase
):
def
test_save_inference_model
(
self
):
MODEL_DIR
=
"./tmp/inference_model3"
init_program
=
Program
()
program
=
Program
()
# fake program without feed/fetch
with
program_guard
(
program
,
init_program
):
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
2
],
dtype
=
'float32'
)
y
=
layers
.
data
(
name
=
'y'
,
shape
=
[
1
],
dtype
=
'float32'
)
y_predict
=
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
cost
=
layers
.
square_error_cost
(
input
=
y_predict
,
label
=
y
)
avg_cost
=
layers
.
mean
(
cost
)
place
=
core
.
CPUPlace
()
exe
=
executor
.
Executor
(
place
)
exe
.
run
(
init_program
,
feed
=
{},
fetch_list
=
[])
# will print warning message
cp_prog
=
CompiledProgram
(
program
).
with_data_parallel
(
loss_name
=
avg_cost
.
name
)
self
.
assertRaises
(
TypeError
,
save_inference_model
,
[
MODEL_DIR
,
[
"x"
,
"y"
],
[
avg_cost
],
exe
,
cp_prog
])
self
.
assertRaises
(
TypeError
,
save_inference_model
,
[
MODEL_DIR
,
[
"x"
,
"y"
],
[
avg_cost
],
[],
cp_prog
])
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录