llama-vision-charts / model /training_data /data_processor.py
tmmdev2's picture
Add files using upload-large-folder tool
60a2572 verified
Raw History Blame
594 Bytes
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