带num_epochs的string_input_producer抛出OutofRangeError

时间:2016-08-29 12:22:35

标签: tensorflow

此代码按预期使元素出列:

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

1 个答案:

答案 0 :(得分:-1)

需要tf.initialize_all_variables().run()