You need to subclass a Datasetclass as follows:
from torch.utils import data
class custom_dataset(data.Dataset):
    def __init__(self,*args,**kwargs):
    """
    Custom arguments, up to you
    """
    self.data = list_of_paths
    def __getitem__(self, index):
        """
        Args:
            index (int): Index
        Returns:
            whatever you need
        """
        #  Here you have to code workload to open files or to do any kind of preprocessing.This function is submitted to multiprocessing.
       return load(self.data[index])
    def __len__(self):
        # Return amount of samples of your dataset.
        return len(self.data)

You need to define a class like the previous one, with init, getitem and len.
Len should return the amount of samples of your dataset, images in your case.
In init you define a list of paths, files, or whatever setup you need.
In getitem you have to load those files prviously enlisted and put all the workload there. This is, any preprocessing operation you have to run on the fly as this function is submitted to multiprocessing