当前位置:  开发笔记 > 编程语言 > 正文

无法在张量流中还原模型

如何解决《无法在张量流中还原模型》经验,为你挑选了0个好方法。

我正在初始化保护程序

self.saver = tf.train.Saver()

在图形构造的末尾。然后我用保存模型

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

最后,我尝试使用还原它:

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()

我的文件夹结构如下所示:

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

错误如下:

Caused by op 'save/RestoreV2', defined at:
  File "/home/dizzi/Work/PycharmProjects/NLP/HomeWork2/main.py", line 22, in 
    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"]()]]
我尝试过的

在日志前放置“ ./”,得到“ ./Logs/”

使用以“ Logs”和“ Logs /”结尾的相对路径

使用以“ Logs”和“ Logs /”结尾的绝对路径

将绝对/相对路径与“日志/检查点”一起使用会产生错误的幻数错误

使用ckpt = tf.train.get_checkpoint_state(path_to_your_checkpoint)和saver.restore(sess,ckpt.model_checkpoint_path),而无需将self.graph赋予tf.Session

删除事件和参数

Tensorflow版本

tf.__version__
Out[3]: '1.7.0'
操作系统
 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

有谁可以帮助我吗?

推荐阅读
和谐啄木鸟
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有