tensorplay.utils.data.sampler
Classes
class BatchSampler [source]
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): IfTrue, the sampler will drop the last batch if its size would be less thanbatch_size
Example
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]
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 ifTrue, default=False - num_samples (
int): number of samples to draw, default=len(dataset). This argument is supposed to be specified only whenreplacementisTrue. - 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]
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]
SequentialSampler(data_source)Bases: Sampler
Samples elements sequentially, always in the same order.
Arguments
- data_source (
Dataset): dataset to sample from
