Download model/training_data/data_processor.py from tmmdev2/llama-vision-charts: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/tmmdev2/llama-vision-charts/resolve/6bc470863fb182e458f376beea2e6ff8ea95fe4e/model/training_data/data_processor.py
- Command line
-
hf download hf://tmmdev2/llama-vision-charts@6bc470863fb182e458f376beea2e6ff8ea95fe4e/model/training_data/data_processor.py
-
curl -L -o data_processor.py https://huggingface.co/tmmdev2/llama-vision-charts/resolve/6bc470863fb182e458f376beea2e6ff8ea95fe4e/model/training_data/data_processor.py
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 | |