class VideoQuality_torchResize(Dataset):

    def __init__(self,imagelist,transform=None):

        with open(imagelist) as f:

            self.lines = f.readlines()

            self.transform = transform

          

    def __len__(self):

        return len(self.lines)

    

    def __getitem__(self,index):

        if '\t' in self.lines[index]:

            imgPath,label = self.lines[index].split('\t')

        else:

            imgPath,label = self.lines[index].split(' ')

        label = int(label.split('\n')[0])

        img = cv2.imread(imgPath)[...,::-1]

        if self.transform is not None:

            img = self.transform(img)

        return img,label,imgPath


You can add you transform in the customdataset class like this
Then when you are creating your dataset its simply

train_dataset = VideoQuality_torchResize(trainlist,transform = trainVal_transform)
Hope this solves your problem