此代码按预期使元素出列:
import tensorflow as tf
with tf.Session() as sess:
queue = tf.train.string_input_producer([str(i) for i in range(10)])
deq = queue.dequeue()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(3):
print(sess.run([deq]))
但是,当我将num_epochs
添加到string_input_producer时,它会失败并显示OutofRangeError
:
import tensorflow as tf
with tf.Session() as sess:
queue = tf.train.string_input_producer([str(i) for i in range(10)], num_epochs=1)
deq = queue.dequeue()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(3):
print(sess.run([deq]))
我正在使用tensorflow 0.9
答案 0 :(得分:-1)
需要tf.initialize_all_variables().run()