At startup
enqueue_op = q.enqueue(list(next(it)))
tensorflow will execute the list (next (it)) exactly once. After that, it will save this first list and add it to q every time it starts enqueue_op. To avoid this, you should use a placeholder. Feed placeholders are not compatible with tf.train.QueueRunner. Use this instead:
import tensorflow as tf
import numpy as np
import threading
imgs = [np.random.randn(i,i) for i in [2,3,4,5]]
def data_iterator():
while True:
for img in imgs:
yield img
it = data_iterator()
q = tf.FIFOQueue(capacity=5, dtypes=[tf.float64])
img_p = tf.placeholder(tf.float64, [None, None])
enqueue_op = q.enqueue(img_p)
dequeue_op = q.dequeue()
with tf.Session() as sess:
coord = tf.train.Coordinator()
def enqueue_thread():
with coord.stop_on_exception():
while not coord.should_stop():
sess.run(enqueue_op, feed_dict={img_p: list(next(it))})
numberOfThreads = 1
for i in range(numberOfThreads):
threading.Thread(target=enqueue_thread).start()
for i in range(3):
data = sess.run(dequeue_op)
print(data)
source
share