Buckets:
| """Per-group statistics of 220-route Bench2Drive evals for the supplementary tables. | |
| python outputs/supp/supp_stats.py GROUP=run1,run2 ... [--ref GROUP] | |
| Per run and per group mean: DS, SR, RC, infraction events, Efficiency (official formula of Bench2Drive | |
| tools/efficiency_smoothness_benchmark.py, from merged.json), Comfortness (same tool, from <run>/metric_info when | |
| the eval logged it), and the number of routes on which the 40 s creep fired at least once (worker logs). | |
| With --ref, every group is compared to the reference by a route-paired bootstrap (route scores averaged | |
| inside each group). | |
| """ | |
| import glob | |
| import json | |
| import os | |
| import re | |
| import sys | |
| from collections import OrderedDict | |
| import numpy as np | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../scripts/analysis/b2d_tools")) | |
| from efficiency_smoothness_benchmark import seg_compute_comfort_metric # noqa: E402 | |
| B = "/workspace/code/ConsDrive_v2_eval/eval_results/Bench2Drive" | |
| KEYS = OrderedDict([ | |
| ("veh", ("collisions_vehicle",)), ("ped", ("collisions_pedestrian",)), ("layout", ("collisions_layout",)), | |
| ("red", ("red_light",)), ("stop", ("stop_infraction",)), ("timeout", ("scenario_timeouts", "route_timeout")), | |
| ("blocked", ("vehicle_blocked",)), ("dev", ("route_dev",)), | |
| ]) | |
| def efficiency(records): | |
| vals = [] | |
| for r in records: | |
| infr = r["infractions"]["min_speed_infractions"] | |
| if not infr: | |
| continue | |
| e = [float(m.group().rstrip("%")) for m in (re.search(r"\b\d+\.?\d*%", s) for s in infr) if m] | |
| e = [x for x in e if x <= 1000] | |
| if e: | |
| vals.append(sum(e) / len(e)) | |
| return float(np.mean(vals)) if vals else float("nan") | |
| def comfort(run, records): | |
| res = [] | |
| for r in records: | |
| path = f"{B}/{run}/metric_info/{r['save_name']}/metric_info.json" | |
| if not os.path.exists(path): | |
| return float("nan"), 0 | |
| steps = json.load(open(path)) | |
| rec = {k: np.array([v[k] for v in steps.values()]) for k in | |
| ("acceleration", "angular_velocity", "forward_vector", "right_vector", "location", "rotation")} | |
| res.append(seg_compute_comfort_metric(**rec)) | |
| return 100.0 * float(np.mean(res)), len(res) | |
| def creep_routes(run): | |
| n = 0 | |
| for log in glob.glob(f"{B}/{run}/logs/w*.log"): | |
| for line in open(log, errors="ignore"): | |
| if line.startswith("Creep stats") and "'fallback'" in line: | |
| n += 1 | |
| return n | |
| def load(run): | |
| path = f"{B}/{run}/merged.json" | |
| if not os.path.exists(path): | |
| return None | |
| m = json.load(open(path)) | |
| recs = m["_checkpoint"]["records"] | |
| out = {"ds": m["driving score"], "sr": 100 * m["success rate"], "n": m["eval num"], | |
| "rc": float(np.mean([r["scores"]["score_route"] for r in recs])), | |
| "score": {r["route_id"]: r["scores"]["score_composed"] for r in recs}, | |
| "eff": efficiency(recs), "creep": creep_routes(run)} | |
| out["comfort"], out["comfort_n"] = comfort(run, recs) | |
| for k, names in KEYS.items(): | |
| out[k] = sum(len(r["infractions"].get(name) or []) for r in recs for name in names) | |
| return out | |
| def paired(a_runs, b_runs, loaded, n_boot=10000, seed=0): | |
| ids = sorted(set.intersection(*[set(loaded[r]["score"]) for r in a_runs + b_runs])) | |
| a = np.array([np.mean([loaded[r]["score"][i] for r in a_runs]) for i in ids]) | |
| b = np.array([np.mean([loaded[r]["score"][i] for r in b_runs]) for i in ids]) | |
| d = a - b | |
| rng = np.random.default_rng(seed) | |
| boots = d[rng.integers(0, len(d), (n_boot, len(d)))].mean(1) | |
| return d.mean(), np.percentile(boots, 2.5), np.percentile(boots, 97.5), float((boots <= 0).mean()) | |
| args = [a for a in sys.argv[1:] if not a.startswith("--ref")] | |
| ref = next((a.split("=", 1)[1] for a in sys.argv[1:] if a.startswith("--ref=")), None) | |
| groups = OrderedDict((a.split("=", 1)[0], a.split("=", 1)[1].split(",")) for a in args) | |
| cols = ["ds", "sr", "rc", "eff", "comfort", "creep"] + list(KEYS) | |
| print(f"{'run':40s} " + " ".join(f"{c:>7s}" for c in cols)) | |
| loaded, summary = {}, OrderedDict() | |
| for g, runs in groups.items(): | |
| rs = [(run, load(run)) for run in runs] | |
| rs = [(run, r) for run, r in rs if r is not None and r["n"] == 220] | |
| for run, r in rs: | |
| loaded[run] = r | |
| print(f"{run:40s} " + " ".join(f"{r[c]:7.2f}" if isinstance(r[c], float) else f"{r[c]:7d}" for c in cols)) | |
| if not rs: | |
| continue | |
| ds = [r["ds"] for _, r in rs] | |
| summary[g] = [run for run, _ in rs] | |
| sd = float(np.std(ds, ddof=1)) if len(ds) > 1 else float("nan") | |
| print(f"{' MEAN ' + g + f' (n={len(rs)}, sd {sd:.2f})':40s} " + | |
| " ".join(f"{np.nanmean([r[c] for _, r in rs]):7.2f}" for c in cols)) | |
| if ref and ref in summary: | |
| print(f"\nroute-paired difference to {ref} (bootstrap 95% CI over routes; P(diff <= 0)):") | |
| for g, runs in summary.items(): | |
| if g == ref: | |
| continue | |
| m, lo, hi, p = paired(runs, summary[ref], loaded) | |
| print(f" {g:28s} {m:+6.2f} [{lo:+.2f}, {hi:+.2f}] P={p:.3f}") | |
Xet Storage Details
- Size:
- 5.05 kB
- Xet hash:
- a68e5b368dc605310b25f3896500fa7427de86d80f40ec5ca16269a92653286f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.