File size: 594 Bytes
60a2572
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import pandas as pd
from PIL import Image
import torch
from torch.utils.data import Dataset

class ChartDataset(Dataset):
    def __init__(self, image_dir, annotations_file):
        self.image_dir = image_dir
        self.annotations = pd.read_csv(annotations_file)
        
    def __len__(self):
        return len(self.annotations)
        
    def __getitem__(self, idx):
        img_path = f"{self.image_dir}/{self.annotations.iloc[idx]['image_name']}"
        image = Image.open(img_path)
        label = self.annotations.iloc[idx]['label']
        return image, label