File size: 1,062 Bytes
1da285f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import json
import shutil

SPLIT = '613'
# SPLIT = 'genre'
# SPLIT = 'cat'

OUTPUT_PATH = './coco_instances_results.json'
RESULT_PATH = f'../../evaluation/results/baselines/{SPLIT}/'
GTS_ROOT = '../../evaluation/gts'
TASKS = ['semantics', 'interactable']
FORMATS = ['det']

with open(OUTPUT_PATH, 'r') as f:
    preds = json.load(f)

for task in TASKS:
    for format in FORMATS:
        result_path = os.path.join(RESULT_PATH, format, task)
        os.makedirs(result_path, exist_ok=True)
        with open(os.path.join(GTS_ROOT, format, task, f'{SPLIT}.json'), 'r') as f:
            gts = json.load(f)
        gt_img_ids = [gt['image_id'] for gt in gts['annotations']]
        filtered_preds = []
        for pred in preds:
            if pred['image_id'] in gt_img_ids:
                filtered_preds.append(pred.copy())
        if task == 'interactable':
            for pred in filtered_preds:
                pred['category_id'] = 1
        with open(os.path.join(result_path, 'O4-E2E.json'), 'w') as f:
            json.dump(filtered_preds, f)