变量saver
程序如下:
import tensorflow as tf
sess = tf.InteractiveSession()
raw_data = [1., 2., 8., -1., 0., 5.5, 6., 13]
spikes = tf.Variable([False] * len(raw_data), name='spikes')
spikes.initializer.run()
tf.global_variables_initializer().run() #add by cs
saver = tf.train.Saver()
for i in range(1, len(raw_data)):
if raw_data[i] - raw_data[i-1] > 5:
spikes_val = spikes.eval()
spikes_val[i] = True
updater = tf.assign(spikes, spikes_val)
updater.eval()
save_path = saver.save(sess, "spikes.ckpt")
print("spikes data saved in file: %s" % save_path)
sess.close()
恢复计划如下:
import tensorflow as tf
sess = tf.InteractiveSession()
spikes = tf.Variable([False]*8, name='spikes')
saver = tf.train.Saver()
try:
saver.restore(sess, 'spikes.ckpt')
print(spikes.eval())
except:
print('file not found')
sess.close()
始终存在异常"file not found"
。
怎么了?