Solved by tux in post #2 
              
              
                I found a solution : 
import torch.utils.data
class FilteredDataset(torch.utils.data.dataset.Dataset):
    def __init__(self, dataset, wanted_labels):
        self.parent = dataset
        indices = []
        for index, (img, lab) in enumerate(dataset):
            if lab == wanted_labels:
        …