mindspore.dataset.Dataset.repeat

Dataset.repeat(count=None)[source]

Repeat this dataset count times. Repeat infinitely if the count is None or -1.

Note

The order of using repeat and batch reflects the number of batches. It is recommended that the repeat operation is used after the batch operation.

Parameters

count (int) – Number of times the dataset is going to be repeated. Default: None.

Returns

Dataset, a new dataset with the above operation applied.

Examples

>>> 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