In [1]:
import random
import os
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from vqatools.visual7w import Visual7wPoint,Visual7wTell

Pointing task


In [2]:
v7wpoint = Visual7wPoint('visual7w/dataset_v7w_pointing.json')
v7wpoint.info()


=======  Visual7W-pointing 1.0  ======= 

In [5]:
outqids = v7wpoint.imgidtoqid[2359297]

In [7]:
for qid in outqids:
    qa = v7wpoint.qidtoqa[qid]
    answer_boxid = qa.get('answer')
    box = v7wpoint.boxidtobox[answer_boxid]
    print (box.get('x'),box.get('y'),box.get('height'),box.get('width'))
#     print (qa)
#     print ()


372 66 153 128
2 4 97 133
372 66 153 128
193 258 57 130
329 212 93 105
193 258 57 130
1 1 143 183
329 212 93 105
216 48 79 109
0 136 44 76
0 136 44 76
216 48 79 109

In [4]:
v7wpoint.boxidtobox[794494]


Out[4]:
{'box_id': 794494,
 'height': 153,
 'name': 'door',
 'width': 128,
 'x': 372,
 'y': 66}

In [5]:
v7wpoint.showQA(265555)


Multiple choices:  [794491, 794496, 794488]
Img id:  2359297
Which door is behind a person sitting on a bench?
Ans:  794494

In [8]:
v7wpoint.boxidtobox[794494]


Out[8]:
{'box_id': 794494,
 'height': 153,
 'name': 'door',
 'width': 128,
 'x': 372,
 'y': 66}

In [9]:
v7wpoint.boxidtobox[794491]


Out[9]:
{'box_id': 794491,
 'height': 57,
 'name': 'shadow',
 'width': 130,
 'x': 193,
 'y': 258}

In [6]:
v7wpoint.qidtoqa[265555]


Out[6]:
{'answer': 794494,
 'image_id': 2359297,
 'multiple_choices': [794491, 794496, 794488],
 'qa_id': 265555,
 'question': 'Which door is behind a person sitting on a bench?',
 'type': 'which'}

Telling task


In [11]:
v7wtell = Visual7wTell('visual7w/dataset_v7w_telling.json')
v7wtell.info()


=======  Visual7W-telling 1.1  ======= 

In [7]:
# howques = getQuesIds(quesType='how')
countques = v7wtell.getCountquesids()
print ("ther are %d count questions" %(len(countques)))
v7wtell.showQA(random.choice(countques))


ther are 15534 count questions
Img id:  2373666
How many bears are there?
Ans:  2.