That code works for me as well. I believe it had something to do with the WeightedRandomSampler from my previous post DataLoader - using SubsetRandomSampler and WeightedRandomSampler at the same time 11. The variable index of the __getitem__ method is a tensor for the code when I make use of the WeightedRandomSampler. Thank you.