1
votes

In my tensorflor pipeline I am creating two batching queues: one for the examples (images) and one for the labels (integers), essentially in the same way that cifar10_input.py processes input:

<read files>
image = tf.image.decode_png(file_contents)
label = tf.string_to_number(label_str, out_type=tf.int32)
# Batch examples here into two queues.
image_batch, label_batch = tf.train.shuffle_batch(
    [image, label], ... )
model = build_model(image_batch)
loss = build_loss(model, label_batch)

The model then takes the image queue as an input, and the loss evaluates the difference between the output of the model and the labels.

My worry is that if I evaluate only the model on a batch of images, the label queue will no longer be "aligned" and the two queues (images and labels) will diverge.

(model_output, ) = sess.run([model])  # Uses the image queue as input
(model_output, true_labels) = sess.run([model, label_batch])  # Are image/labels pairs valid?

How can I ensure the two queues stay synchronized, so that fetching an element from each will always return a correct image/label pair?

1
you have to always dequeue them at the same time. You could evaluate model on batch of images and discard the labels even though you dequeue them - Yaroslav Bulatov
@YaroslavBulatov this seems tricky, because you have to know every place that either queue gets used (in this case, for example, the model itself) and dequeue the other ones appropriately. - Felix

1 Answers

2
votes

Yaroslav's comment is correct - you have to ensure they're always dequeued together.

If you want to evaluate the model on non-labeled data in a way that's interleaved with your training steps, then you could instantiate another copy of the model (with weights shared - set reuse=true) and have it read from your alternate, non-labeled data source. That's not an unusual pattern if you want to have simultaneous training and inference going on.

train_predict = model(train_input)
do something with the label here...
alternate:
use_predict = model(use_input, reuse=true)

(reuse=true referring to the variable scoping).