Skip to content

Instantly share code, notes, and snippets.

@hanxiao
Created July 5, 2018 01:55
Show Gist options
  • Save hanxiao/c210f9e232db50167228bc67e2700e34 to your computer and use it in GitHub Desktop.
Save hanxiao/c210f9e232db50167228bc67e2700e34 to your computer and use it in GitHub Desktop.
Interleaving multiple datasets
datasets = [tf.data.Dataset...]
def concat_datasets(datasets):
ds0 = tf.data.Dataset.from_tensors(datasets[0])
for ds1 in datasets[1:]:
ds0 = ds0.concatenate(tf.data.Dataset.from_tensors(ds1))
return ds0
ds = tf.data.Dataset.zip(tuple(datasets)).flat_map(
lambda *args: concat_datasets(args)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment