halo-tracker-v9 / tracker_example.py
rain-sicoreai's picture
v9 release: EMA flow planner / v9 tracker
cc6c61c verified
Raw History Blame Contribute Delete
1.46 kB
#!/usr/bin/env python3
"""Minimal HALO-v9 tracker call (simulation contract, onnxruntime + numpy).
pip install onnxruntime numpy
python tracker_example.py --model tracker.onnx
The 69-D observation layout and the depth conventions are documented in the
model card; this script only validates the interface and shapes.
"""
from __future__ import annotations
import argparse
import numpy as np
import onnxruntime as ort
def main() -> int:
p = argparse.ArgumentParser()
p.add_argument("--model", default="tracker.onnx")
args = p.parse_args()
sess = ort.InferenceSession(args.model, providers=["CPUExecutionProvider"])
print("inputs ", [(i.name, i.shape) for i in sess.get_inputs()])
print("outputs", [(o.name, o.shape) for o in sess.get_outputs()])
rng = np.random.default_rng(0)
obs = np.zeros((1, 69), np.float32)
depth = np.full((1, 1, 120, 160), 0.8, np.float32) # metres
action = sess.run(None, {"obs_vec": obs, "wrist_depth": depth})[0]
print("action", action.shape, np.round(action[0], 4).tolist())
# Batch invariance: the same sample through a 2-row batch.
batch = sess.run(None, {
"obs_vec": np.repeat(obs, 2, axis=0),
"wrist_depth": np.repeat(depth, 2, axis=0)})[0]
delta = float(np.abs(batch[0] - action[0]).max())
print("batch_delta", delta)
print("TRACKER_EXAMPLE_OK", delta < 1e-5)
return 0
if __name__ == "__main__":
raise SystemExit(main())