Getting slightly different input in each data fetch operation
<p>I am following the <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/image/cifar10" rel="nofollow">cifar10 tutorial</a> and fetch my data using <a href="https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/models/image/cifar10/cifar10_input.py#L197" rel="nofollow">inputs()</a> function called by <a href="https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/models/image/cifar10/cifar10.py#L163" rel="nofollow">cifar10.inputs</a>. My code is as follows:</p>

<pre><code>import tensorflow as tf
import cifar10

# Get images and labels
images, labels = cifar10.inputs(eval_data='test')

# Start running operations on the Graph.
sess = tf.Session()
sess.run(tf.initialize_all_variables())

# Start the queue runners.
tf.train.start_queue_runners(sess=sess)

img, lab = sess.run([images, labels])
print(lab)
</code></pre>

<p>To test this, I run the code with batch size 10 and print the <strong>labels</strong> of the first batch. I expect the same output each time I execute this code, because <strong>shuffle=False</strong> in the <a href="https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/models/image/cifar10/cifar10_input.py#L197" rel="nofollow">inputs()</a> function. However, I observe slightly different labels in each execution, for example outputs from three consecutive executions are:</p>

<pre><code>run-1: [0 1 2 2 1 1 1 9 8 8]
run-2: [1 2 2 0 1 1 1 9 8 8]
run-3: [0 2 2 1 1 1 1 9 8 8]
</code></pre>

<p>I would like to know: </p>

<ol>
<li>Why I am getting different labels although shuffle is off? and  </li>
<li>What should I do to obtain the same labels at each execution?</li>
</ol>

<p>The queue runners you are starting there are multiple threads loading data from disk and adding it to the queue. <a href="https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/models/image/cifar10/cifar10_input.py#L117" rel="nofollow">There are 16 of them by default</a>. </p>

<p>The queue itself is thread-safe, but there is nothing enforcing order.</p>

<p>So even though you're not using the shuffling queue, the race-condition between the threads to fetch and insert the items randomizes the order slightly.</p>

<p>The easiest way to make it completely repeatable is to only use 1 thread to fetch items. This will probably be slow.</p>

python io tensorflow