mindspore.dataset.SubsetSampler
- class mindspore.dataset.SubsetSampler(indices, num_samples=None)[source]
- Samples the elements from a sequence of indices. - Parameters
- indices (Iterable) – A sequence of indices (Any iterable Python object but string). 
- num_samples (int, optional) – Number of elements to sample. Default: - None, which means sample all elements.
 
- Raises
- TypeError – If elements of indices are not of type number. 
- TypeError – If num_samples is not of type int. 
- ValueError – If num_samples is a negative value. 
 
 - Examples - >>> import mindspore.dataset as ds >>> indices = [0, 1, 2, 3, 4, 5] >>> >>> # creates a SubsetSampler, will sample from the provided indices >>> sampler = ds.SubsetSampler(indices) >>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir, ... num_parallel_workers=8, ... sampler=sampler) - add_child(sampler)[source]
- Add a sub-sampler for given sampler. The parent will receive all data from the output of sub-sampler sampler and apply its sample logic to return new samples. - Note - If a child sampler is added and it has a shuffle option, its value cannot be - Shuffle.PARTIAL. Additionally, the parent sampler's shuffle value must be- Shuffle.GLOBAL.
 - Parameters
- sampler (Sampler) – Object used to choose samples from the dataset. Only builtin samplers( - mindspore.dataset.DistributedSampler,- mindspore.dataset.PKSampler,- mindspore.dataset.RandomSampler,- mindspore.dataset.SequentialSampler,- mindspore.dataset.SubsetRandomSampler,- mindspore.dataset.WeightedRandomSampler) are supported.
 - Examples - >>> import mindspore.dataset as ds >>> sampler = ds.SequentialSampler(start_index=0, num_samples=3) >>> sampler.add_child(ds.RandomSampler(num_samples=4)) >>> dataset = ds.Cifar10Dataset(cifar10_dataset_dir, sampler=sampler) 
 - get_child()[source]
- Get the child sampler of given sampler. - Returns
- Sampler, The child sampler of given sampler. 
 - Examples - >>> import mindspore.dataset as ds >>> sampler = ds.SequentialSampler(start_index=0, num_samples=3) >>> sampler.add_child(ds.RandomSampler(num_samples=2)) >>> child_sampler = sampler.get_child()