gpt4 book ai didi

Tensorflow Saver()不保存为.ckpt文件

转载 作者:行者123 更新时间:2023-12-03 16:41:42 31 4
gpt4 key购买 nike

我尝试运行一个简单的程序来将 Tensorflow session 保存到磁盘上作为“spikes.cpkt”。虽然在交互式程序中,系统输出显示我已成功创建该文件,但我在文件系统中找不到该文件。

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

以下是保存 session 的源代码:

# 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)所示:
enter image description here

File System中创建的文件如图(2)所示:
enter image description here

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

最佳答案

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

saver = tf.train.Saver(write_version=tf.train.SaverDef.V1)

关于Tensorflow Saver()不保存为.ckpt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032075/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com