Example #1
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]
Example #2
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]
Example #3
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    # In case when exact filename is passed
    if os.path.isdir(data_dir):
        dataFile = os.path.join(data_dir, 'image_data.json')
    else:
        dataFile = data_dir
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]
def get_all_image_data(data_dir=None, as_dict=False):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    if not as_dict:
        return [utils.parse_image_data(image) for image in data]

    return {
        image['id'] if 'id' in image else image['image_id']: utils.parse_image_data(image) for image in data
    }
Example #5
0
def get_all_qas(data_dir=None):
    """
    Get all question answers.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'question_answers.json')
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(utils.parse_QA(image['qas'], image_map))
    return output
def get_region_descriptions(image_ids, data_dir=None):
    """
    Get all region descriptions.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'region_descriptions.json')
    image_data = get_all_image_data(data_dir, True)

    images = json.load(open(data_file))
    output = []
    for image in images:
        if image["id"] in image_ids and len(image["regions"]) > 0:
            output.append(utils.parse_region_descriptions(
                image['regions'], image_data[image['id']]))
    return output
Example #7
0
def get_all_qas(data_dir=None):
    """
    Get all question answers.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'question_answers.json')
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(utils.ParseQA(image['qas'], image_map))
    return output
Example #8
0
def get_all_region_descriptions(data_dir=None):
    """
    Get all region descriptions.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'region_descriptions.json')
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(utils.parse_region_descriptions(
            image['regions'], image_map[image['id']]))
    return output
Example #9
0
def get_all_region_descriptions(data_dir=None):
    """
    Get all region descriptions.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'region_descriptions.json')
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(utils.parse_region_descriptions(
            image['regions'], image_map[image['id']]))
    return output
Example #10
0
def get_all_attributes(data_dir=None):
    """
    Get all attributes.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    data_file = os.path.join(data_dir, 'attributes.json')
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(
            utils.parse_attributes(image['attributes'],
                                   image_map[image['image_id']]))
    return output
Example #11
0
def get_all_objects(data_dir=None):
    """
    Get all region descriptions.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    # In case when exact filename is passed
    if os.path.isdir(data_dir):
        data_file = os.path.join(data_dir, 'objects.json')
    else:
        dataFile = data_dir
    image_data = get_all_image_data(data_dir)
    image_map = {}
    for d in image_data:
        image_map[d.id] = d
    images = json.load(open(data_file))
    output = []
    for image in images:
        output.append(
            utils.parse_region_descriptions(image['regions'],
                                            image_map[image['id']]))
    return output