lines = tf.data.TextLineDataset(filenames=['aa']).batch(2)
# 用于动态的增长计数
counter = tf.data.experimental.Counter()
dataset = tf.data.Dataset.zip((counter, lines))
epochs = 3
for i in range(epochs):
for line in dataset:
print(line[0].numpy(), line[1].numpy())
print('End of epoch {}'.format(i))
结果如下
0 [b'aa' b'bb']
1 [b'cc' b'dd']
2 [b'ee']
End of epoch 0
0 [b'aa' b'bb']
1 [b'cc' b'dd']
2 [b'ee']
End of epoch 1
0 [b'aa' b'bb']
1 [b'cc' b'dd']
2 [b'ee']
End of epoch 2