File size: 1,890 Bytes
0f131e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
"""Dump the graph inputs of demo-scene frames to npz (development and goldens; host only).

Uses tt-autoware's scripts/autoware/meteor2_lib.py + meteor2_ref.py (the upstream input pipeline: cubic x1.5
upscale, K x1.5, T_cam_ego = inv(T_ego_cam), causal acc, 0.5 s ego history, route of the driven path).

    python make_scene_inputs.py --ttaw-repo ~/tt-autoware/tt-autoware --scene valday --frames 30 60 --out DIR
"""
import argparse
import os
import sys

import numpy as np


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--ttaw-repo", required=True)
    ap.add_argument("--scenes-root", default=os.path.expanduser("~/data/tt-autoware/meteor-demo-scenes"))
    ap.add_argument("--scene", required=True)
    ap.add_argument("--frames", type=int, nargs="+", required=True)
    ap.add_argument("--route", choices=("none", "recorded"), default="recorded")
    ap.add_argument("--out", required=True)
    a = ap.parse_args()
    sys.path.insert(0, os.path.join(a.ttaw_repo, "scripts", "autoware"))
    import meteor2_lib as M2
    import meteor2_ref as R

    path = R.scene_dir(a.scenes_root, a.scene)
    man, em, K, T, dt, _, _ = R.load_scene(path)
    frames = man["frames"]
    os.makedirs(a.out, exist_ok=True)
    for fi in a.frames:
        imgs = R.load_images(path, frames[fi])
        v0 = float(em["v0"][fi])
        acc = float(M2.causal_acc(em["v0"], fi, dt))
        hist = M2.ego_hist(em["pose"], fi, dt)
        route = M2.route_input(em["pose"], fi, a.route == "recorded")
        f = os.path.join(a.out, f"{a.scene}_{fi:04d}.npz")
        np.savez(f, imgs=imgs, K=K, T_cam_ego=T, v0=np.float32(v0), acc=np.float32(acc),
                 ego_hist=np.asarray(hist, np.float32), route=np.asarray(route, np.float32))
        print(f, imgs.shape, v0, acc)


if __name__ == "__main__":
    main()