What is the format of your dataset? I think you should be able to make the necessary changes in the dataset class. Instead of loading the images/labels from the directory, load the 3d dataset (np.array() or .nii) and then crop the no. of slices accordingly depending upon your memory.