Download code/scripts/make_goldens.py from changh95/METEOR-2-p150: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/changh95/METEOR-2-p150/resolve/main/code/scripts/make_goldens.py
- Command line
-
hf download hf://changh95/METEOR-2-p150/code/scripts/make_goldens.py
-
curl -L -o make_goldens.py https://huggingface.co/changh95/METEOR-2-p150/resolve/main/code/scripts/make_goldens.py
2.13 kB
| #!/usr/bin/env python3 | |
| # SPDX-License-Identifier: Apache-2.0 | |
| """fp32 CPU reference taps + outputs of input npz files -> goldens npz (host only; the device tests read them). | |
| python make_goldens.py --form gather --out ~/ttaw-phase0/data/meteor2_port/goldens INPUT.npz ... | |
| """ | |
| import argparse | |
| import os | |
| import sys | |
| import numpy as np | |
| sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) | |
| from tt_meteor2.host.ego import EgoHead # noqa: E402 | |
| from tt_meteor2.reference import config as C # noqa: E402 | |
| from tt_meteor2.reference.model import Meteor2Net # noqa: E402 | |
| from tt_meteor2.reference.weights import Meteor2Weights # noqa: E402 | |
| KEEP = ("img.c1", "img.c2", "img.c3", "img.c4", "img.fpn", "ctx", "depth.prob", "paint.feat", "lift.polar", | |
| "lift.bev", "paint.bev", "bev.b0", "bev.b1", "bev.fuse", "det.feat", "lane.up", "occ.feat", "ego.flat") | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--model-dir", default=os.path.expanduser(f"~/data/tt-autoware/meteor2/{C.WEIGHTS_REVISION}")) | |
| ap.add_argument("--form", choices=C.FORMS, required=True) | |
| ap.add_argument("--out", required=True) | |
| ap.add_argument("--threads", type=int, default=8) | |
| ap.add_argument("inputs", nargs="+") | |
| a = ap.parse_args() | |
| import torch | |
| torch.set_num_threads(a.threads) | |
| net = Meteor2Net(Meteor2Weights(os.path.join(a.model_dir, C.ONNX_FILES[a.form]))) | |
| os.makedirs(os.path.join(a.out, a.form), exist_ok=True) | |
| for f in a.inputs: | |
| z = dict(np.load(f)) | |
| taps = {} | |
| out = net(**{k: z[k] for k in ("imgs", "K", "T_cam_ego", "v0", "acc", "ego_hist", "route")}, taps=taps) | |
| d = {"out." + k: v.astype(np.float32) for k, v in out.items() if k not in ("depth_logit", "seg2d_logit", "hm2d", "reg2d")} | |
| for k in KEEP: | |
| v = taps[k] | |
| d["tap." + k] = (v.numpy() if hasattr(v, "numpy") else np.asarray(v)).astype(np.float32) | |
| dst = os.path.join(a.out, a.form, os.path.basename(f)) | |
| np.savez(dst, **d) | |
| print(dst, sum(v.nbytes for v in d.values()) >> 20, "MB") | |
| if __name__ == "__main__": | |
| main() | |