Datasets:

Modalities:
Image
Text
Formats:
parquet
Libraries:
Datasets
pandas
File size: 2,047 Bytes
c1d9547
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import csv
import datasets
from PIL import Image
import pandas as pd


class MyDataset(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            description="Dataset containing medical images with associated questions and answers.",
            features=datasets.Features({
                "image": datasets.Image(),
                "source": datasets.Value("string"),
                "question": datasets.Value("string"),
                "answer": datasets.Value("string"),
                "img_id": datasets.Value("string"), }),
            supervised_keys=None,
        )

    def _split_generators(self, dl_manager):
        df = pd.read_csv(os.path.join(self.config.data_dir, "gt.csv"),
                         delimiter=";")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={"df": df,
                            "images_dir": os.path.join(self.config.data_dir, "data")}
            )
        ]

    def _generate_examples(self, df, images_dir):
        #  iterate df
        for idx, row in df.iterrows():
            img_id = row.get("img_id")
            if not img_id:
                continue  # Skip rows without a valid image identifier
            image_path = os.path.join(images_dir, f"{img_id}")
            if not os.path.exists(image_path):
                continue  # Skip if image file does not exist
            yield idx, {
                "image": image_path,
                "source": row["source"],
                "question": row["question"],
                "answer": row["answer"],
                "img_id": img_id.split(".")[0],
            }

#  MedVQA_test_cli.py
# from datasets import load_dataset

# dataset = load_dataset(
#     "/Users/sgautam/Documents/MedVQA/MedVQA_test.py", data_dir="/Users/sgautam/Downloads/kvasir_vqa_test/", trust_remote_code=True)
# dataset.push_to_hub("SimulaMet/Kvasir-VQA-test", private=False)
# breakpoint()

# then
#  python MedVQA_test_cli.py