ZenoNing commited on
Commit
e857152
·
verified ·
1 Parent(s): 95aa6cf

Add nodetfold1 policy checkpoint, StreamPETR detector, and ablation scripts

Browse files
scripts/analysis/compare_nodet_nofold.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Ablation without det_v1 and fold detectors (scripts/ablate_nodet_nofold.sh) vs the best configuration.
2
+
3
+ python scripts/analysis/compare_nodet_nofold.py --tag nodetfold1 (writes eval_results/Bench2Drive/ablation_<tag>.txt)
4
+
5
+ Baseline = every run of the best configuration: the 5 original sp_ft_det4hz_nomask runs and the 2 runs of
6
+ reproduction repro1 (same recipe, retrained; within noise of the original). The ablation is "equivalent" when
7
+ |mean_ablation - mean_baseline| <= 1.96 * sd * sqrt(1/n_ablation + 1/n_baseline) with the single-run sd
8
+ measured on the original repeats; a run-label permutation test and a route-paired Wilcoxon test are reported too.
9
+ """
10
+ import argparse
11
+ import itertools
12
+ import math
13
+
14
+ import numpy as np
15
+ from scipy import stats
16
+
17
+ from compare_reproduction import (B, ORIG_EVALS, SINGLE_RUN_SD, detector_val, final_val_loss, fmt_metrics,
18
+ load_eval, summarize, train_hours)
19
+
20
+ BASELINE_EVALS = ORIG_EVALS + ["repro1_sp_ft_nomask_r1", "repro1_sp_ft_nomask_r2"]
21
+ DETECTORS = {"sp_v1 (orig)": "outputs/stream_petr/sp_v1", "sp_v1 (repro1)": "outputs/stream_petr/sp_v1_repro1"}
22
+ TRACKER_SP = {"orig": "outputs/fastvlm_stage3_tracker_sp/2026-11-03_16-38-38",
23
+ "repro1": "outputs/fastvlm_stage3_tracker_sp/repro1"}
24
+
25
+
26
+ def route_matrix(names):
27
+ runs = [load_eval(n) for n in names]
28
+ keys = sorted(runs[0])
29
+ return keys, np.array([[run[k]["scores"]["score_composed"] for k in keys] for run in runs])
30
+
31
+
32
+ def main():
33
+ ap = argparse.ArgumentParser()
34
+ ap.add_argument("--tag", default="nodetfold1")
35
+ args = ap.parse_args()
36
+ tag = args.tag
37
+ evals = sorted(p.name for p in B.glob(f"{tag}_sp_ft_nomask_r*") if (p / "merged.json").exists())
38
+ L = [f"# Ablation '{tag}': StreamPETR from FastVLM-0.5B (no det_v1), in-sample tracker banks (no folds)"]
39
+
40
+ L += ["", "## Detector: last validation (frames with memory; recall = recall_pos; velocity error median, m/s)"]
41
+ for name, d in {**DETECTORS, f"sp_direct ({tag})": f"outputs/stream_petr/sp_direct_{tag}"}.items():
42
+ L.append(f"{name:22s} {fmt_metrics(detector_val(d))}")
43
+
44
+ L += ["", "## Stage 3 fine-tune: final validation loss",
45
+ f"{'':10s} {'val/loss':>9s} {'route':>8s} {'speed_wps':>10s} {'hours':>6s}"]
46
+ for lab, d in {**TRACKER_SP, tag: f"outputs/fastvlm_stage3_tracker_sp/{tag}"}.items():
47
+ v, h = final_val_loss(d), train_hours(d)
48
+ if v is None:
49
+ L.append(f"{lab:10s} {'pending':>9s}")
50
+ else:
51
+ L.append(f"{lab:10s} {v.get('loss', float('nan')):9.4f} {v.get('route_loss', float('nan')):8.4f} "
52
+ f"{v.get('speed_wps_loss', float('nan')):10.4f} {h if h is not None else float('nan'):6.2f}")
53
+
54
+ L += ["", f"## Closed loop, Bench2Drive-220 (single-run sd {SINGLE_RUN_SD} DS)",
55
+ f"{'':9s} {'n':>2s} {'DS per run':>52s} {'mean':>6s} {'SR':>6s} {'veh.col':>8s} {'timeouts':>9s}"]
56
+ base = summarize(BASELINE_EVALS)
57
+ L.append(f"{'baseline':9s} {len(BASELINE_EVALS):2d} {' / '.join(f'{x:.2f}' for x in base['ds']):>52s} "
58
+ f"{np.mean(base['ds']):6.2f} {np.mean(base['sr']):6.2f} {np.mean(base['col']):8.1f} {np.mean(base['stops']):9.1f}")
59
+ if not evals:
60
+ L.append(f"{'ablation':9s} 0 {'pending':>52s}")
61
+ else:
62
+ abl = summarize(evals)
63
+ L.append(f"{'ablation':9s} {len(evals):2d} {' / '.join(f'{x:.2f}' for x in abl['ds']):>52s} "
64
+ f"{np.mean(abl['ds']):6.2f} {np.mean(abl['sr']):6.2f} {np.mean(abl['col']):8.1f} {np.mean(abl['stops']):9.1f}")
65
+ diff = np.mean(abl["ds"]) - np.mean(base["ds"])
66
+ band = 1.96 * SINGLE_RUN_SD * math.sqrt(1 / len(evals) + 1 / len(BASELINE_EVALS))
67
+ verdict = "equivalent (within noise)" if abs(diff) <= band else ("BETTER" if diff > 0 else "WORSE")
68
+ L.append(f"ablation - baseline = {diff:+.2f} DS, 95% noise band +/-{band:.2f} -> {verdict}")
69
+
70
+ ds = np.array(base["ds"] + abl["ds"])
71
+ n_abl, n_all = len(evals), len(ds)
72
+ splits = list(itertools.combinations(range(n_all), n_abl))
73
+ null = np.array([ds[list(c)].mean() - np.delete(ds, list(c)).mean() for c in splits])
74
+ L.append(f"run-label permutation test ({len(splits)} splits): p = {(np.abs(null) >= abs(diff) - 1e-9).mean():.3f}")
75
+
76
+ keys, mb = route_matrix(BASELINE_EVALS)
77
+ keys_a, ma = route_matrix(evals)
78
+ assert keys == keys_a, "route sets differ"
79
+ rb, ra = mb.mean(0), ma.mean(0)
80
+ w = stats.wilcoxon(ra, rb, zero_method="zsplit")
81
+ L.append(f"route-paired Wilcoxon on per-route means: p = {w.pvalue:.3f}; routes better {int((ra > rb).sum())}, "
82
+ f"worse {int((ra < rb).sum())}, equal {int((ra == rb).sum())}")
83
+ worst = np.argsort(ra - rb)[:6]
84
+ L.append("largest per-route losses: " + ", ".join(
85
+ f"{keys[i].replace('RouteScenario_', '').replace('_rep0', '')} {ra[i] - rb[i]:+.0f}" for i in worst))
86
+ L.append(f"runs >= 92 DS: baseline {sum(x >= 92 for x in base['ds'])}/{len(base['ds'])}, "
87
+ f"ablation {sum(x >= 92 for x in abl['ds'])}/{len(abl['ds'])}")
88
+
89
+ text = "\n".join(L)
90
+ print(text)
91
+ (B / f"ablation_{tag}.txt").write_text(text + "\n")
92
+
93
+
94
+ if __name__ == "__main__":
95
+ main()