【发布时间】:2015-12-19 14:36:25
【问题描述】:
在Tensorflow reading data tutorial 中给出了一个示例输入管道。在该管道中,数据被洗牌两次,在string_input_producer 和shuffle batch generator 中。代码如下:
def input_pipeline(filenames, batch_size, num_epochs=None):
# Fist shuffle in the input pipeline
filename_queue = tf.train.string_input_producer(
filenames, num_epochs=num_epochs, shuffle=True)
example, label = read_my_file_format(filename_queue)
min_after_dequeue = 10000
capacity = min_after_dequeue + 3 * batch_size
# Second shuffle as part of the batching.
# Requiring min_after_dequeue preloaded images
example_batch, label_batch = tf.train.shuffle_batch(
[example, label], batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
return example_batch, label_batch
第二次洗牌有什么用处吗? shuffle 批处理生成器的缺点是min_after_dequeue 示例总是预先加载在内存中以允许有用的 shuffle。我确实有图像数据,这在内存消耗方面非常重要。这就是为什么我考虑改用normal batch generator。将数据洗牌两次有什么好处吗?
编辑:附加问题,为什么 string_input_producer 仅使用默认容量 32 初始化?将 batch_size 的倍数作为容量不是很有利吗?
【问题讨论】:
标签: python tensorflow