I have one serialized file for each class in my dataset. I would like to use queues to load up each of these files and then place them in a RandomShuffleQueue that will pull them off so I get a random mix of examples from each class. I thought this code would work.
In this example each file has 10 examples.
filenames = ["a", "b", ...]
with self.test_session() as sess:
# for each file open a queue and get that
# queue's results.
strings = []
rq = tf.RandomShuffleQueue(1000, 10, [tf.string], shapes=())
for filename in filenames:
q = tf.FIFOQueue(99, [tf.string], shapes=())
q.enqueue([filename]).run()
q.close().run()
# read_string just pulls a string from the file
key, out_string = input_data.read_string(q, IMAGE_SIZE, CHANNELS, LABEL_BYTES)
strings.append(out_string)
rq.enqueue([out_string]).run()
rq.close().run()
qs = rq.dequeue()
label, image = input_data.string_to_data(qs, IMAGE_SIZE, CHANNELS, LABEL_BYTES)
for i in range(11):
l, im = sess.run([label, image])
print("L: {}".format(l)
This works fine for 10 calls, but on the 11th it says that the queue is empty.
I believe this is due to a misunderstanding on my part of what these queues operate on. I add 10 variables to the RandomShuffleQueue
, but each of those variables is itself pulling from a queue, so I assumed the queue would not be emptied until each of the file queues was empty.
What am I doing wrong here?