Tensorflow warning: Out of range about RandomShuffleQueue
<p>I have a TFRecords file storing 8000 train samples. I load it into a filename queue and set the <code>num_epoches</code> to <code>2</code>, so that it should be 16000 samples to enqueue the queue. At the same time, I set the <code>batch_size</code> to 100, so it should be iterate 160 times before the queue becomes empty.</p>

<pre><code>... 
...
sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
start_time = time.time()
try:
    step = 0
    while not coord.should_stop():
        _, loss_value, acc_value_train, acc_value_test, summary_str \
            = sess.run([train_op, loss, acc_train, acc_test, summary_op])
        step = step + 1
        if step % 1 == 0:
            format_str = ('step %d, loss = %.2f, acc_train = %.2f, acc_test = %.2f, time: %.2f seconds')
            print(format_str % (step, loss_value, acc_value_train, acc_value_test, (time.time() - start_time)))
            summary_writer.add_summary(summary_str, step)
            start_time = time.time()
except tf.errors.OutOfRangeError:
    print('done')
finally:
    coord.request_stop()

coord.join(threads)
sess.close()
</code></pre>

<p>However, when I really run the training code, I got the following logs:</p>

<pre><code>...
step 157, loss = 4.59, acc_train = 0.12, acc_test = 0.20, time: 0.07 seconds
step 158, loss = 4.53, acc_train = 0.15, acc_test = 0.17, time: 0.07 seconds
step 159, loss = 4.44, acc_train = 0.18, acc_test = 0.21, time: 0.07 seconds
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
done
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
W tensorflow/core/framework/op_kernel.cc:940] Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
     [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Process finished with exit code 0
</code></pre>

<p>You see, since the 'done' was printed, it means OutOfRangeError exception has been catched. However, why there is still so many "out of range" warnings after Step 159?</p>