Tartan_IMU_VBR / examples /load_via_airlab.py
YiZhaoJasper's picture
Add files using upload-large-folder tool
20bb0ea verified
Raw
History Blame Contribute Delete
2.62 kB
#!/usr/bin/env python3
"""load_via_airlab.py — TartanIMU AirLabNPZSequence single-file loader.
Verifies that this dataset is drop-in compatible with TartanIMU's
`dataloader.dataset_AirLab.AirLabNPZSequence`. **No monkey-patch is required**
— the path layout `data/{car,human}/vbr/...` causes the loader's substring
matcher to assign the correct `motion_type` automatically (1 = car, 4 = human).
None of our 8 sequence names contain the substrings "car", "dog", "drone",
or "human", so there is no false-match hazard.
Run from the dataset root:
python examples/load_via_airlab.py \\
--tartanimu-master /path/to/TartanIMU-master \\
--num 4
"""
from __future__ import annotations
import argparse
import random
import sys
import warnings
from pathlib import Path
import numpy as np
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--tartanimu-master", required=True,
help="path to the cloned TartanIMU-master repo")
ap.add_argument("--data-root", default="data")
ap.add_argument("--num", type=int, default=4)
ap.add_argument("--seed", type=int, default=0)
args = ap.parse_args()
sys.path.insert(0, args.tartanimu_master)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from dataloader.dataset_AirLab import AirLabNPZSequence
files = sorted(Path(args.data_root).rglob("traj.npz"))
if not files:
print(f"[error] no traj.npz under {args.data_root}", file=sys.stderr)
return 2
random.seed(args.seed)
picks = random.sample(files, min(args.num, len(files)))
name_of = {0: "none", 1: "car", 2: "dog", 3: "drone", 4: "human"}
failed = 0
for p in picks:
seq = AirLabNPZSequence(
data_path=str(p),
imu_freq=200,
window_size=200,
verbose=False,
use_local_coord=True,
mode="train",
)
mt = int(seq.motion_type.item())
expected = 1 if "/car/" in str(p) else 4
ok = bool(seq.valid) and mt == expected
failed += not ok
print(
f"[{('OK ' if ok else 'BAD')}] {p.parent.name:<24s} "
f"motion_type={name_of.get(mt, '?'):<5s} (got={mt} expected={expected}) "
f"feat={tuple(seq.features.shape)} targ={tuple(seq.targets.shape)} "
f"valid={seq.valid}"
)
print()
print(f"[summary] {len(picks) - failed}/{len(picks)} files load via AirLabNPZSequence with correct motion_type")
return 0 if failed == 0 else 1
if __name__ == "__main__":
raise SystemExit(main())