BinRoot / TensorFlow-Book

Accompanying source code for Machine Learning with TensorFlow. Refer to the book for step-by-step explanations.
http://www.tensorflowbook.com
MIT License
4.45k stars 1.21k forks source link

ch02_basics Concept06_saving_variables #3

Closed toasteez closed 7 years ago

toasteez commented 7 years ago

When running the following code from code:

save_path = saver.save(sess, "spikes.ckpt")
print("spikes data saved in file: %s" % save_path)

I receive an error.

I am running on Windows 7 in conda virtual environment and Jupyter.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-444ce612b9fd> in <module>()
----> 1 save_path = saver.save(sess, "spikes.ckpt")
      2 print("spikes data saved in file: %s" % save_path)

C:\Program Files\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\saver.py in save(self, sess, save_path, global_step, latest_filename, meta_graph_suffix, write_meta_graph, write_state)
   1312     if not gfile.IsDirectory(os.path.dirname(save_path)):
   1313       raise ValueError(
-> 1314           "Parent directory of {} doesn't exist, can't save.".format(save_path))
   1315 
   1316     save_path = os.path.dirname(save_path)

ValueError: Parent directory of spikes.ckpt doesn't exist, can't save.
johndpope commented 7 years ago

I recommend you provide an ubuntu virtual machine image link(not docker), rather than trying to get this code running on every machine.

johndpope commented 7 years ago

Try this

https://medium.com/@josemarcialportilla/hi-there-im-jose-portilla-and-i-teach-data-science-online-and-in-person-1c93298d5145#.b7be2cczt

sicnarf1a commented 7 years ago

I have the same issue. I am currently using windows10 and jupyter notebooks. To solve this problem, is it necessary to use in a virtual environment?

chmnoh commented 7 years ago

You may try absolute path, for example: "C:\\Users\\YourName\\Documents\\spikes.ckpt"

DiegoPortoJaccottet commented 7 years ago

I got a similar problem in "Ch 02: Concept 07", couldn't load the variables until I used the full path:

try: ... saver.restore(sess, 'spikes.ckpt') ... print(spikes.eval()) ... except: ... print('file not found') ... W tensorflow/core/framework/op_kernel.cc:975] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for spikes.ckpt file not found try: ... saver.restore(sess, os.path.abspath('spikes.ckpt')) ... print(spikes.eval()) ... except: ... print('file not found') ... [False False True False False True False True]

BinRoot commented 7 years ago

Interesting. Have you tried running restore on ".spikes.ckpt"? It seems to work with the prefixed "."

minkoon commented 7 years ago

change the path to be exactly directory. For example: checkpoint_name = "C:\Users\Minkun\Desktop\VTIS_Project\model.ckpt" note that you used '\' instead ''