import json


def load_image_infos(img_dir, image_file):
    """
    Loads the image filenames from visual genome from the JSON file that contains them.
    This matches the preprocessing in scene-graph-TF-release/data_tools/vg_to_imdb.py.
    Parameters:
        image_file: JSON file. Elements contain the param "image_id".
        img_dir: directory where the VisualGenome images are located
    Return:
        List of filenames corresponding to the good images
    """
    with open(image_file, 'r') as f:
        im_data = json.load(f)

    img_infos = {}
    for i, img in enumerate(im_data):
        # align with coco format
        img['id'] = img['image_id']
        img['file_name'] = img['filename']
        img_infos[img['image_id']] = img
    return img_infos