def read_vqa(vqa_dir, section):
ans = 'mscoco_%s2014_annotations.json' % section
with (vqa_dir / ans).open() as file_:
ans_data = json.load(file_)
answers_by_id = {}
for answer in ans_data['annotations']:
mca = answer['multiple_choice_answer']
answers_by_id[answer['question_id']] = mca
filename = ('MultipleChoice_mscoco_'
'%s2014_questions.json' % section)
with (vqa_dir / filename).open() as file_:
ques_data = json.load(file_)
for question in ques_data['questions']:
text = question['question']
ques_id = question['question_id']
options = question['multiple_choices']
yield text, options, answers_by_id[ques_id]
评论列表
文章目录