TensorFlow-Book icon indicating copy to clipboard operation
TensorFlow-Book copied to clipboard

Ch02 concept 6 Saving variable

Open boloson opened this issue 8 years ago • 6 comments

saver.save(sess, "spikes.ckpt") doesn't work

require running tf.global_variables_initializer() for newer version of Tensorflow

sess = tf.InteractiveSession() init = tf.global_variables_initializer() sess.run(init)

raw_data = [1., 2., 8., -1., 0., 5.5, 6., 13] spikes = tf.Variable([False] * len(raw_data), name='spikes') spikes.initializer.run()

saver = tf.train.Saver()

boloson avatar Jul 30 '17 22:07 boloson

Same issue (Not found: ; No such file or directory). Apparently, it tries to look for the file before creating it.

sirusss avatar Nov 05 '17 04:11 sirusss

running on a windows machine, change line : saver.save(sess, "spikes.ckpt") to saver.save(sess, "./spikes.ckpt") resulted in successful save of the checkpoint

roip avatar Dec 02 '17 20:12 roip

saver.save(sess, "spikes.ckpt")

This line raises the error: ValueError: Parent directory of spikes.ckpt doesn't exist, can't save.

It's pretty clear the parameter is asking for a path and not just a file name. So please fix the code into the format as @roip suggested or into a sub-directory format like this: saver.save(sess, "train_saves\spikes.ckpt")

sansmoraxz avatar Jan 24 '18 18:01 sansmoraxz

I had to use "./spikes.ckpt"

nickdesaulniers avatar Feb 13 '18 08:02 nickdesaulniers

except for "Parent directory of spikes.ckpt doesn't exist", on windows and spyder, the following error happened:

... shape_and_slices=shape_and_slices, tensors=tensors, name=name) File "e:\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "e:\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 3290, in create_op op_def=op_def) File "e:\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1654, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value Variable [[Node: save_7/SaveV2 = SaveV2[dtypes=[DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL, DT_BOOL], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save_7/Const_0_0, save_7/SaveV2/tensor_names, save_7/SaveV2/shape_and_slices, Variable, Variable_1, Variable_2, Variable_3, Variable_4, spikes, spikes_1, spikes_2, spikes_3, spikes_4, spikes_5, spikes_6, spikes_7, spikes_8)]] ...

I also doubt this is the spyder's problem because it works on python console.

tangyong avatar Apr 08 '18 02:04 tangyong

adding the following in spyder has fixed the problem! (including any file eg. loading variable)

tf.reset_default_graph()

tangyong avatar Apr 08 '18 04:04 tangyong