6

I'm initializing the saver with

self.saver = tf.train.Saver()

at the end of the graph construction. Then I save my model with

self.saver.save(sess, self.data_batch.params.LOG_DIR + "model", global_step=epoch)

Finally i try to restore it with :

with tf.Session(graph=self.graph, config=self.proto_config) as sess:
    if restore:

        self.saver.restore(sess, "./" + self.data_batch.params.LOG_DIR)

    else:
        self.init.run()

my folder structure looks like this:

-Main directory
--main
--Logs/
---checkpoint
---events.out.tfevents.1528047461.Ublion18
---model-0.data-00000-of-00001
---model-0.index
---model-0.meta
---params

Error

The error is the following:

Caused by op 'save/RestoreV2', defined at:
  File "/home/dizzi/Work/PycharmProjects/NLP/HomeWork2/main.py", line 22, in <module>
    model.init_graph()
  File "/home/dizzi/Work/PycharmProjects/NLP/HomeWork2/Classes/Model.py", line 293, in init_graph
    self.saver = tf.train.Saver()
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1311, in __init__
    self.build()
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1320, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1357, in _build
    build_save=build_save, build_restore=build_restore)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 809, in _build_internal
    restore_sequentially, reshape)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 448, in _AddRestoreOps
    restore_sequentially)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 860, in bulk_restore
    return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 1458, in restore_v2
    shape_and_slices=shape_and_slices, dtypes=dtypes, name=name)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3290, in create_op
    op_def=op_def)
  File "/home/dizzi/anaconda3/envs/NLP/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1654, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ./Logs/
     [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
     [[Node: save/RestoreV2/_15 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_20_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

What I Tried

  • Putting "./" before Logs resulting in "./Logs/"
  • Using relative path ending with both "Logs" and "Logs/"
  • Using absolute path ending with both "Logs" and "Logs/"
  • Using absolute/relative path with "Logs/checkpoint", yields bad magic number error
  • Using ckpt = tf.train.get_checkpoint_state(path_to_your_checkpoint) and saver.restore(sess, ckpt.model_checkpoint_path), without giving self.graph to the tf.Session
  • Remove events and params

Tensorflow Version

tf.__version__
Out[3]: '1.7.0'

Operating system

 uname -a
 Linux Ublion18 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Can someone help me please?

ThatGuy
  • 75
  • 1
  • 9
  • use the full path or relative path. Dont include `/` at the end of `Logs` https://github.com/tensorflow/tensorflow/issues/6082 – Morse Jun 03 '18 at 19:44
  • I already tried it, I edited the "What I did" section to make it clearer. But thank you for your quick response! – ThatGuy Jun 03 '18 at 19:48
  • I am asking to try `./Logs` not `./Logs/` Get rid of ending slash. lets see – Morse Jun 03 '18 at 19:50
  • It yields this error: `DataLossError (see above for traceback): Unable to open table file ./Logs: Failed precondition: Logs; Is a directory: perhaps your file is in a different file format and you need to use a different restore operator?` – ThatGuy Jun 03 '18 at 19:52
  • you are trying to load a folder as model which is wrong. - you need to restore by passing **model name** or **meta file name** or **check point file name** . Check this answer. https://stackoverflow.com/questions/33759623/tensorflow-how-to-save-restore-a-model#40765759 – Morse Jun 03 '18 at 19:56
  • This solved my issue, thank you so much! – ThatGuy Jun 03 '18 at 19:58

0 Answers0