Subset

class torchelie.datasets.Subset(ds, ratio=None, num_indices=None, remap_unused_classes=False, seed=None, include=True)

Create a subset that is a random ratio of a dataset.

Parameters
  • ds (Dataset) – the dataset to sample from. Must have a .samples member like torchvision’s datasets.

  • ratio (float, optional) – a value between 0 and 1, the subsampling ratio. Can’t be specified if num_indices is already set.

  • num_indices (int, optional) – how many indices to include/exclude. Can’t be set if ratio is set.

  • remap_unused_classes (boolean) – if True, classes not represented in the subset will not be considered. Remaining classes will be numbered from 0 to N.

  • seed (int, optional) – if provided, sampling will be made deterministically from this seed.

  • include (bool) – if True, keep sampled indices, otherwise, exclude sampled indices. Can be used for creating mutually exclusive sets if seed is provided.

Take 10% of a dataset:

set_10pct = Subset(dataset, ratio=0.1)

Take a deterministic 10% of a dataset:

set_10pct = Subset(dataset, ratio=0.1, seed=42)

Split a dataset in 10%/90% (mutually exclusive):

:code:` set_90pct = Subset(dataset, ratio=0.9, seed=42, include=True) set_10pct = Subset(dataset, ratio=0.9, seed=42, include=False) `