def GetAllQAs(dataDir=None): if dataDir is None: dataDir = utils.GetDataDir() dataFile = os.path.join(dataDir, 'question_answers.json') imageData = GetAllImageData(dataDir) imageMap = {} for d in imageData: imageMap[d.id] = d images = json.load(open(dataFile)) output = [] for image in images: output.append(utils.ParseQA(image['qas'], imageMap)) return output
def GetQAofImage(id=61512): page = 1 next = '/api/v0/image/' + str(id) + '/qa?page=' + str(page) qas = [] image_map = {} while True: data = utils.RetrieveData(next) for d in data['results']: if d['image'] not in image_map: image_map[d['image']] = GetImageData(id=d['image']) qas.extend(utils.ParseQA(data['results'], image_map)) if data['next'] is None: break page += 1 next = '/api/v0/image/' + str(id) + '/qa?page=' + str(page) return qas
def GetAllQAs(qtotal=100): page = 1 next = '/api/v0/qa/all?page=' + str(page) qas = [] image_map = {} while True: data = utils.RetrieveData(next) for d in data['results']: if d['image'] not in image_map: image_map[d['image']] = GetImageData(id=d['image']) qas.extend(utils.ParseQA(data['results'], image_map)) if qtotal is not None and len(qas) > qtotal: return qas if data['next'] is None: break page += 1 next = '/api/v0/qa/all?page=' + str(page) return qas
def GetAllQAs(qtotal=100): """ Gets all the QA from the dataset. qtotal int total number of QAs to return. Set to None if all QAs should be returned """ page = 1 next = '/api/v0/qa/all?page=' + str(page) qas = [] image_map = {} while True: data = utils.RetrieveData(next) for d in data['results']: if d['image'] not in image_map: image_map[d['image']] = GetImageData(id=d['image']) qas.extend(utils.ParseQA(data['results'], image_map)) if qtotal is not None and len(qas) > qtotal: return qas if data['next'] is None: break page += 1 next = '/api/v0/qa/all?page=' + str(page) return qas
def GetQAofType(qtype='why', qtotal=100): """ Get all QA's of a particular type - example, 'why' qtype string possible values: what, where, when, why, who, how. qtotal int total number of QAs to return. Set to None if all QAs should be returned """ page = 1 next = '/api/v0/qa/' + qtype + '?page=' + str(page) qas = [] image_map = {} while True: data = utils.RetrieveData(next) for d in data['results']: if d['image'] not in image_map: image_map[d['image']] = GetImageData(id=d['image']) qas.extend(utils.ParseQA(data['results'], image_map)) if qtotal is not None and len(qas) > qtotal: return qas if data['next'] is None: break page += 1 next = '/api/v0/qa/' + qtype + '?page=' + str(page) return qas