mindspore.dataset.Dataset.repeat
- mindspore.dataset.Dataset.repeat(count=None)[源代码]
重复此数据集 count 次。如果 count 为
None
或-1
,则无限重复迭代。说明
repeat和batch的顺序反映了batch的数量。建议:repeat操作在batch操作之后使用。
- 参数:
count (int) - 数据集重复的次数。默认值:
None
。
- 返回:
Dataset,应用了上述操作的新数据集对象。
样例:
>>> import mindspore.dataset as ds >>> >>> # Create a dataset with 10 elements >>> dataset = ds.GeneratorDataset([i for i in range(10)], "column1") >>> ori_size = dataset.get_dataset_size() >>> >>> # Repeat the dataset 50 times. >>> dataset = dataset.repeat(50) >>> repeated_size = dataset.get_dataset_size() >>> print("ori_size", ori_size, ", repeated_size", repeated_size) ori_size 10 , repeated_size 500 >>> >>> # Since the original dataset size is less than batch_size, thus no data is returned >>> dataset1 = ds.GeneratorDataset([i for i in range(10)], "column1") >>> dataset1 = dataset1.batch(batch_size=20, drop_remainder=True) >>> dataset1 = dataset1.repeat(6) >>> >>> # Repeat the original dataset to 60 elements, thus 3 batches are returned >>> dataset2 = ds.GeneratorDataset([i for i in range(10)], "column1") >>> dataset2 = dataset2.repeat(6) >>> dataset2 = dataset2.batch(batch_size=20, drop_remainder=True) >>> print("dataset1 size", dataset1.get_dataset_size(), ", dataset2 size", dataset2.get_dataset_size()) dataset1 size 0 , dataset2 size 3