One thing you can do is what I did here 2. You can randomly select image paths of 10 images of a particular class. After you have a list which has paths of these image files, you can define the rule in __getitem__. Dataloader will open the image on the fly using the path (by iterating over the list) and converting it into a tensor. You can have a look in the repo for more details. The concept is same.