Tensorflow Saver () is not saved as a .ckpt file

I tried to run a simple program to save a Tensorflow session to disk as "spikes.cpkt". Although the system output in the interactive program showed that I successfully created this file, I can not find this file in the file system.

As a version of Tensorflow, I use 0.11rc using Python 2. The operating system is Ubuntu 16.04. The program was written and launched on Jupiter's laptop.

The following is the source code for saving a session:

# Import TensorFlow and enable interactive sessions
import tensorflow as tf
sess = tf.InteractiveSession()

# Let 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()

The system output is shown in figure (1):

Files created in the File system are shown in the figure (2):

There is no file on the disk named "spikes.ckpt".

+4
source share
3 answers

TensorFlow (Saver V2), . tf.train.Saver, , :

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

tf.trai.Saver

saver = tf.train.Saver([spikes]) 
0

I had the same problem, I read the Machine Learning book with Tensorflow, in the forums you can also find a solution that should make the relative path

save_path = saver.save(sess, "./spikes.ckpt")

Forum post https://forums.manning.com/posts/list/41796.page

0
source

Source: https://habr.com/ru/post/1663196/


All Articles