# NIfTI Segmentation Dataset to Image Dataset for SegFormer

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnifti-segmentation-dataset-to-image-dataset-for-segformer%2F83069%3E%5C
**Category:** 🤗Datasets\
**Created:** [April 22, 2024, 9:31am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnifti-segmentation-dataset-to-image-dataset-for-segformer%2F83069 "2024-04-22T09:31:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexwang05](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alexwang05/32/26087_2.png) [@alexwang05](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Falexwang05)%5C
**Post date:** [April 22, 2024, 9:31am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnifti-segmentation-dataset-to-image-dataset-for-segformer%2F83069%2F1 "2024-04-22T09:31:48Z")

</div>

I’m attempting to convert my local custom dataset to a HF dataset to use to be used as in [this SegFormer tutorial](https://huggingface.co/blog/fine-tune-segformer). I’ve followed [this thread](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-i-create-a-image-segmentation-dataset%2F23123) 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:

```auto
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:

```auto
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), 
})

```
