使用以下方式保存模型:
self.model.saver.save(sess, os.path.join(result_dir, "basic"), global_step=global_step)
这会产生:
devuser@gpu:~/ChatLearner-v1$ ls -al ./Data/Result/
total 7945536
drwxrwxr-x 3 devuser devuser 4096 Oct 18 12:45 .
drwxrwxr-x 6 devuser devuser 4096 Oct 13 07:54 ..
-rw-rw-r-- 1 devuser devuser 1625702412 Oct 17 00:22 basic-143640.data-00000-of-00001
-rw-rw-r-- 1 devuser devuser 2660 Oct 17 00:22 basic-143640.index
-rw-rw-r-- 1 devuser devuser 1525771 Oct 17 00:22 basic-143640.meta
-rw-rw-r-- 1 devuser devuser 1625702412 Oct 17 01:52 basic-146205.data-00000-of-00001
-rw-rw-r-- 1 devuser devuser 2660 Oct 17 01:52 basic-146205.index
-rw-rw-r-- 1 devuser devuser 1525771 Oct 17 01:52 basic-146205.meta
-rw-rw-r-- 1 devuser devuser 1625702412 Oct 17 03:22 basic-148770.data-00000-of-00001
-rw-rw-r-- 1 devuser devuser 2660 Oct 17 03:22 basic-148770.index
-rw-rw-r-- 1 devuser devuser 1525771 Oct 17 03:22 basic-148770.meta
-rw-rw-r-- 1 devuser devuser 1625702412 Oct 17 04:51 basic-151335.data-00000-of-00001
-rw-rw-r-- 1 devuser devuser 2660 Oct 17 04:51 basic-151335.index
-rw-rw-r-- 1 devuser devuser 1525771 Oct 17 04:51 basic-151335.meta
-rw-rw-r-- 1 devuser devuser 1625702412 Oct 17 06:21 basic-153900.data-00000-of-00001
-rw-rw-r-- 1 devuser devuser 2660 Oct 17 06:21 basic-153900.index
-rw-rw-r-- 1 devuser devuser 1525771 Oct 17 06:21 basic-153900.meta
-rw-rw-r-- 1 devuser devuser 487 Oct 17 06:21 checkpoint
drwxr-xr-x 2 devuser devuser 4096 Oct 18 12:36 train_log
然后使用以下方法恢复模型:
self.model.saver.restore(session, os.path.join(result_dir, "basic"))
但是这会引发以下错误:
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/devuser/ChatLearner-v1/Data/Result/basic
[[Node: save/RestoreV2_6 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save/Const_0_0, save/RestoreV2_6/tensor_names, save/RestoreV2_6/shape_and_slices)]]
有人可以帮忙吗?
答案 0 :(得分:1)
请使用tf.train.latest_checkpoint:
self.model.saver.restore(session,tf.train.latest_checkpoint(os.path.join(result_dir,“basic”)))
Doc:https://www.tensorflow.org/api_docs/python/tf/train/latest_checkpoint
答案 1 :(得分:0)
答案是修改模型路径:
self.model.saver.restore(session, os.path.join(result_dir, "basic-153900"))
根据检查站日志:
cybercon@gpu:~/ChatLearner-v1$ cat Data/Result/checkpoint
model_checkpoint_path: "/home/cybercon/ChatLearner/Data/Result/basic-153900"
all_model_checkpoint_paths: "/home/cybercon/ChatLearner/Data/Result/basic-143640"
all_model_checkpoint_paths: "/home/cybercon/ChatLearner/Data/Result/basic-146205"
all_model_checkpoint_paths: "/home/cybercon/ChatLearner/Data/Result/basic-148770"
all_model_checkpoint_paths: "/home/cybercon/ChatLearner/Data/Result/basic-151335"
all_model_checkpoint_paths: "/home/cybercon/ChatLearner/Data/Result/basic-153900"