Kossisoroyce's picture
Upload folder using huggingface_hub
82c6e06 verified
raw
history blame contribute delete
564 Bytes
from datasets import Dataset, Image
import pandas as pd
import os
def load_dataset():
df = pd.read_csv('Comprehensive_Metadata.csv')
def load_image(example):
label = 'NORMAL' if example['Label'] == 'Normal' else 'PNEUMONIA'
image_path = f'Xray-images/{example["Dataset_type"]}/{label}/{example["X_ray_image_name"]}'
if os.path.exists(image_path):
example['image'] = Image.open(image_path)
return example
dataset = Dataset.from_pandas(df)
dataset = dataset.map(load_image)
return dataset