解决tensorflow1.x版本加载saver.restore目录报错的问题
这个错误是最新的错误哈,目前只在tensorflow上的github仓库上面有提出,所以你在百度上面找不到。
是个tensorflow的bug十天前提出的,只有github仓库上一个地方有提出。
NotFoundError(seeabovefortraceback):UnsuccessfulTensorSliceReaderconstructor: Failedtofindanymatchingfilesforxxx
Traceback(mostrecentcalllast): File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line1022,in_do_call returnfn(*args) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line1004,in_run_fn status,run_metadata) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\contextlib.py",line66,in__exit__ next(self.gen) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py",line466,inraise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.NotFoundError:UnsuccessfulTensorSliceReaderconstructor:FailedtofindanymatchingfilesforD://model.ckpt [[Node:save_1/RestoreV2_10=RestoreV2[dtypes=[DT_FLOAT],_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0,save_1/RestoreV2_10/tensor_names,save_1/RestoreV2_10/shape_and_slices)]] Duringhandlingoftheaboveexception,anotherexceptionoccurred: Traceback(mostrecentcalllast): File"F:/DeepStock/DeepStock/testCapacity.py",line77,inprediction(out) File"F:/DeepStock/DeepStock/testCapacity.py",line63,inprediction saver.restore(sess,'D://model.ckpt') File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line1428,inrestore {self.saver_def.filename_tensor_name:save_path}) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line767,inrun run_metadata_ptr) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line965,in_run feed_dict_string,options,run_metadata) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line1015,in_do_run target_list,options,run_metadata) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py",line1035,in_do_call raisetype(e)(node_def,op,message) tensorflow.python.framework.errors_impl.NotFoundError:UnsuccessfulTensorSliceReaderconstructor:FailedtofindanymatchingfilesforD://model.ckpt [[Node:save_1/RestoreV2_10=RestoreV2[dtypes=[DT_FLOAT],_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0,save_1/RestoreV2_10/tensor_names,save_1/RestoreV2_10/shape_and_slices)]] Causedbyop'save_1/RestoreV2_10',definedat: File"F:/DeepStock/DeepStock/testCapacity.py",line77,in prediction(out) File"F:/DeepStock/DeepStock/testCapacity.py",line60,inprediction saver=tf.train.Saver(tf.global_variables()) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line1040,in__init__ self.build() File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line1070,inbuild restore_sequentially=self._restore_sequentially) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line675,inbuild restore_sequentially,reshape) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line402,in_AddRestoreOps tensors=self.restore_op(filename_tensor,saveable,preferred_shard) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\training\saver.py",line242,inrestore_op [spec.tensor.dtype])[0]) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\gen_io_ops.py",line668,inrestore_v2 dtypes=dtypes,name=name) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py",line763,inapply_op op_def=op_def) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py",line2327,increate_op original_op=self._default_original_op,op_def=op_def) File"C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py",line1226,in__init__ self._traceback=_extract_stack() NotFoundError(seeabovefortraceback):UnsuccessfulTensorSliceReaderconstructor:FailedtofindanymatchingfilesforD://model.ckpt [[Node:save_1/RestoreV2_10=RestoreV2[dtypes=[DT_FLOAT],_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0,save_1/RestoreV2_10/tensor_names,save_1/RestoreV2_10/shape_and_slices)]]
改之前代码:
saver.restore(sess,'D://model.ckpt')
将前面加上个点斜杠就好了。
saver.restore(sess,'D://./model.ckpt')
如果你目录太复杂实在搞不明白用这个(默认加载checkout文件中的最新的保存的数据):
module_file=tf.train.latest_checkpoint('E://deeplearning-master/deeplearning-master/tensorflow-program/save/') withtf.Session()assess: sess.run(tf.global_variables_initializer()) ifmodule_fileisnotNone: saver.restore(sess,module_file)
以上这篇解决tensorflow1.x版本加载saver.restore目录报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。