Datasets:
Tasks:
Image Classification
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
1K - 10K
License:
Upload folder using huggingface_hub
Browse files- dataset.py +27 -0
dataset.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import Dataset, Image
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def load_dataset():
|
| 8 |
+
|
| 9 |
+
df = pd.read_csv('Comprehensive_Metadata.csv')
|
| 10 |
+
|
| 11 |
+
def load_image(example):
|
| 12 |
+
|
| 13 |
+
label = 'NORMAL' if example['Label'] == 'Normal' else 'PNEUMONIA'
|
| 14 |
+
|
| 15 |
+
image_path = f'Xray-images/{example["Dataset_type"]}/{label}/{example["X_ray_image_name"]}'
|
| 16 |
+
|
| 17 |
+
if os.path.exists(image_path):
|
| 18 |
+
|
| 19 |
+
example['image'] = Image.open(image_path)
|
| 20 |
+
|
| 21 |
+
return example
|
| 22 |
+
|
| 23 |
+
dataset = Dataset.from_pandas(df)
|
| 24 |
+
|
| 25 |
+
dataset = dataset.map(load_image)
|
| 26 |
+
|
| 27 |
+
return dataset
|