首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tensorflow Saver()未另存为.ckpt文件

Tensorflow Saver()未另存为.ckpt文件
EN

Stack Overflow用户
提问于 2016-12-08 12:59:47
回答 4查看 7.5K关注 0票数 3

我尝试运行一个简单的程序来将Tensorflow会话保存到磁盘上,并将其命名为"spikes.cpkt“。尽管在交互式程序中,系统输出显示我已成功创建该文件,但我在文件系统中找不到该文件。

我使用的Tensorflow版本是0.11rc,使用的是Python 2。操作系统是Ubuntu 16.04。该程序是在Jupiter notebook中编写和运行的。

保存会话的源码如下:

代码语言:javascript
复制
# Import TensorFlow and enable interactive sessions
import tensorflow as tf
sess = tf.InteractiveSession()

# Let's say we have a series data like this
raw_data = [1., 2., 8., -1., 0., 5.5, 6., 13.]
# Define a boolean vector called `spikes` to locate a sudden spike in raw data
spikes = tf.Variable([False] * len(raw_data), name='spikes')
# Don't forget to initialize the variable
spikes.initializer.run()

# The saver op will enable saving and restoring variables.
# If no dictionary is passed into the constructor, then the saver operators of all variables in the current program.
saver = tf.train.Saver()

# Loop through the data and update the spike variable when there is a significant increase
for i in range(1, len(raw_data)):
    if raw_data[i] - raw_data[i-1] > 5:
        spikes_val = spikes.eval()
        spikes_val[i] = True
        # Update the value of spikes by using the `tf.assign` function
        updater = tf.assign(spikes, spikes_val)
        # Don't forget to actually evaluate the updater, otherwise spikes will not be updated
        updater.eval()

# Save the variable to the disk
save_path = saver.save(sess, "spikes.ckpt")

# Print out where the relative file path of the saved variables
print("spikes data saved in file: %s" % save_path)

# Remember to close the session after it will no longer be used
sess.close()

系统的输出如图(1)所示:

在文件系统中创建的文件如图(2)所示:

磁盘中没有名为"spikes.ckpt“的文件。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-12-08 13:46:40

TensorFlow最近引入了一种新的检查点格式(Saver V2),它将检查点保存为一组具有公共前缀的文件。要创建使用旧格式的tf.train.Saver,您可以执行create it操作,如下所示:

代码语言:javascript
复制
saver = tf.train.Saver(write_version=tf.train.SaverDef.V1)
票数 9
EN

Stack Overflow用户

发布于 2017-09-01 19:27:53

您只需要将变量的名称放在tf.trai.Saver

代码语言:javascript
复制
saver = tf.train.Saver([spikes]) 
票数 0
EN

Stack Overflow用户

发布于 2018-04-16 04:36:28

我也有同样的问题,我正在阅读Tensorflow的机器学习这本书,在论坛上你也可以找到解决方案,那就是使路径相对

代码语言:javascript
复制
save_path = saver.save(sess, "./spikes.ckpt")

论坛帖子https://forums.manning.com/posts/list/41796.page

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41032075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档