mindspore.dataset.SubsetRandomSampler
- class mindspore.dataset.SubsetRandomSampler(indices, num_samples=None)[source]
Samples the elements randomly 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. Used to partially extract samples obtained through sampling. 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, 7, 88, 119] >>> >>> # create a SubsetRandomSampler, will sample from the provided indices >>> sampler = ds.SubsetRandomSampler(indices) >>> data = ds.ImageFolderDataset(image_folder_dataset_dir, num_parallel_workers=8, sampler=sampler)