File size: 545 Bytes
8520896 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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)
|