print("Overall Accuracy is: %.02f\n" %(vqaEval.accuracy['overall'])) print("Per Question Type Accuracy is the following:") for quesType in vqaEval.accuracy['perQuestionType']: print("%s : %.02f" %(quesType, vqaEval.accuracy['perQuestionType'][quesType])) print("\n") print("Per Answer Type Accuracy is the following:") for ansType in vqaEval.accuracy['perAnswerType']: print("%s : %.02f" %(ansType, vqaEval.accuracy['perAnswerType'][ansType])) print("\n") # demo how to use evalQA to retrieve low score result evals = [quesId for quesId in vqaEval.evalQA if vqaEval.evalQA[quesId]<35] #35 is per question percentage accuracy if len(evals) > 0: print('ground truth answers') randomEval = random.choice(evals) randomAnn = vqa.loadQA(randomEval) vqa.showQA(randomAnn) print('\n') print('generated answer (accuracy %.02f)'%(vqaEval.evalQA[randomEval])) ann = vqaRes.loadQA(randomEval)[0] print("Answer: %s\n" %(ann['answer'])) imgId = randomAnn[0]['image_id'] imgFilename = 'COCO_' + dataSubType + '_'+ str(imgId).zfill(12) + '.jpg' if os.path.isfile(imgDir + imgFilename): I = io.imread(imgDir + imgFilename) plt.imshow(I) plt.axis('off') plt.show() # plot accuracy for various question types
f3.close() exit(0) #gt_mat = gt_mat.astype(int) print(gt_mat.shape) np.savez("gt_mat.npy", gt_mat) exit(0) exit(0) exit(0) #randomAnn = random.choice(anns) ##print("HELLO1") #print(randomAnn) quest = vqa.showQA([randomAnn]) print("This is quest") print(quest) imgId = randomAnn['image_id'] image_feat = coco_train[imgId] print(image_feat) print(image_feat.shape) print(randomAnn['question_id']) imgFilename = 'COCO_' + dataSubType + '_' + str(imgId).zfill(12) + '.jpg' if os.path.isfile(imgDir + imgFilename): I = io.imread(imgDir + imgFilename) plt.imshow(I) plt.axis('off') plt.show() exit(0)
dataSubType) quesFile = '%s/Questions/%s_%s_%s_questions.json' % (dataDir, taskType, dataType, dataSubType) imgDir = '%s/%s/' % (dataDir, dataSubType) # initialize VQA api for QA annotations vqa = VQA(annFile, quesFile) # load and display QA annotations for given question types """ All possible quesTypes for abstract and mscoco has been provided in respective text files in ../QuestionTypes/ folder. """ annIds = vqa.getQuesIds(quesTypes='how many') anns = vqa.loadQA(annIds) randomAnn = random.choice(anns) vqa.showQA([randomAnn]) imgId = randomAnn['image_id'] imgFilename = 'COCO_' + dataSubType + '_' + str(imgId).zfill(12) + '.jpg' if os.path.isfile(imgDir + imgFilename): I = io.imread(imgDir + imgFilename) plt.imshow(I) plt.axis('off') plt.show() # load and display QA annotations for given answer types """ ansTypes can be one of the following yes/no number other """
dataSubType = "train2014" annFile = "%s/Annotations/%s_%s_annotations.json" % (dataDir, dataType, dataSubType) quesFile = "%s/Questions/%s_%s_%s_questions.json" % (dataDir, taskType, dataType, dataSubType) imgDir = "%s/Images/%s/%s/" % (dataDir, dataType, dataSubType) # initialize VQA api for QA annotations vqa = VQA(annFile, quesFile) # load and display QA annotations for given question types """ All possible quesTypes for abstract and mscoco has been provided in respective text files in ../QuestionTypes/ folder. """ annIds = vqa.getQuesIds(quesTypes="how many") anns = vqa.loadQA(annIds) randomAnn = random.choice(anns) vqa.showQA([randomAnn]) imgId = randomAnn["image_id"] imgFilename = "COCO_" + dataSubType + "_" + str(imgId).zfill(12) + ".jpg" if os.path.isfile(imgDir + imgFilename): I = io.imread(imgDir + imgFilename) plt.imshow(I) plt.axis("off") plt.show() # load and display QA annotations for given answer types """ ansTypes can be one of the following yes/no number other """