chris elgoog
chris elgoog

Reputation: 145

Queue works not as expected

In the TensorFlow Tutorial "Threading_and Queues" there is an example how using the queue (the animated gif at the beginning (see https://www.tensorflow.org/versions/r0.11/how_tos/threading_and_queues/index.html).

I tried the example on my computer and it works not as expected:

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

So the queue is empty :-( Each time running q_inc shortens the queue. y is not enqueued. Why?

Upvotes: 0

Views: 53

Answers (1)

Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57893

You are dequeuing twice for each enqueue.

q_inc.run() triggers y, which triggers x which dequeues from queue

y.eval() triggers x which also dequeues from queue

Upvotes: 1

Related Questions