Datasets:

Modalities:
Image
Text
Formats:
parquet
Libraries:
Datasets
pandas
SushantGautam commited on
Commit
c1d9547
·
verified ·
1 Parent(s): 8612cf3

Upload MedVQA_test.py

Browse files
Files changed (1) hide show
  1. MedVQA_test.py +58 -0
MedVQA_test.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+ import datasets
4
+ from PIL import Image
5
+ import pandas as pd
6
+
7
+
8
+ class MyDataset(datasets.GeneratorBasedBuilder):
9
+ def _info(self):
10
+ return datasets.DatasetInfo(
11
+ description="Dataset containing medical images with associated questions and answers.",
12
+ features=datasets.Features({
13
+ "image": datasets.Image(),
14
+ "source": datasets.Value("string"),
15
+ "question": datasets.Value("string"),
16
+ "answer": datasets.Value("string"),
17
+ "img_id": datasets.Value("string"), }),
18
+ supervised_keys=None,
19
+ )
20
+
21
+ def _split_generators(self, dl_manager):
22
+ df = pd.read_csv(os.path.join(self.config.data_dir, "gt.csv"),
23
+ delimiter=";")
24
+ return [
25
+ datasets.SplitGenerator(
26
+ name=datasets.Split.VALIDATION,
27
+ gen_kwargs={"df": df,
28
+ "images_dir": os.path.join(self.config.data_dir, "data")}
29
+ )
30
+ ]
31
+
32
+ def _generate_examples(self, df, images_dir):
33
+ # iterate df
34
+ for idx, row in df.iterrows():
35
+ img_id = row.get("img_id")
36
+ if not img_id:
37
+ continue # Skip rows without a valid image identifier
38
+ image_path = os.path.join(images_dir, f"{img_id}")
39
+ if not os.path.exists(image_path):
40
+ continue # Skip if image file does not exist
41
+ yield idx, {
42
+ "image": image_path,
43
+ "source": row["source"],
44
+ "question": row["question"],
45
+ "answer": row["answer"],
46
+ "img_id": img_id.split(".")[0],
47
+ }
48
+
49
+ # MedVQA_test_cli.py
50
+ # from datasets import load_dataset
51
+
52
+ # dataset = load_dataset(
53
+ # "/Users/sgautam/Documents/MedVQA/MedVQA_test.py", data_dir="/Users/sgautam/Downloads/kvasir_vqa_test/", trust_remote_code=True)
54
+ # dataset.push_to_hub("SimulaMet/Kvasir-VQA-test", private=False)
55
+ # breakpoint()
56
+
57
+ # then
58
+ # python MedVQA_test_cli.py