| import os | |
| import json | |
| with open("./clevr_data/test_all_captions.json", "r") as f: | |
| captions = json.load(f) | |
| print(captions.keys()) | |
| coco_res = {"images": [], "annotations": []} | |
| caption_id = 0 | |
| for k, v in captions.items(): | |
| coco_res["images"].append({"file_name": k, "id": k}) | |
| for i, caption in enumerate(v): | |
| coco_res["annotations"].append({"image_id": k, "caption": caption, "id": caption_id}) | |
| caption_id += 1 | |
| with open("./clevr_data/clevr_total_change_captions_reformat.json", "w") as f: | |
| json.dump(coco_res, f) | |