我有一个存储8000个火车样本的TFRecords文件。我将其加载到文件名队列并将num_epoches
设置为2
,以便将16000个样本排入队列。同时,我将batch_size
设置为100,因此在队列变空之前应该迭代160次。
...
...
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()
然而,当我真正运行训练代码时,我得到了以下日志:
...
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
你知道,因为'做了'被打印,这意味着已经捕获了OutOfRangeError异常。但是,为什么还有这么多"超出范围"步骤159后的警告?