![](/img/trans.png)
[英]IndexError: list index out of range in Tensorflow chatbot
[英]IndexError: list index out of range when save model in tensorflow
誰能幫我? 我使用 tensorflow 來訓練 LSTM 網絡。 訓練運行良好,但是當我想保存模型時,出現以下錯誤。
Step 1, Minibatch Loss= 0.0146, Training Accuracy= 1.000
Step 1, Minibatch Loss= 0.0129, Training Accuracy= 1.000
Optimization Finished!
Traceback (most recent call last):
File ".\lstm.py", line 169, in <module>
save_path = saver.save(sess, "modelslstm/" + str(time.strftime("%d-%m-%Y-%H-%M-%S")) + ".ckpt")
File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1314, in __exit__
self._default_graph_context_manager.__exit__(exec_type, exec_value, exec_tb)
File "C:\Python35\lib\contextlib.py", line 66, in __exit__
next(self.gen)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3815, in get_controller
if self.stack[-1] is not default:
IndexError: list index out of range
我的代碼:
with tf.Session() as sess:
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# from tensorflow.examples.tutorials.mnist import input_data
# mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
# a,b = mnist.train.next_batch(5)
# print(b)
# Run the initializer
sess.run(init)
saver = tf.train.Saver()
merged_summary_op = tf.summary.merge_all()
writer = tf.summary.FileWriter("trainlstm", sess.graph)
#print(str(data.train.num_examples))
for step in range(1, training_steps+1):
for batch_i in range(data.train.num_examples // batch_size):
batch_x, batch_y,name = data.train.next_batch(batch_size)
#hasil,cost = encode(batch_x[0][0],"models/25-09-2017-15-25-54.ckpt")
temp = []
for batchi in range(batch_size):
temp2 = []
for ti in range(timesteps):
hasil,cost = encode(batch_x[batchi][ti],"models/25-09-2017-15-25-54.ckpt")
hasil = np.reshape(hasil,[num_input])
temp2.append(hasil.copy())
temp.append(temp2.copy())
batch_x = temp
# Reshape data to get 28 seq of 28 elements
#batch_x = batch_x.reshape((batch_size, timesteps, num_input))
#dlib.hit_enter_to_continue()
# Run optimization op (backprop)
sess.run(train_op, feed_dict={X: batch_x, Y: batch_y})
# Calculate batch loss and accuracy
loss, acc = sess.run([loss_op, accuracy], feed_dict={X: batch_x,
Y: batch_y})
print("Step " + str(step) + ", Minibatch Loss= " + \
"{:.4f}".format(loss) + ", Training Accuracy= " + \
"{:.3f}".format(acc))
f.write("Step " + str(step) + ", Minibatch Loss= " + \
"{:.4f}".format(loss) + ", Training Accuracy= " + \
"{:.3f}".format(acc)+"\n")
print("Optimization Finished!")
save_path = saver.save(sess, "modelslstm/" + str(time.strftime("%d-%m-%Y-%H-%M-%S")) + ".ckpt")
f.close()
我添加了 tf.reset_default_graph() 但它不起作用。 請幫我解決我的問題。 謝謝!
你有使用的上下文管理器( with
1號線的語句?)。 上下文管理器似乎很難銷毀您的對象。 這可能是__exit__
內置__exit__
一個問題。 建議您向開發人員提交錯誤報告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.