voice-gender-ecapa (ONNX)
The ECAPA-TDNN voice gender classifier by Jaesung Huh,
JaesungHuh/voice-gender-classifier
(MIT), converted to ONNX so it runs on onnxruntime alone, with no PyTorch.
Use
- Input
audio: float32, shape[1, samples], mono, 16 kHz, any length. - Output
logits: shape[1, 2], index 0 male, index 1 female. Softmax gives the probability.
import numpy as np, onnxruntime as ort
session = ort.InferenceSession("ecapa_gender.onnx", providers=["CPUExecutionProvider"])
logits = session.run(None, {"audio": audio[np.newaxis, :].astype(np.float32)})[0][0]
p_female = float(np.exp(logits[1] - logits.max()) / np.exp(logits - logits.max()).sum())
Conversion
The original's first step (sound to log-mel frequencies) uses torch.stft, which does not
export to ONNX. It was rebuilt from plain convolutions (the same pre-emphasis, Hamming window,
512-point FFT, 80 mel bands, 20-7600 Hz) and the rest of the network is unchanged. Exported with
opset 17.
Checked against the original PyTorch model on 80 guesses (1.5 s and 3 s of phone-quality speech): the same answer every time, and the largest difference in probability 0.0. The rebuilt first step differs from the original's by at most 8e-5.
sha256 of ecapa_gender.onnx:
39776e6bbd3af6649973e670aaca03f6b0913e060184737d2ea37bff895efb99
Measured
On phone-quality Hebrew (8 kHz mu-law), 320 clips from FLEURS: 98.1% right at 1.5 s, 99.4% at 3 s; at 0.9 confidence or more, no wrong answer. Read speech from few speakers, so these numbers are optimistic. About 55 ms per 1.5 s guess and 100 ms per 3 s guess on one CPU thread (Apple M2), about 45 MB of memory to load.
License
MIT, as the original. The model and its weights are Jaesung Huh's work; this repo only converts them.
Model tree for cerebrimceo/voice-gender-ecapa
Base model
JaesungHuh/voice-gender-classifier