Using the Dataset 2 class, you can lazily load your images in the __getitem__ method.
Here is a small example:
class TrainDataset(Dataset):
    def __init__(self, image_paths, targets):
        self.image_paths = image_paths
        self.targets = targets

    def __getitem__(self, index):
        image = Image.open(self.image_paths[index])
        y = self.target[index]

        # Resize your image here
        if image.size...:
            ....
        .... # Do other stuff here

        x = torch.from_numpy(image)
    
        return x, y

    def __len__(self):
        return len(self.image_paths)

You can wrap your Dataset to a DataLoader 3 for efficient loading, preprocessing, shuffling etc.
Hope this helps!