epoch设置过小导致OutOfRangeError

在通过读取TFRecod文件,形成batch数据训练时,为什么提示如下错误 OutOfRangeError (see above for traceback): RandomShuffleQueue ‘_2_shuffle_batch/random_shuffle_queue’ is closed and has insufficient elements (requested 2, current size 0

image_batch, label_batch = tf.train.shuffle_batch([images, labels], 
			                                              batch_size = batchsize, 
			                                              capacity = capacity, 
			                                              min_after_dequeue = min_after_dequeue)

错误提示: OutOfRangeError (see above for traceback): RandomShuffleQueue ‘_2_shuffle_batch/random_shuffle_queue’ is closed and has insufficient elements (requested 2, current size 0) [Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"]] [[Node: shuffle_batch/_17 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name=“edge_20_shuffle_batch”, tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

这个问题的原因是:我只有一个TFRecord数据文件,其中样本数仅1500个。并且因为epoch设置过小,在开始训练前就把数据读完退出了。可以加大样本数量,或者把epoch设置的大一些,如果设置成Nnoe,程序会无限制地一直跑下去,当然你可以在结果足够好的时候手动中断程序的运行。
下面一行代码中,原num_epochs = 3 , 出现上述错误。将num_epochs 改为 10 即可正常运行。没有测试最小可设置多少。
不过问题是如何计算出准确的 num_epochs 值呢?

filename_queue = tf.train.string_input_producer([tfr_filename], shuffle = False, num_epochs = 10)

你可能感兴趣的:(Tensor,Flow)