def _load_answer_type(self, quest_ids): answer_type_file = 'data/%sanswer_type_std_mscoco_%s.data' % ( self._version_suffix, self._subset) if not os.path.exists(answer_type_file): _mc_ctx = MultiChoiceQuestionManger(subset='val') answer_type_ids = [ _mc_ctx.get_answer_type_coding(quest_id) for quest_id in quest_ids ] answer_type_ids = np.array(answer_type_ids, dtype=np.int32) save_hdf5( answer_type_file, { 'answer_type': answer_type_ids, 'quest_ids': np.array(quest_ids, dtype=np.int32) }) else: d = load_hdf5(answer_type_file) answer_type_ids = d['answer_type'] self._answer_type = answer_type_ids
def load_vqa_predictions(subset): data_file = '../iccv_vaq/data/sparse_vqa_scores_%s_0.h5' % subset data_file = '../iccv_vaq/data/sparse_vqa_scores_dev_5nogt.h5' d = load_hdf5(data_file) quest_ids = d['quest_ids'] pdb.set_trace() mc_ctx = MultiChoiceQuestionManger(subset='val', load_ans=True) type_labels = [] for qid in quest_ids: coding = mc_ctx.get_answer_type_coding(qid) type_labels.append(coding) type_labels = np.array(type_labels) unique_ids = np.unique(type_labels) print(np.bincount(type_labels)) valid_types = [u'other', u'number', u'yes/no'] yes_no_id = mc_ctx._answer_type2id['yes/no'] # yes_no_id = mc_ctx._answer_type2id['other'] # yes_no_id = mc_ctx._answer_type2id['number'] is_yes_no = type_labels == yes_no_id candidates = d['top_k_index'][:, :3] num_yes_no = is_yes_no.sum() num_tot = candidates.shape[0] print('Yes/No: %d in %d' % (num_yes_no, num_tot)) yes_top_ans_id = 0 no_top_ans_id = 1 yes_no_cands = candidates[is_yes_no] has_yes = (yes_no_cands == yes_top_ans_id).sum(axis=1) == 1 print(has_yes.sum()) has_no = (yes_no_cands == no_top_ans_id).sum(axis=1) == 1 print(has_no.sum()) yn_inter = np.logical_and(has_yes, has_no) yn_union = np.logical_or(has_yes, has_no) print('Either yes/no %d:' % yn_union.sum()) print('Both yes/no %d:' % yn_inter.sum())