Download tests/test_features.py from k9cli/video-vec2wav2-tokenizer: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/datasets/k9cli/video-vec2wav2-tokenizer/resolve/main/tests/test_features.py
- Command line
-
hf download hf://datasets/k9cli/video-vec2wav2-tokenizer/tests/test_features.py
-
curl -L -o test_features.py https://huggingface.co/datasets/k9cli/video-vec2wav2-tokenizer/resolve/main/tests/test_features.py
1.3 kB
| """Tests for feature extraction and the binary store.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from video_vec2wav2_tokenizer.features.extractor import ( | |
| FeatureExtractor, | |
| compute_mel_spectrogram, | |
| read_feature_record, | |
| ) | |
| def test_compute_mel_shape(sine_wav: Path) -> None: | |
| from video_vec2wav2_tokenizer.audio.extractor import load_wav | |
| samples, sr = load_wav(sine_wav) | |
| mel = compute_mel_spectrogram(samples, sr, n_mels=80) | |
| assert mel.shape[0] == 80 | |
| assert mel.dtype == np.float32 | |
| assert mel.shape[1] > 0 | |
| def test_feature_store_roundtrip(sine_wav: Path, tmp_path: Path) -> None: | |
| fx = FeatureExtractor(sample_rate=16000, n_mels=40) | |
| features_dir = tmp_path / "features" | |
| dat_path = fx.extract_dataset([sine_wav, sine_wav], features_dir) | |
| bin_path = features_dir / "train.bin" | |
| assert bin_path.exists() | |
| assert dat_path.exists() | |
| records = [json.loads(line) for line in dat_path.read_text().splitlines() if line] | |
| assert len(records) == 2 | |
| audio, mel = read_feature_record(bin_path, records[0]) | |
| assert audio.dtype == np.float32 | |
| assert mel.shape == tuple(records[0]["mel_shape"]) | |
| assert records[0]["sample_rate"] == 16000 | |
| assert records[0]["duration"] > 0 | |