I would like to try that way but in advance why I am having this problem: RuntimeError: stack expects each tensor to be equal size, but got [512, 512, 533] at entry 0 and [512, 512, 661] at entry 1
I didn`t change the code I just deleted the for part…
class TrainSet(Dataset):
    def __init__(self, image_dir, mask_dir):
        self.image_dir = image_dir
        self.mask_dir = mask_dir
        self.images = os.listdir(image_dir)
        self.masks = os.listdir(mask_dir)

    def __getitem__(self, index):
        img_path = os.path.join(self.image_dir, self.images[index])
        mask_path = os.path.join(self.mask_dir, self.masks[index])
        image = nibabel.load(img_path)
        img = image.get_fdata()
        mask, _ = nrrd.read(mask_path)



        return img, mask

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