NIfTI Segmentation Dataset to Image Dataset for SegFormer

I’m attempting to convert my local custom dataset to a HF dataset to use to be used as in this SegFormer tutorial. I’ve followed this thread to attempt dataset creation, but have yet to find any method to convert from NIfTI formats to Image & Dataset formats.

I’d greatly appreciate any advice on working with NIfTI formats and making the dataset compatible for later use on the SegFormer tutorial.

My current dataset is of the following format:

Patient-1:
    1-Flair.nii
    1-LesionSeg-Flair.nii
Patient-2:
    2-Flair.nii
    2-LesionSeg-Flair.nii

where files ending in Flair are MRI images, and ones ending in LesionSeg-Flair are the corresponding segmentations. My previous attempt uses the following structure:

image_paths = sorted([f for f in glob.glob(os.path.join(data_dir, "Patient-*/*-Flair.nii")) if "LesionSeg-Flair" not in f])  # don't over include
label_paths = sorted(glob.glob(os.path.join(data_dir, "Patient-*/*-LesionSeg-Flair.nii")))


def create_dataset(image_paths, label_paths):
    dataset = Dataset.from_dict({"image": 'image_paths??', "label": "label_paths??"})
    dataset = dataset.cast_column("image", Image('???'))
    dataset = dataset.cast_column("label", Image('???'))
    return dataset


dataset = DatasetDict({
    "train": create_dataset(image_paths, label_paths), 
})