mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
Retain the contributor alias cleanup and remove the NumPy cap with verified CPU dependency, frontend, masking and clustering coverage. NumPy 1.26.4 and 2.4.0 each pass 23 exact-head CI tests and 77 local tests plus 184 subtests. Existing EEND mel calls now use keyword arguments for modern librosa. The related installation issue remains open pending published-package and reporter re-test. Co-authored-by: linhongyu510 <[email protected]> Signed-off-by: zhifu gao <[email protected]>
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
"""Check EEND feature values across the supported scientific-stack matrix."""
|
|
|
|
import numpy as np
|
|
import pytest
|
|
import torch
|
|
|
|
|
|
@pytest.fixture
|
|
def spectra():
|
|
amplitudes = np.array([1, 10, 100, 1000], dtype=np.float32)
|
|
return amplitudes[:, None] * np.full((4, 257), 1 + 1j, dtype=np.complex64)
|
|
|
|
|
|
@pytest.mark.parametrize("mode,bands", [("logmel", 40), ("logmel23", 23)])
|
|
def test_eend_logmel_preserves_power_ratios(spectra, mode, bands):
|
|
from funasr.models.eend.utils.feature import transform
|
|
|
|
result = transform(spectra, transform_type=mode)
|
|
assert result.dtype == np.float32 and result.shape == (4, bands)
|
|
assert np.isfinite(result).all()
|
|
# A tenfold amplitude increase adds 2 to log10 power in every mel band.
|
|
np.testing.assert_allclose(np.diff(result, axis=0), 2.0, atol=2e-6)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mode,expected",
|
|
[
|
|
("logmel23_mn", [-3, -1, 1, 3]),
|
|
("logmel23_mvn", np.array([-3, -1, 1, 3]) / np.sqrt(5)),
|
|
("logmel23_swn", [-5, -3, -1, 1]),
|
|
],
|
|
)
|
|
def test_eend_normalization_values(spectra, mode, expected):
|
|
from funasr.models.eend.utils.feature import transform
|
|
|
|
original = spectra.copy()
|
|
result = transform(spectra, transform_type=mode)
|
|
assert result.dtype == np.float32
|
|
np.testing.assert_allclose(
|
|
result, np.repeat(np.asarray(expected)[:, None], 23, axis=1), atol=2e-6
|
|
)
|
|
np.testing.assert_array_equal(spectra, original)
|
|
|
|
|
|
def test_eend_ola_mean_normalization(spectra):
|
|
from funasr.frontends.eend_ola_feature import transform
|
|
|
|
result = transform(spectra)
|
|
np.testing.assert_allclose(
|
|
result, np.repeat(np.array([-3, -1, 1, 3])[:, None], 23, axis=1), atol=2e-6
|
|
)
|
|
assert result.dtype == np.float32
|
|
|
|
|
|
def test_mel23_waveform_frontend_returns_finite_padded_features():
|
|
from funasr.frontends.wav_frontend import WavFrontendMel23
|
|
|
|
wave = np.sin(2 * np.pi * 440 * np.arange(1600) / 8000).astype(np.float32)
|
|
samples = torch.from_numpy(np.stack([wave, wave]))
|
|
frontend = WavFrontendMel23(
|
|
fs=8000, frame_length=256, frame_shift=80, lfr_m=0, lfr_n=1
|
|
)
|
|
features, lengths = frontend(samples, torch.tensor([1600, 1200]))
|
|
assert features.shape == (2, 20, 23)
|
|
assert lengths.tolist() == [20, 15]
|
|
assert features.dtype == torch.float32 and torch.isfinite(features).all()
|
|
assert torch.count_nonzero(features[1, 15:]) == 0
|
|
assert torch.count_nonzero(features[0]) > 0
|