datariengcuathuongbui / code /vlr_submit.py
ThuongBuiRVC's picture
Add files using upload-large-folder tool
cfa2024 verified
Raw History Blame Contribute Delete
3.43 kB
"""Leaderboard submission from one VLR run: every answer and every trajectory comes from the run (one model).
The skeleton is data/submission_template.json (clip list, question ids, frame conventions; no answer, no trajectory),
made once with --make-template from any earlier submission of the benchmark format. The script stops if a single
question has no VLR answer or a single clip has no VLR trajectory (nothing is filled from elsewhere).
Run: python vlr_submit.py --template data/submission_template.json --answers runs/<r>/test_answers.json \
--traj runs/<r>/test_traj.json --out <json>
python vlr_submit.py --make-template <earlier submission json> --out data/submission_template.json
"""
import argparse
import json
import math
from pathlib import Path
FORMAT_META = ('coordinate_frame', 'trajectory_dt_s', 'trajectory_horizon_s', 'trajectory_steps', 'num_clips', 'num_answers')
def make_template(src, out):
sub = json.loads(Path(src).read_text())
tmpl = dict(meta={k: sub['meta'][k] for k in FORMAT_META},
clips=[dict(clip=c['clip'], clip_token=c['clip_token'], log_name=c['log_name'],
target_frame_index=c['target_frame_index'], trajectory=None,
answers=[dict(question_id=q['question_id'], answer=None) for q in c['answers']]) for c in sub['clips']])
Path(out).write_text(json.dumps(tmpl))
print(f'{out}: {len(tmpl["clips"])} clips, {sum(len(c["answers"]) for c in tmpl["clips"])} questions (format only)')
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--template', default=''); ap.add_argument('--answers', default=''); ap.add_argument('--traj', default='')
ap.add_argument('--out', required=True); ap.add_argument('--make-template', default='')
ap.add_argument('--run', default='', help='run name written into meta')
a = ap.parse_args()
if a.make_template:
return make_template(a.make_template, a.out)
sub = json.loads(Path(a.template).read_text())
letters = json.loads(Path(a.answers).read_text())
trajs = json.loads(Path(a.traj).read_text())
no_ans, no_traj = [], []
for c in sub['clips']:
for q in c['answers']:
if q['question_id'] in letters:
q['answer'] = letters[q['question_id']]
else:
no_ans.append(q['question_id'])
t = trajs.get(c['clip'])
if t is None:
no_traj.append(c['clip']); continue
assert len(t) == 51 and all(len(p) == 3 and all(math.isfinite(x) for x in p) for p in t), c['clip']
t[0] = [0.0, 0.0, 0.0] # the ego pose at the key frame (benchmark convention)
c['trajectory'] = t
if no_ans or no_traj:
raise SystemExit(f'incomplete: {len(no_ans)} questions without a VLR answer, {len(no_traj)} clips without a '
f'VLR trajectory (e.g. {no_traj[:3]}) - nothing is filled from another model')
sub['meta'].update(trajectory_provider=f'VLR joint model {a.run} (one model: answers and trajectories)',
reasoning=f'VLR joint model {a.run}')
Path(a.out).parent.mkdir(parents=True, exist_ok=True)
Path(a.out).write_text(json.dumps(sub))
print(f'{a.out}: {sum(len(c["answers"]) for c in sub["clips"])} answers and {len(sub["clips"])} trajectories, all from VLR', flush=True)
if __name__ == '__main__':
main()