viks66 commited on
Commit
dd08df9
·
verified ·
1 Parent(s): 48a2321

remove turn-bench-submission/plot_debug.py

Browse files
Files changed (1) hide show
  1. turn-bench-submission/plot_debug.py +0 -88
turn-bench-submission/plot_debug.py DELETED
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Plot debug_pass{N}.npz files saved by predict.py when MIMI_DEBUG=1."""
3
- import sys
4
- from pathlib import Path
5
-
6
- import matplotlib
7
- matplotlib.use("Agg")
8
- import matplotlib.pyplot as plt
9
- import numpy as np
10
-
11
- _HERE = Path(__file__).resolve().parent
12
-
13
- # class index → label (from training config)
14
- CLASS_NAMES = ["bos", "system_end", "user_end", "system", "user"]
15
- CLASS_COLORS = ["#9E9E9E", "#FF9800", "#8BC34A", "#03A9F4", "#2196F3"]
16
- IDX_USER = 4
17
-
18
-
19
- def plot_npz(path: Path) -> None:
20
- d = np.load(path)
21
- subj = d["subj"]
22
- other = d["other"]
23
- floor = d["floor"].astype(np.float32)
24
- if "probs" in d.files:
25
- probs = d["probs"] # (T, 5) — new format
26
- else:
27
- p_user = d["p_user"] # old format: only P(user) was stored
28
- probs = np.zeros((len(p_user), 5), dtype=np.float32)
29
- probs[:, IDX_USER] = p_user
30
- thr = float(d["threshold"])
31
- sr = int(d["sr"])
32
- hz = int(d["frame_rate"])
33
-
34
- n_steps = len(floor)
35
- duration = n_steps / hz
36
- t_wav = np.arange(len(subj)) / sr
37
- t_frame = np.arange(n_steps) / hz
38
-
39
- fig, axes = plt.subplots(4, 1, figsize=(max(20, duration / 5), 10),
40
- gridspec_kw={"hspace": 0.05, "height_ratios": [1, 1, 2, 1]})
41
-
42
- # waveforms
43
- for ax, wav, label in zip(axes[:2], [subj, other], ["subject", "other"]):
44
- ax.plot(t_wav, wav, lw=0.3, color="#555", alpha=0.8)
45
- ax.set_ylabel(label, fontsize=8)
46
- ax.set_xlim(0, duration)
47
- ax.tick_params(labelbottom=False)
48
-
49
- # all 5 class probabilities
50
- ax_prob = axes[2]
51
- for idx, (name, color) in enumerate(zip(CLASS_NAMES, CLASS_COLORS)):
52
- lw = 1.2 if idx == IDX_USER else 0.7
53
- alpha = 0.9 if idx == IDX_USER else 0.7
54
- ax_prob.plot(t_frame, probs[:, idx], lw=lw, color=color, alpha=alpha, label=name)
55
- ax_prob.fill_between(t_frame, probs[:, IDX_USER], alpha=0.1, color=CLASS_COLORS[IDX_USER])
56
- ax_prob.axhline(thr, color="red", lw=0.8, ls="--", label=f"threshold={thr}")
57
- ax_prob.set_ylim(-0.05, 1.05)
58
- ax_prob.set_ylabel("class probs", fontsize=8)
59
- ax_prob.legend(fontsize=7, loc="upper right", ncol=3)
60
- ax_prob.set_xlim(0, duration)
61
- ax_prob.tick_params(labelbottom=False)
62
-
63
- # floor bit
64
- axes[3].step(t_frame, floor, where="post", lw=0.8, color="#4CAF50")
65
- axes[3].fill_between(t_frame, floor, step="post", alpha=0.2, color="#4CAF50")
66
- axes[3].set_ylim(-0.1, 1.1)
67
- axes[3].set_ylabel("floor bit", fontsize=8)
68
- axes[3].set_xlabel("Time (s)", fontsize=9)
69
- axes[3].set_xlim(0, duration)
70
-
71
- for ax in axes:
72
- for vl in np.arange(1, int(duration) + 1):
73
- ax.axvline(vl, color="#ddd", lw=0.4, zorder=0)
74
-
75
- axes[0].set_title(f"mimi_endpointer {path.stem} threshold={thr}", fontsize=9, loc="left", pad=3)
76
- out = path.with_suffix(".png")
77
- fig.savefig(out, dpi=100, bbox_inches="tight")
78
- plt.close(fig)
79
- print(f"saved → {out}")
80
-
81
-
82
- if __name__ == "__main__":
83
- npz_files = sorted(_HERE.glob("debug_pass*.npz"))
84
- if not npz_files:
85
- print("No debug_pass*.npz files found. Run with MIMI_DEBUG=1 first.")
86
- sys.exit(1)
87
- for f in npz_files:
88
- plot_npz(f)