队列工作不如预期

时间:2016-10-28 16:14:59

标签: tensorflow

在TensorFlow教程“Threading_and Queues”中有一个使用队列的例子(开头的动画gif(见https://github.com/etetoolkit/ete/issues/244)。

我在我的计算机上尝试了这个示例,它的工作方式并不像预期的那样:

import tensorflow as tf
q = tf.FIFOQueue(3, tf.float32)
sess = tf.InteractiveSession()
q_size = q.size()
init = q.enqueue_many(([0.,0.,0.],))
# for getting the number of elements in the queue
q_size.eval()

0

# enqueue three elements into the queue
init.run()
q_size.eval()

3

x = q.dequeue()
y = x + 1
q_inc = q.enqueue([y])
q_inc.run()
y.eval()

1

q_size.eval()

2

q_inc.run()
y.eval()

2

q_size.eval()

1

q_inc.run()
y.eval()

3

q_size.eval()

0

所以队列是空的:-( 每次运行q_inc都会缩短队列。 y没有加入队列。为什么呢?

1 个答案:

答案 0 :(得分:1)

每个队列都会出两次队列。

y触发x,触发从队列中出列的y.eval()

x触发{{1}},它也从队列

中出列
相关问题