Download scripts/analysis/extract_failed.py from ZenoNing/ConsDrive: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/ZenoNing/ConsDrive/resolve/main/scripts/analysis/extract_failed.py
- Command line
-
hf download hf://ZenoNing/ConsDrive/scripts/analysis/extract_failed.py
-
curl -L -o extract_failed.py https://huggingface.co/ZenoNing/ConsDrive/resolve/main/scripts/analysis/extract_failed.py
1.82 kB
| """Extract recorder kinematics for every finished, failed route of a (possibly still running) eval. | |
| Usage: python extract_failed.py RESULT_ROOT --ports 2000,2010,... | |
| """ | |
| import argparse | |
| import glob | |
| import json | |
| import subprocess | |
| import sys | |
| from concurrent.futures import ThreadPoolExecutor | |
| from pathlib import Path | |
| from failure_report import is_success | |
| HERE = Path(__file__).resolve().parent | |
| def finished_records(root): | |
| recs = {} | |
| for f in glob.glob(f"{root}/bench2drive220_*.json"): | |
| try: | |
| data = json.load(open(f)) | |
| except json.JSONDecodeError: | |
| continue | |
| for r in data.get("_checkpoint", {}).get("records", []): | |
| if r.get("status") and r["status"] != "Started": | |
| recs[r["route_id"]] = r | |
| return recs | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("root") | |
| ap.add_argument("--ports", default="2000") | |
| args = ap.parse_args() | |
| root = Path(args.root) | |
| out_dir = root / "analysis" / "npz" | |
| recs = finished_records(root) | |
| todo = [] | |
| for rid, r in recs.items(): | |
| log = root / "recorder" / f"{rid}.log" | |
| if not is_success(r) and log.exists() and not (out_dir / f"{rid}.npz").exists(): | |
| todo.append(str(log)) | |
| ports = [int(p) for p in args.ports.split(",")] | |
| print(f"{len(recs)} finished, {len(todo)} failed logs to extract", flush=True) | |
| chunks = [todo[k::len(ports)] for k in range(len(ports))] | |
| def run(k): | |
| if not chunks[k]: | |
| return | |
| subprocess.run([sys.executable, str(HERE / "recorder_extract.py"), "--port", str(ports[k]), | |
| "--out-dir", str(out_dir), *chunks[k]], check=False) | |
| with ThreadPoolExecutor(len(ports)) as ex: | |
| list(ex.map(run, range(len(ports)))) | |
| if __name__ == "__main__": | |
| main() | |