-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_results.py
79 lines (66 loc) · 2.52 KB
/
get_results.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Run symbolic reasoning on parsed programs and motion predictions
Output an answer prediction file for test evaluation
"""
import os
import json
from tqdm import tqdm
import argparse
from executor import Executor
from simulation import Simulation
parser = argparse.ArgumentParser()
parser.add_argument('--no_event', action='store_true', default=False)
args = parser.parse_args()
if not args.no_event:
raw_motion_dir = 'data/propnet_preds/with_edge_supervision'
else:
raw_motion_dir = 'data/propnet_preds/without_edge_supervision'
question_path = 'data/test.json'
mc_program_path = 'data/parsed_programs/mc_parsed_prog_1000_test.json'
oe_program_path = 'data/parsed_programs/oe_parsed_prog_1000_test.json'
with open(mc_program_path) as f:
mc_programs = json.load(f)
with open(oe_program_path) as f:
oe_programs = json.load(f)
with open(question_path) as f:
questions = json.load(f)
pred_map = {'yes': 'correct', 'no': 'wrong', 'error': 'error'}
all_pred = []
for i in tqdm(range(5000)):
ann_path = os.path.join(raw_motion_dir, 'sim_%05d.json' % (i + 15000))
sim = Simulation(ann_path, use_event_ann=True)
exe = Executor(sim)
scene = {
'scene_index': questions[i]['scene_index'],
'questions': [],
}
for j, q in enumerate(questions[i]['questions']):
if q['question_type'] == 'descriptive':
assert oe_programs[i]['questions'][j]['question_id'] == q['question_id']
pg = oe_programs[i]['questions'][j]['program']
ans = exe.run(pg, debug=False)
ann = {
'question_id': q['question_id'],
'answer': ans,
}
else:
n_oe = mc_programs[i]['questions'][0]['question_id']
assert mc_programs[i]['questions'][j - n_oe]['question_id'] == q['question_id']
q_pg = mc_programs[i]['questions'][j - n_oe]['program']
ann = {
'question_id': q['question_id'],
'choices': [],
}
for k, c in enumerate(mc_programs[i]['questions'][j - n_oe]['choices']):
c_pg = c['program']
ans = exe.run(c_pg + q_pg, debug=False)
ans = pred_map[ans]
cann = {
'choice_id': c['choice_id'],
'answer': ans,
}
ann['choices'].append(cann)
scene['questions'].append(ann)
all_pred.append(scene)
with open('nsdr_pred.json', 'w') as fout:
json.dump(all_pred, fout)