import os import json OUTPUT_PATH = './output.json' result = [] with open(OUTPUT_PATH, 'r') as f: output = json.load(f) for img_id, objects in output.items(): for obj in objects: result.append({ 'image_id': int(img_id), 'category_id': obj['name'], 'bbox': [obj['bbox'][0], obj['bbox'][1], obj['bbox'][2], obj['bbox'][3]], 'score': obj['confidence'] }) with open('coco_instances_results.json', 'w') as f: json.dump(result, f)