Getting a subset(given their indices) of data from the data loader

I need to train my neural network on a selected subset of the FashionMNIST training dataset. The indices of these are known. How can I pass the indices to the DataLoader so the samples are generated only from these indices.

train_fm = torchvision.datasets.FashionMNIST("./data/",
                                             train=True,
                                             transform=
                                             torchvision.transforms.
                                             Compose
                                             ([torchvision.transforms.ToTensor()]
                                              ),
                                             target_transform=None,
                                             download=True)
train_loader = torch.utils.data.DataLoader(
    train_fm, batch_size=100
)

Can i use the sampler argument to get it done? How?
Thanks in advance :slight_smile:

The below solution is what I was looking for.:slight_smile:

train_loader_2 = torch.utils.data.DataLoader(
    train_fm, batch_size=100,
    sampler =  sampler.SubsetRandomSampler(<array containing indices>)
)
1 Like

thank you, friend! It worked for me too.