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