torchdata.samplers¶
This module implements samplers to be used in conjunction with torch.utils.data.DataLoader instances.
Those can be used just like PyTorch’s torch.utils.data.Sampler instances.
See PyTorch tutorial for more examples and information.
-
class
torchdata.samplers.Distribution(distribution: torch.distributions.distribution.Distribution, num_samples: int)[source]¶ Sample
num_samplesindices from distribution object.- Parameters
distribution (torch.distributions.distribution.Distribution) – Distribution-like object implementing
sample()method.num_samples (int) – Number of samples to be yielded
-
class
torchdata.samplers.RandomOverSampler(labels)[source]¶ Sample elements randomly with underrepresented classes upsampled.
Length is equal to
max_samples_per_class * classes.- Parameters
labels (torch.Tensor) – Tensor containing labels for respective samples.
-
class
torchdata.samplers.RandomSubsetSampler(indices, replacement=False, num_samples=None)[source]¶ Sample elements randomly from a given list of indices.
If without
replacement, then sample from a shuffled dataset. If with replacement, then user can specifynum_samplesto draw.Similar to PyTorch’s
SubsetRandomSampler, but this one allows you to specifyindiceswhich will be sampled in random order, notrangesubsampled.- Parameters
indices (typing.Iterable) – A sequence of indices
replacement (bool, optional) – Samples are drawn with replacement if
True. Default:Falsenum_samples (int, optional) – Number of samples to draw, default=`len(dataset)`. This argument is supposed to be specified only when
replacementisTrue. Default:None