File size: 2,152 Bytes
a1fe2e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""Baseline TFLite (1.5 s window every 100 ms) on en_dev2 with the same audio prep as vf_cache.py (1 s lead/tail on keyword
clips, -60 dBFS pink floor, same seeds). Saves runs/vf_eval/cache_TAG.npz with kind=baseline (window scores, not frame logits).
    COMPANY_REL=/path/to/release python comp_clean.py TAG [workers]"""
import json, os, sys
from multiprocessing import get_context
import numpy as np
TAG = sys.argv[1]; WORK = int(sys.argv[2]) if len(sys.argv) > 2 else 8
REL = os.environ.get("COMPANY_REL", "/home/user/Downloads/wuw/3.8.6_en")
sys.argv = [sys.argv[0], "runs/en13_ft2_causal_mel80/best.pt", "stream", "/dev/null"]
sys.path.insert(0, "/home/user/Downloads/vita-kws/plans_local"); sys.path.insert(0, "/home/user/Downloads/vita-wakeword-handoff/scripts")
import stream_eval as S  # noqa
M = None


def init():
    global M
    import bench_wuw_testset as B
    M = B.make(("tflite", "c", REL))


def job(a):
    i, r = a
    w = S.audio.load(r["audio"], S.SR); pos = r["label"] not in S.NK; end = None
    if pos:
        end = len(w) / S.SR + 1.0; w = np.concatenate([np.zeros(S.SR, np.float32), w, np.zeros(S.SR, np.float32)])
    x = (w + 1e-3 * S.noise(len(w), np.random.default_rng(i))).astype(np.float32)
    if len(x) < S.W: x = np.concatenate([np.zeros(S.W - len(x), np.float32), x])
    return pos, M.windows(x).astype(np.float32), end, len(x) / S.SR


if __name__ == "__main__":
    os.environ.setdefault("OMP_NUM_THREADS", "1")
    rows = [json.loads(l) for l in open("/home/user/Downloads/vita-kws/data/aurora/en_dev2.jsonl")]
    with get_context("fork").Pool(WORK, initializer=init) as P:
        R = list(P.imap(job, list(enumerate(rows)), chunksize=8))
    pos = [r for r in R if r[0]]; neg = [r for r in R if not r[0]]
    np.savez(f"/home/user/Downloads/vita-kws/runs/vf_eval/cache_{TAG}.npz", kind="baseline",
             pos=np.array([r[1] for r in pos], dtype=object), pos_end=np.array([r[2] for r in pos]),
             neg=np.array([r[1] for r in neg], dtype=object), neg_hours=sum(r[3] for r in neg) / 3600)
    print("COMP CLEAN DONE", TAG, len(pos), "pos", len(neg), "neg", flush=True)