我建立了CNN分类模型并在训练时保存了检查点。运行此代码后。
checkpoint_dir = "/home/user/cnn-model/trained_model_1506946529/"
checkpoint_file = tf.train.latest_checkpoint(checkpoint_dir + 'checkpoints')
我收到错误:
NotFoundError Traceback (most recent call last)
<ipython-input-60-8de4d687f60c> in <module>()
5 checkpoint_dir += '/'
6 print (checkpoint_dir + 'checkpoints')
----> 7 checkpoint_file = tf.train.latest_checkpoint(checkpoint_dir + 'checkpoints')
8 print (checkpoint_file)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py in latest_checkpoint(checkpoint_dir, latest_filename)
1612 v1_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
1613 saver_pb2.SaverDef.V1)
-> 1614 if file_io.get_matching_files(v2_path) or file_io.get_matching_files(
1615 v1_path):
1616 return ckpt.model_checkpoint_path
/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py in get_matching_files(filename)
330 # Convert the filenames to string from bytes.
331 compat.as_str_any(matching_filename)
--> 332 for single_filename in filename
333 for matching_filename in pywrap_tensorflow.GetMatchingFiles(
334 compat.as_bytes(single_filename), status)
/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
64 if type is None:
65 try:
---> 66 next(self.gen)
67 except StopIteration:
68 return
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
464 None, None,
465 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466 pywrap_tensorflow.TF_GetCode(status))
467 finally:
468 pywrap_tensorflow.TF_DeleteStatus(status)
NotFoundError: /home/user/cnn-model/trained_model_1506946529/checkpoints
文件位置存在,检查点也存在,我该怎么做才能缓解它?
答案 0 :(得分:0)
tf.train.latest_checkpoint将文件夹名称作为arg。只需将其更改为:
checkpoint_file = tf.train.latest_checkpoint(checkpoint_dir)