Skip to content

repeat

Dataset wrapper that lengthens an epoch by repeating an underlying dataset.

Classes:

  • RepeatDataset –

    Repeats a dataset k times so one epoch iterates it k times.

  • RepeatSampler –

    Draws every sample of a dataset its own number of times per epoch.

RepeatDataset [source] ΒΆ

RepeatDataset(dataset: Dataset, k: int)

Bases: Dataset

Repeats a dataset k times so one epoch iterates it k times.

Lengthens an epoch (and thus the number of optimizer steps per epoch) without otherwise changing training.

Parameters:

  • dataset (Dataset) –

    The dataset to repeat.

  • k (int) –

    Number of times the dataset is iterated per epoch.

RepeatSampler [source] ΒΆ

RepeatSampler(
    counts: Sequence[int],
    shuffle: bool = True,
    generator: Optional[Generator] = None,
)

Bases: Sampler[int]

Draws every sample of a dataset its own number of times per epoch.

An epoch yields index \(i\) counts[i] times, shuffled unless shuffle is off, so unevenly sized samples can be visited in proportion to their size (large scenes more often than small ones).

Parameters:

  • counts (Sequence[int]) –

    Number of draws per epoch of every sample, one non-negative count per dataset index.

  • shuffle (bool, default: True ) –

    Shuffle the draws; False yields them grouped by sample, in index order.

  • generator (Optional[Generator], default: None ) –

    Random generator of the shuffle; None uses the global one.

Example
>>> sampler = RepeatSampler([2, 0, 3, 1], shuffle=False)
>>> list(sampler)
[0, 0, 2, 2, 2, 3]
>>> len(sampler)
6