File size: 1,083 Bytes
f749037
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from datasets import Dataset, Features, Value
import os
import nibabel as nib

# Define the paths to your raw data files
raw_data_path = './data/raw'

# Function to load NIfTI files
def load_nifti(file_path):
    nifti = nib.load(file_path)
    return nifti.get_fdata()

# Create a list to hold the data
data = []

# Iterate over the files in the raw data directory
for file_name in os.listdir(raw_data_path):
    if file_name.endswith('.nii.gz'):
        file_path = os.path.join(raw_data_path, file_name)
        data.append({
            'file_name': file_name,
            'data': load_nifti(file_path).tolist()  # Convert to list for serialization
        })

# Define the features of the dataset
features = Features({
    'file_name': Value('string'),
    'data': Value('float32', id='data')
})

# Create Dataset object
dataset = Dataset.from_dict({'file_name': [d['file_name'] for d in data], 'data': [d['data'] for d in data]}, features=features)

if __name__ == "__main__":
    # Push the dataset to Hugging Face
    dataset.push_to_hub("ashutosh-pathak/liver-segmentation")