Could you change the __getitem__ to just return img_path and mask_paths?
Then you could observe your RAM usage and load the images outside the Dataset:
img_path, mask_path = dataset[0]
img = io.imread(img_path)
mask = io.imread(mask_path)