how can I ues Dataset to shuffle a large whole dataset?

本文介绍了一种适用于大规模数据集的外部内存洗牌方法。该方法首先使用MapReduce/Spark/Beam等工具对整个数据集进行一次随机洗牌,并将其拆分成大致相等大小的文件(碎片)。随后,在每个训练周期内,通过随机洗牌文件名列表并使用tf.data API将不同碎片中的记录混合,最后再对组合后的数据集进行洗牌。

The Dataset.shuffle() implementation is designed for data that could be shuffled in memory; we're considering whether to add support for external-memory shuffles, but this is in the early stages. In case it works for you, here's the usual approach we use when the data are too large to fit in memory:

Randomly shuffle the entire data once using a MapReduce/Spark/Beam/etc. job to create a set of roughly equal-sized files ("shards").
In each epoch:

  1. Randomly shuffle the list of shard filenames, using Dataset.list_files(...).shuffle(num_shards).
  2. Use dataset.interleave(lambda filename: tf.data.TextLineDataset(filename), cycle_length=N) to mix together records from N different shards.
  3. Use dataset.shuffle(B) to shuffle the resulting dataset. Setting B might require some experimentation, but you will probably want to set it to some value larger than the number of records in a single shard.

转载于:https://www.cnblogs.com/crackpotisback/p/9227523.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值