Skip to content

tensorplay.utils.data.sampler

Classes

class BatchSampler [source]

python
BatchSampler(sampler, batch_size, drop_last)

Bases: Sampler

Wraps another sampler to yield a mini-batch of indices.

Args

  • sampler (Sampler): Base sampler.
  • batch_size (int): Size of mini-batch.
  • drop_last (bool): If True, the sampler will drop the last batch if its size would be less than batch_size

Example

python
list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=False))
    [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=True))
    [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
Methods

__init__(self, sampler, batch_size, drop_last) [source]

Initialize self. See help(type(self)) for accurate signature.


class RandomSampler [source]

python
RandomSampler(data_source, replacement=False, num_samples=None, generator=None)

Bases: Sampler

Samples elements randomly. If without replacement, then sample from a shuffled dataset. If with replacement, then user can specify num_samples to draw.

Arguments

  • data_source (Dataset): dataset to sample from
  • replacement (bool): samples are drawn on-demand with replacement if True, default=False
  • num_samples (int): number of samples to draw, default=len(dataset). This argument is supposed to be specified only when replacement is True.
  • generator (Generator): Generator used in sampling.
Methods

__init__(self, data_source, replacement=False, num_samples=None, generator=None) [source]

Initialize self. See help(type(self)) for accurate signature.


class Sampler [source]

python
Sampler(data_source: Optional[Sized])

Bases: Generic

Base class for all Samplers.

Every Sampler subclass has to provide an __iter__ method, providing a way to iterate over indices of dataset elements, and a __len__ method that returns the length of the returned iterators.

.. note:: The __len__ method isn't strictly required by ~torch.utils.data.DataLoader, but is expected in any calculation involving the length of a ~torch.utils.data.DataLoader.

Methods

__init__(self, data_source: Optional[Sized]) [source]

Initialize self. See help(type(self)) for accurate signature.


class SequentialSampler [source]

python
SequentialSampler(data_source)

Bases: Sampler

Samples elements sequentially, always in the same order.

Arguments

  • data_source (Dataset): dataset to sample from
Methods

__init__(self, data_source) [source]

Initialize self. See help(type(self)) for accurate signature.


Released under the Apache 2.0 License.

📚DeepWiki