這裏是我的模型保存到磁盤:tensorflow - 不能恢復模型 - 「無法匹配檢查點文件」
import tensorflow as tf
import numpy as np
BATCH_SIZE = 3
VECTOR_SIZE = 1
LEARNING_RATE = 0.1
x = tf.placeholder(tf.float32, [BATCH_SIZE, VECTOR_SIZE],
name='input_placeholder')
y = tf.placeholder(tf.float32, [BATCH_SIZE, VECTOR_SIZE],
name='labels_placeholder')
W = tf.get_variable('W', [VECTOR_SIZE, BATCH_SIZE])
b = tf.get_variable('b', [VECTOR_SIZE], initializer=tf.constant_initializer(0.0))
y_hat = tf.matmul(W, x) + b
predict = tf.add(tf.matmul(W, x), b, name='predict')
total_loss = tf.reduce_mean(y-y_hat)
train_step = tf.train.AdagradOptimizer(LEARNING_RATE).minimize(total_loss)
X = np.ones([BATCH_SIZE, VECTOR_SIZE])
Y = np.ones([BATCH_SIZE, VECTOR_SIZE])
all_saver = tf.train.Saver()
sess= tf.Session()
sess.run(tf.global_variables_initializer())
sess.run([train_step], feed_dict = {x: X, y:Y})
save_path = r'C:\tmp\tmp\\'
all_saver.save(sess,save_path)
在試圖恢復
checkpoint_path = r'C:\tmp\tmp\\'
tf.train.latest_checkpoint(checkpoint_path)
我正在以下錯誤信息:
ERROR:tensorflow:Couldn't match files for checkpoint C:\tmp\tmp\\
在C:\tmp\tmp\
我有以下文件:
.data-00000-of-00001
.index
.meta
checkpoint
有什麼想法?
您的解決方案可能是工作。我做了什麼,我只是寫了r'C:\ tmp \ tmp \ prefix_name'。 'prefix_name'被視爲前綴名稱,而不是作爲tensorflow中路徑的一部分。 – user1700890