Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Saver() not saving as .ckpt file

Tags:

tensorflow

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

The version of Tensorflow I used is 0.11rc using Python 2. The operating system is Ubuntu 16.04. The program was written and run in Jupiter notebook.

The following is the source code of saving 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()

The output of the system is in Figure (1): enter image description here

The files created in the File System is shown in Figure (2): enter image description here

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

like image 291
Yuan Ma Avatar asked Dec 24 '22 22:12

Yuan Ma


1 Answers

TensorFlow recently introduced a new checkpoint format (Saver V2) which saves the checkpoint as a set of files with a common prefix. To create a tf.train.Saver that uses the old format, you can create it as follows:

saver = tf.train.Saver(write_version=tf.train.SaverDef.V1)
like image 141
mrry Avatar answered Dec 30 '22 21:12

mrry