File size: 1,604 Bytes
3f3265f | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import json
FORMAT = 'det'
TASK = 'interactable'
# TASK = 'semantics'
# TASK = 'interaction'
DATASET_PATH = f'./data/coco_{FORMAT}/annotations/{TASK}.json'
TEST_613_PATH = f'../evaluation/gts/{FORMAT}/{TASK}/613.json'
TEST_GENRE_PATH = f'../evaluation/gts/{FORMAT}/{TASK}/genre.json'
TEST_CAT_PATH = f'../evaluation/gts/{FORMAT}/{TASK}/cat.json'
UNION_PATH = f'../evaluation/gts/{FORMAT}/{TASK}/union_test.json'
UNION3_PATH = f'../evaluation/gts/{FORMAT}/{TASK}/union3_test.json'
def get_union_test(fullset, testset1, testset2):
union_test = {'images': [], 'categories': fullset['categories'], 'annotations': []}
img_ids = []
for img in testset1['images']:
img_ids.append(img['id'])
union_test['images'].append(img)
for img in testset2['images']:
if img['id'] not in img_ids:
union_test['images'].append(img)
img_ids.append(img['id'])
for ann in fullset['annotations']:
if ann['image_id'] in img_ids:
union_test['annotations'].append(ann)
return union_test
with open(DATASET_PATH, 'r') as f:
dataset = json.load(f)
with open(TEST_613_PATH, 'r') as f:
test_613 = json.load(f)
with open(TEST_GENRE_PATH, 'r') as f:
test_genre = json.load(f)
with open(TEST_CAT_PATH, 'r') as f:
test_cat = json.load(f)
union_test = get_union_test(dataset, test_613, test_genre)
with open(UNION_PATH, 'w') as f:
json.dump(union_test, f, indent=4)
union3_test = get_union_test(dataset, union_test, test_cat)
with open(UNION3_PATH, 'w') as f:
json.dump(union3_test, f, indent=4) |