Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_38905368
tensorflow
提交
3cf41b2e
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,体验更适合开发者的 AI 搜索 >>
提交
3cf41b2e
编写于
10月 04, 2017
作者:
A
A. Unique TensorFlower
提交者:
TensorFlower Gardener
10月 04, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test save/restore variable from graph_callable.
PiperOrigin-RevId: 171051237
上级
cf17ec96
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
0 deletion
+52
-0
tensorflow/contrib/eager/python/BUILD
tensorflow/contrib/eager/python/BUILD
+1
-0
tensorflow/contrib/eager/python/saver_test.py
tensorflow/contrib/eager/python/saver_test.py
+51
-0
未找到文件。
tensorflow/contrib/eager/python/BUILD
浏览文件 @
3cf41b2e
...
...
@@ -81,6 +81,7 @@ cuda_py_test(
"//tensorflow/python:array_ops"
,
"//tensorflow/python:client"
,
"//tensorflow/python:client_testlib"
,
"//tensorflow/python/eager:graph_callable"
,
"//tensorflow/python:platform_test"
,
"//tensorflow/python:variables"
,
],
...
...
tensorflow/contrib/eager/python/saver_test.py
浏览文件 @
3cf41b2e
...
...
@@ -21,10 +21,14 @@ import os
from
tensorflow.contrib.eager.python
import
saver
as
_saver
from
tensorflow.python.eager
import
context
from
tensorflow.python.eager
import
graph_callable
from
tensorflow.python.framework
import
dtypes
from
tensorflow.python.framework
import
errors
from
tensorflow.python.framework
import
ops
from
tensorflow.python.ops
import
array_ops
from
tensorflow.python.ops
import
init_ops
from
tensorflow.python.ops
import
resource_variable_ops
from
tensorflow.python.ops
import
variable_scope
from
tensorflow.python.platform
import
test
...
...
@@ -87,6 +91,53 @@ class SaverTest(test.TestCase):
with
_saver
.
restore_variables_on_create
(
ckpt_prefix
):
_
=
model
(
resource_variable_ops
.
ResourceVariable
(
1.0
,
name
=
'v2'
))
def
testSaveRestoreGraphCallable
(
self
):
with
context
.
eager_mode
(),
ops
.
device
(
self
.
_dev
()):
@
graph_callable
.
graph_callable
(
[
graph_callable
.
ShapeAndDtype
(
shape
=
(),
dtype
=
dtypes
.
float32
)])
def
model
(
x
):
v
=
variable_scope
.
get_variable
(
'v'
,
initializer
=
init_ops
.
zeros_initializer
(),
shape
=
())
return
v
+
x
# Default 2 + 0 = 2
self
.
assertEqual
(
2
,
model
(
array_ops
.
constant
(
2
,
dtype
=
dtypes
.
float32
)).
numpy
())
# Save the variable value 0.
ckpt_prefix
=
os
.
path
.
join
(
test
.
get_temp_dir
(),
'ckpt'
)
_saver
.
Saver
(
model
.
variables
).
save
(
ckpt_prefix
)
# update variable to 1, so that 2 + 1 = 3
model
.
variables
[
0
].
assign
(
1.
)
self
.
assertEqual
(
3
,
model
(
array_ops
.
constant
(
2
,
dtype
=
dtypes
.
float32
)).
numpy
())
# load the variable value 0, so that 2 + 0 = 2
_saver
.
Saver
(
model
.
variables
).
restore
(
ckpt_prefix
)
self
.
assertEqual
(
2
,
model
(
array_ops
.
constant
(
2
,
dtype
=
dtypes
.
float32
)).
numpy
())
# update checkpoint variable to 1 and memory value to 2.
model
.
variables
[
0
].
assign
(
1.
)
_saver
.
Saver
(
model
.
variables
).
save
(
ckpt_prefix
)
model
.
variables
[
0
].
assign
(
2.
)
self
.
assertEqual
(
4
,
model
(
array_ops
.
constant
(
2
,
dtype
=
dtypes
.
float32
)).
numpy
())
# reset the graph and reload on create, so that 1 + 2 = 3
with
ops
.
Graph
().
as_default
():
with
_saver
.
restore_variables_on_create
(
ckpt_prefix
):
@
graph_callable
.
graph_callable
(
[
graph_callable
.
ShapeAndDtype
(
shape
=
(),
dtype
=
dtypes
.
float32
)])
def
model2
(
x
):
v
=
variable_scope
.
get_variable
(
'v'
,
initializer
=
init_ops
.
zeros_initializer
(),
shape
=
())
return
v
+
x
self
.
assertEqual
(
3
,
model2
(
array_ops
.
constant
(
2
,
dtype
=
dtypes
.
float32
)).
numpy
())
if
__name__
==
'__main__'
:
test
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录