| 27 | |
| 28 | |
| 29 | class CocoCapDataset(Dataset): |
| 30 | def __init__(self) -> None: |
| 31 | super().__init__() |
| 32 | self.datas = json.load(open('datasets/Eval/image/coco_cap/coco_karpathy_val.json')) |
| 33 | |
| 34 | def __len__(self): |
| 35 | return len(self.datas) |
| 36 | |
| 37 | def __getitem__(self, index): |
| 38 | data = self.datas[index] |
| 39 | image_path = os.path.join("datasets/InstructionTuning/image/coco/", data['image']) |
| 40 | image = Image.open(image_path).convert('RGB') |
| 41 | image = T_resized_center_crop(image) |
| 42 | image_id = int(data['image'].split('_')[-1].split('.')[0]) |
| 43 | question = 'Provide a one-sentence caption for the provided image.' |
| 44 | return image, question, image_id |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |