Dodon commited on
Commit
a0c7aa6
·
1 Parent(s): e4c98f7

Update PlotQA_dataset.py

Browse files
Files changed (1) hide show
  1. PlotQA_dataset.py +22 -16
PlotQA_dataset.py CHANGED
@@ -139,23 +139,23 @@ class PlotQA(datasets.GeneratorBasedBuilder):
139
  ),
140
  ]
141
 
142
- def find_qa(self, annotation_v1_path:str, annotation_v2_path:str, img_idx:int):
143
- with open(annotation_v1_path, "r", encoding="utf-8") as v1:
144
- data_v1 = json.load(v1)
145
 
146
- with open(annotation_v2_path, "r", encoding="utf-8") as v2:
147
- data_v2 = json.load(v2)
148
 
149
- #1.
150
- version = 1
151
- _temp_item = []
152
- for ele in data_v1:
153
- if ele['image_index'] == img_idx:
154
- _temp_item.append(ele)
155
- for ele in data_v2:
156
- if ele['image_index'] == img_idx:
157
- _temp_item.append(ele)
158
- return _temp_item
159
 
160
  def _generate_examples(self, annotation_v1_path:str, annotation_v2_path:str, img_anno_path:str ,images_path: str):
161
  #Load image folder
@@ -165,6 +165,8 @@ class PlotQA(datasets.GeneratorBasedBuilder):
165
  ## file.extractall('./imgs')
166
  ## file.close()
167
  _multi_anno = [annotation_v1_path, annotation_v2_path]
 
 
168
 
169
  idx = 0
170
  with open(img_anno_path, "r", encoding="utf-8") as a:
@@ -175,7 +177,11 @@ class PlotQA(datasets.GeneratorBasedBuilder):
175
  item["imgname"] = str(ele['image_index'])+'.png'
176
  # item['image'] = os.path.join('./imgs',item['imgname'])
177
  item["query_token"] = []
178
- qa_returns = find_qa(annotation_v1_path,annotation_v2_path, item['image_index'])
 
 
 
 
179
  _question = []
180
  _label = []
181
  for pair in qa_returns:
 
139
  ),
140
  ]
141
 
142
+ # def find_qa(self, annotation_v1_path:str, annotation_v2_path:str, img_idx:int):
143
+ # with open(annotation_v1_path, "r", encoding="utf-8") as v1:
144
+ # data_v1 = json.load(v1)
145
 
146
+ # with open(annotation_v2_path, "r", encoding="utf-8") as v2:
147
+ # data_v2 = json.load(v2)
148
 
149
+ # #1.
150
+ # version = 1
151
+ # _temp_item = []
152
+ # for ele in data_v1:
153
+ # if ele['image_index'] == img_idx:
154
+ # _temp_item.append(ele)
155
+ # for ele in data_v2:
156
+ # if ele['image_index'] == img_idx:
157
+ # _temp_item.append(ele)
158
+ # return _temp_item
159
 
160
  def _generate_examples(self, annotation_v1_path:str, annotation_v2_path:str, img_anno_path:str ,images_path: str):
161
  #Load image folder
 
165
  ## file.extractall('./imgs')
166
  ## file.close()
167
  _multi_anno = [annotation_v1_path, annotation_v2_path]
168
+ with (_multi_anno, "r", encoding="utf-8") as v:
169
+ data = json.load(v)
170
 
171
  idx = 0
172
  with open(img_anno_path, "r", encoding="utf-8") as a:
 
177
  item["imgname"] = str(ele['image_index'])+'.png'
178
  # item['image'] = os.path.join('./imgs',item['imgname'])
179
  item["query_token"] = []
180
+ _temp_item = []
181
+ for element in data_v1:
182
+ if element['image_index'] == ele['image_index']:
183
+ _temp_item.append(element)
184
+ #qa_returns = find_qa(annotation_v1_path,annotation_v2_path, item['image_index'])
185
  _question = []
186
  _label = []
187
  for pair in qa_returns: