[Python] Cannot restore model in tensorflow [duplicate]

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página