Nurec_eval / inject_map.py
luuuulinnnn's picture
Add 59 OOD-longtail USDZ scenes with HD-map artifacts injected
dab81f5 verified
"""Add clipgt/map_data parquet files to NRE-exported USDZs.
Usage:
python inject_map.py <src_usdz> <map_dir> <dst_usdz>
map_dir is the per-scene directory under
/mnt/data4/nurec_ood64/map/ood_closeloop_map/<uuid>/.
"""
from __future__ import annotations
import shutil
import sys
import zipfile
from pathlib import Path
MAP_FILES = [
"cf_crosswalks.parquet",
"cf_lane_topology_node.parquet",
"cf_road_boundary.parquet",
"dw_lane.parquet",
"lane_chunk.parquet",
"lane_rail.parquet",
]
def inject(src: Path, map_dir: Path, dst: Path) -> None:
shutil.copy2(src, dst)
with zipfile.ZipFile(dst, "a", compression=zipfile.ZIP_STORED) as zf:
existing = set(zf.namelist())
for name in MAP_FILES:
arc = f"map_data/{name}"
if arc in existing:
print(f" skip (already present): {arc}")
continue
src_file = map_dir / name
if not src_file.exists():
raise FileNotFoundError(src_file)
zf.write(src_file, arcname=arc)
print(f" added: {arc} ({src_file.stat().st_size} bytes)")
def main() -> int:
if len(sys.argv) != 4:
print(__doc__)
return 1
src, map_dir, dst = map(Path, sys.argv[1:])
print(f"inject {map_dir} -> {src} => {dst}")
inject(src, map_dir, dst)
print(f"wrote {dst} ({dst.stat().st_size} bytes)")
return 0
if __name__ == "__main__":
sys.exit(main())