Download code/plans/fa2/casc_fuse.py from thucdangvan020999/aurora-wake-model: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/thucdangvan020999/aurora-wake-model/resolve/main/code/plans/fa2/casc_fuse.py
- Command line
-
hf download hf://thucdangvan020999/aurora-wake-model/code/plans/fa2/casc_fuse.py
-
curl -L -o casc_fuse.py https://huggingface.co/thucdangvan020999/aurora-wake-model/resolve/main/code/plans/fa2/casc_fuse.py
2.34 kB
| #!/usr/bin/env python3 | |
| """Offline sweep of a stored cascade (casc_S1_VTAG.npz) with score FUSION: accept a candidate when | |
| s1 >= T1 and (1-a)*logit(s1) + a*logit(s2) >= L (a=1 -> plain stage-2 threshold) | |
| Prints the best rows (fewest VN FA) with misses <= MAXMISS and EN FA <= MAXEN, per D. | |
| python casc_fuse.py S1 VTAG [MAXMISS] [MAXEN]""" | |
| import sys | |
| import numpy as np | |
| K = "/home/user/Downloads/vita-kws" | |
| SR = 16000 | |
| def lg(p): | |
| p = np.clip(p, 1e-6, 1 - 1e-6) | |
| return np.log(p / (1 - p)) | |
| def count(ends, ok): | |
| n, nxt = 0, -1 | |
| for e in ends[ok]: | |
| if e >= nxt: | |
| n, nxt = n + 1, e + 2 * SR | |
| return n | |
| def main(): | |
| s1t, vt = sys.argv[1], sys.argv[2] | |
| MAXMISS = int(sys.argv[3]) if len(sys.argv) > 3 else 45 | |
| MAXEN = int(sys.argv[4]) if len(sys.argv) > 4 else 2 | |
| z = np.load(f"{K}/runs/vf_eval/casc_{s1t}_{vt}.npz", allow_pickle=True) | |
| d = z["data"][0]; pe = z["pos_end"] | |
| rows = [] | |
| for j in range(3): | |
| P = [(lg(s1), lg(s2[:, j]) if len(s2) else np.zeros(0), ends, (ends >= e * SR) & (ends <= (e + 1) * SR)) for (s1, ends, s2), e in zip(d["pos"], pe)] | |
| N = [(lg(s1), lg(s2[:, j]) if len(s2) else np.zeros(0), ends) for s1, ends, s2 in d["neg"]] | |
| Vv = [(lg(s1), lg(s2[:, j]) if len(s2) else np.zeros(0), ends) for s1, ends, s2 in d["vi"]] | |
| for t1 in (0.8, 0.85, 0.875, 0.9, 0.925, 0.9375): | |
| l1 = lg(np.array(t1)) | |
| for a in (0.3, 0.5, 0.7, 1.0): | |
| for L in np.arange(0.0, 6.01, 0.25): | |
| miss = sum(1 for x1, x2, en, m in P if not (m & (x1 >= l1) & ((1 - a) * x1 + a * x2 >= L)).any()) | |
| if miss > MAXMISS: | |
| continue | |
| ef = sum(count(en, (x1 >= l1) & ((1 - a) * x1 + a * x2 >= L)) for x1, x2, en in N) | |
| if ef > MAXEN: | |
| continue | |
| vf = sum(count(en, (x1 >= l1) & ((1 - a) * x1 + a * x2 >= L)) for x1, x2, en in Vv) | |
| rows.append((vf, miss, ef, j * 0.1, t1, a, round(float(L), 2))) | |
| rows.sort() | |
| print(f"{s1t} -> {vt}: best rows with miss <= {MAXMISS}, EN FA <= {MAXEN}") | |
| for vf, miss, ef, D, t1, a, L in rows[:12]: | |
| print(f" VN FA {vf:3d} miss {miss} EN FA {ef} D={D:.1f} T1={t1} a={a} L={L}") | |
| if __name__ == "__main__": | |
| main() | |