How can I return the same batch twice from a tensorflow dataset iterator?

三世轮回 提交于 2019-12-05 12:53:00

You can repeat individual elements of a Dataset using Dataset.flat_map(), Dataset.from_tensors() and Dataset.repeat() together. For example, to repeat elements twice:

NUM_REPEATS = 2
dataset = tf.data.Dataset.range(10)  # ...or the output of `.batch()`, etc.

# Repeat each element of `dataset` NUM_REPEATS times.
dataset = dataset.flat_map(
    lambda x: tf.data.Dataset.from_tensors(x).repeat(NUM_REPEATS))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!