SpoofSUPERB-XLSR / source_parity_float.py
korallll's picture
Wrapper code (speech-spoof-bench)
1919b5b verified
Raw History Blame Contribute Delete
1.09 kB
# Float-source parity vs the published ITW score file: run from this dir:
# python source_parity_float.py <module> <ssl_name> <N> (reads the original float wavs, not the PCM_16 parquet)
import os, sys, numpy as np, soundfile as sf, torch, importlib
sys.path.insert(0, os.getcwd())
W = importlib.import_module(sys.argv[1]); ssl = sys.argv[2]; N = int(sys.argv[3])
SRC = "/home/kirill/mnt/users_4tb/datasets/release_in_the_wild"
pub = {}
for line in open(f"../_ckpt_dl/issf__spoof-superb-scores/raw/linear_head/in_the_wild/{ssl}.txt"):
p = line.split(); pub[int(p[0])] = float(p[-1])
ids = list(range(N))
aud = [sf.read(f"{SRC}/{i}.wav", dtype="float32")[0] for i in ids]
m = [c for n, c in vars(W).items() if n.startswith("SpoofSUPERB") and isinstance(c, type)][0](); m.load()
pv = np.array([pub[i] for i in ids])
for tf in (False, True):
torch.backends.cudnn.allow_tf32 = tf
s = np.array(sum((m.score_batch(aud[k:k+16], [16000]*16) for k in range(0, N, 16)), []))
print(f"float source, cudnn_tf32={tf}: max|d|={np.abs(pv-s).max():.3g} mean|d|={np.abs(pv-s).mean():.3g}")