In tensorflow 2.0.0, this will work:
import tensorflow as tf
raw_dataset = tf.data.TFRecordDataset("input_file.tfrecord")
shards = 10
for i in range(shards):
writer = tf.data.experimental.TFRecordWriter(f"output_file-part-{i}.tfrecord")
writer.write(raw_dataset.shard(shards, i))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…