-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVQA_RAD.py
53 lines (40 loc) · 1.5 KB
/
VQA_RAD.py
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
import pandas as pd
import torch
import os
from dataset.VQAFeatureDataset import VQADataset
qtype_map = {
"PRES": "Presence",
"ABN": "Abnormality",
"MODALITY": "Modality",
"ORGAN": "Organ",
"PLANE": "Plane",
"OTHER": "Other",
"SIZE": "Size",
"ATTRIB": "Attribute",
"COLOR": "Color",
"ATRIB": "Attribute",
"PRSE": "Presence",
"POS": "Position",
"COUNT": "Quantity",
"Other": "Other"
}
class VQARADFeatureDataset(VQADataset):
def __init__(self, name, dataroot, device = "cuda" if torch.cuda.is_available() else "cpu"):
super(VQARADFeatureDataset, self).__init__(name , dataroot, device)
def _load_dataset(sself, dataroot, name):
data_path = os.path.join(dataroot, f'{name}.json')
samples_all = pd.read_json(data_path)
entries = []
for idx, entry in samples_all.iterrows():
for qtype in entry["question_type"].split(", "):
sample = {'image_name' : entry['image_name'],
'question_id': str(entry['qid']),
'question': entry['question'].lower(),
'answer' : str(entry['answer']).lower(),
'task': qtype_map[qtype],
'question_type': entry['answer_type'].lower()}
# Some typos in dataset:
if sample['question_type'] == 'closed ':
sample['question_type'] = 'closed'
entries.append(sample)
return entries