File size: 564 Bytes
82c6e06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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