Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_38905368
tensorflow
提交
df8e306d
T
tensorflow
项目概览
qq_38905368
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
df8e306d
编写于
10月 31, 2016
作者:
S
Sukriti Ramesh
提交者:
TensorFlower Gardener
10月 31, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for clear devices in SavedModel.
Change: 137772478
上级
f6d70256
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
42 addition
and
3 deletion
+42
-3
tensorflow/python/saved_model/builder.py
tensorflow/python/saved_model/builder.py
+19
-3
tensorflow/python/saved_model/saved_model_test.py
tensorflow/python/saved_model/saved_model_test.py
+23
-0
未找到文件。
tensorflow/python/saved_model/builder.py
浏览文件 @
df8e306d
...
...
@@ -249,11 +249,18 @@ class SavedModelBuilder(object):
proto_meta_graph_def
=
self
.
_saved_model
.
meta_graphs
.
add
()
proto_meta_graph_def
.
CopyFrom
(
meta_graph_def
)
def
_maybe_clear_devices
(
self
,
clear_devices
):
if
not
clear_devices
:
return
for
node
in
ops
.
get_default_graph
().
as_graph_def
().
node
:
node
.
device
=
""
def
add_meta_graph
(
self
,
tags
,
signature_def_map
=
None
,
assets_collection
=
None
,
legacy_init_op
=
None
):
legacy_init_op
=
None
,
clear_devices
=
False
):
"""Adds the current meta graph to the SavedModel.
Creates a Saver in the current scope and uses the Saver to export the meta
...
...
@@ -269,6 +276,8 @@ class SavedModelBuilder(object):
the first meta graph in the SavedModel.
legacy_init_op: Op or group of ops to execute after the restore op upon a
load.
clear_devices: Set to true if the device info on the default graph should
be cleared.
Raises:
AssertionError: If the variables for the SavedModel have not been saved
...
...
@@ -279,6 +288,8 @@ class SavedModelBuilder(object):
"Variables and assets have not been saved yet. "
"Please invoke `add_meta_graph_and_variables()` first."
)
self
.
_maybe_clear_devices
(
clear_devices
)
# Save asset files and write them to disk, if any.
self
.
_save_and_write_assets
(
assets_collection
)
...
...
@@ -300,7 +311,8 @@ class SavedModelBuilder(object):
tags
,
signature_def_map
=
None
,
assets_collection
=
None
,
legacy_init_op
=
None
):
legacy_init_op
=
None
,
clear_devices
=
False
):
"""Adds the current meta graph to the SavedModel and saves variables.
Creates a Saver to save the variables from the provided session. Exports the
...
...
@@ -318,11 +330,15 @@ class SavedModelBuilder(object):
assets_collection: Assets collection to be saved with SavedModel.
legacy_init_op: Op or group of ops to execute after the restore op upon a
load.
clear_devices: Set to true if the device info on the default graph should
be cleared.
"""
if
self
.
_has_saved_variables
:
raise
AssertionError
(
"Variables and assets have already been saved. "
"Please invoke `add_meta_graph()` instead."
)
self
.
_maybe_clear_devices
(
clear_devices
)
# Save asset files and write them to disk, if any.
self
.
_save_and_write_assets
(
assets_collection
)
...
...
tensorflow/python/saved_model/saved_model_test.py
浏览文件 @
df8e306d
...
...
@@ -553,6 +553,29 @@ class SavedModelTest(tf.test.TestCase):
tf
.
get_collection
(
"init_op"
)[
0
].
run
()
self
.
assertEqual
(
3
,
tf
.
get_collection
(
"v"
)[
2
].
eval
())
def
testClearDevices
(
self
):
export_dir
=
os
.
path
.
join
(
tf
.
test
.
get_temp_dir
(),
"test_clear_devices"
)
builder
=
saved_model_builder
.
SavedModelBuilder
(
export_dir
)
# Specify a device and save a variable.
tf
.
reset_default_graph
()
with
tf
.
Session
(
target
=
""
,
config
=
config_pb2
.
ConfigProto
(
device_count
=
{
"CPU"
:
2
}))
as
sess
:
with
sess
.
graph
.
device
(
"/cpu:0"
):
self
.
_init_and_validate_variable
(
sess
,
"v"
,
42
)
builder
.
add_meta_graph_and_variables
(
sess
,
[
tag_constants
.
TRAINING
],
clear_devices
=
True
)
# Save the SavedModel to disk.
builder
.
save
()
# Restore the graph with a single predefined tag whose variables were saved
# without any device information.
with
self
.
test_session
(
graph
=
tf
.
Graph
())
as
sess
:
loader
.
load
(
sess
,
[
tag_constants
.
TRAINING
],
export_dir
)
self
.
assertEqual
(
42
,
tf
.
get_collection
(
tf
.
GraphKeys
.
VARIABLES
)[
0
].
eval
())
if
__name__
==
"__main__"
:
tf
.
test
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录