The second one is actually the way that -for example- ImageFolder dataset class load the images. So, the best practice is load the path directory where your images are ( for example with os.listdir() ) , and load the image in __getitem__ method