How to insert data from a python function into a TensorFlow queue

I have a python function that automatically generates a (data, label) pair when I call it. I do not know how to attach this function to TIFF, so the queue is filled with data received from my function. The code I have so far is:

myq = tf.FIFOQueue(5000, [tf.float32, tf.float32], [[4],[1]])
enqueue_op = myq.enqueue(read_data()) # read_data() returns two numpy arrays of shape [4] and [1]
qr = tf.train.QueueRunner(myq, [enqueue_op]*2)
...
threads = qr.create_threads(sess=sess,coord=coord, start=True)

However, this only calls the read_data () function and continues to push the same value into the queue. How to properly connect my function to the enqueue method so that I can fill the queue with data from my function (preferably using multiple threads in the background). Thank you for your help.

+4
source share
1 answer

, read_data - , TF. enqueue_op, feed_dict.

# Graph setup
x_enqueue = tf.placeholder(tf.float32, shape=(4))
y_enqueue = tf.placeholder(tf.float32, shape=(1))
enqueue_op = myq.enqueue([x_enqueue, y_enqueue])

...

# Enqueue loop:
x_read, y_read = read_data()
sess.run(enqueue_op, feed_dict={x_enqueue: x_read, y_enqueue: y_read})
+2

Source: https://habr.com/ru/post/1674135/


All Articles