- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现如果要保存某个图的所有变量,必须在图的最后定义tf.train.Saver
,否则saver无法获取所有变量变量。
这是我的测试代码:
def how_saver_work():
g = tf.Graph()
with g.as_default():
a = tf.Variable(1, name='a')
b = tf.Variable(2, name='b')
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
saver = tf.train.Saver()
c = tf.Variable(3, name='c')
print(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
with tf.Session() as sess:
tf.global_variables_initializer().run()
print(a.eval())
print(b.eval())
print(c.eval())
save_path = saver.save(sess, "./tmp/model.ckpt")
with tf.Session(graph=g) as sess:
print(g.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
saver.restore(sess, save_path)
print(a.eval())
print(b.eval())
print(c.eval()) # err: uninitialized
我首先认为保存程序可能会从tf.GraphKeys.GLOBAL_VARIABLES
或tf.GraphKeys.SAVEABLE_OBJECTS
获取变量。但这似乎是错误的。
我还想知道如何向 Saver 添加新变量。例如 var c
.
最佳答案
你是对的,saver
确实从tf.GraphKeys.GLOBAL_VARIABLES
和tf.GraphKeys.SAVEABLE_OBJECTS
的联合中获取变量在其构建时(参见 Saver._build
实现或下面的引用):
if self._var_list is None:
# pylint: disable=protected-access
self._var_list = variables._all_saveable_objects()
其中_all_saveable_objects
在python/ops/variables.py
文件中定义
def _all_saveable_objects(scope=None):
"""Returns all variables and `SaveableObject`s that must be checkpointed.
Args:
scope: (Optional.) A string. If supplied, the resulting list is filtered
to include only items whose `name` attribute matches `scope` using
`re.match`. Items without a `name` attribute are never returned if a
scope is supplied. The choice of `re.match` means that a `scope` without
special tokens filters by prefix.
Returns:
A list of `Variable` and `SaveableObject` to be checkpointed
"""
# TODO(andreasst): make this function public once things are settled.
return (ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope) +
ops.get_collection(ops.GraphKeys.SAVEABLE_OBJECTS, scope))
除了创建新的保护程序之外,无法向保护程序添加变量(参见 https://github.com/tensorflow/tensorflow/issues/2489#issuecomment-221282483 ):
When you create a
tf.train.Saver
with no arguments, it will implicitly use the current set of variables at the time of Saver construction when it saves and restores. If you add a new variable [...], you have to create a newtf.train.Saver
to save it.
关于python - `tf.train.Saver`收集变量保存在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49528515/
重要说明:我只是在笔记本环境中运行这一部分,图形定义。我还没有运行实际的 session 。 运行这段代码时: with graph.as_default(): #took out " , tf.de
将训练好的模型参数保存起来,以便以后进行验证或测试,这是我们经常要做的事情。tf里面提供模型保存的是tf.train.Saver()模块。 模型保存,先要创建一个Saver对象:如
我尝试运行一个简单的程序来将 Tensorflow session 保存到磁盘上作为“spikes.cpkt”。虽然在交互式程序中,系统输出显示我已成功创建该文件,但我在文件系统中找不到该文件。 我使
我有一个带有Autoencoder的docker容器,可以通过Flask-Server启动它。所有脚本都被复制到Docker的/ root中,并且还可以访问共享卷/ data,如下所示: /数据 -/
我需要将我的 iPad 应用程序完全按照它在设备上运行的方式镜像到外部屏幕上,但在一段时间不事件后,外部屏幕应显示静态图像,直到设备再次接收触摸输入。我今天阅读了很多关于在 iOS 中处理多个屏幕的内
我正在尝试在我的 Angular 2 应用程序中实现下载按钮。 我用过这些教程: http://alferov.github.io/angular-file-saver/ https://coryry
根据有关此 API 的文档和大量 SO 帖子,必须使用 创建保护程序对象 saver = tf.train.Saver(...variables...) 我想知道是否有任何方法可以自动填充(...va
Android 7.0 Nougat 添加了 Data Saver 功能,允许用户限制某些应用程序(包括推送通知)的后台数据。当 Data Saver 开启时,只有在 中找到的列表中的应用程序 Set
我正在为 Android 开发一个音乐流媒体应用。 在这个应用程序中,我有一个 Service 负责播放来自 HTTP 服务器的音频。在播放之前,我确保 startForeground() 并获取部分
var MyFiles = []; if (val == "Address") { MyFiles.push({ 'file': 'http://-
我发现如果要保存某个图的所有变量,必须在图的最后定义tf.train.Saver,否则saver无法获取所有变量变量。 这是我的测试代码: def how_saver_work(): g =
是否可以通过 drop-in saver 将 localhost 文件上传到 dropbox?( https://www.dropbox.com/developers/dropins/saver )
我有一个训练好的模型,使用tf.train.Saver保存,生成4个相关文件 检查点 model_iter-315000.data-00000-of-00001 model_iter-315000.i
我刚刚将本地安装的 Tensorflow 更新为 0.11rc2,我收到一条消息说我应该向我的保护程序添加一个参数以使其保存在版本 2 中。我更新了它,现在我无法加载保存在版本 2 中的模型这种格式。
关于模型保存的一点心得 ? 1
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 3 年前。 Improve th
我创建了一些按钮,并且单击按钮 url 和文件名发送到动态数组,当我单击 dropbox saver 按钮时,我希望 saver 函数使用该动态数组将文件发送到 dropbox。我当前的代码出现此错误
我想知道在每次训练后使用 tf.train.Saver() 保存我的模型时到底保存了什么。与我习惯使用 Keras 模型的文件相比,该文件似乎有点大。现在我的 RNN 在每次保存时占用 900 MB。
我们可以保存一个检查点 saver = tf.train.Saver() saver.save(sess, FLAGS.train_dir, global_step=step) 然后,稍后,我可以恢复
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 3 年前。 Improve th
我是一名优秀的程序员,十分优秀!