Download code/tests/check_numeric.py from zhizeng115/EchoScout-FourTask: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/datasets/zhizeng115/EchoScout-FourTask/resolve/main/code/tests/check_numeric.py
- Command line
-
hf download hf://datasets/zhizeng115/EchoScout-FourTask/code/tests/check_numeric.py
-
curl -L -o check_numeric.py https://huggingface.co/datasets/zhizeng115/EchoScout-FourTask/resolve/main/code/tests/check_numeric.py
1.9 kB
| """CPU checks using synthetic inputs only; no checkpoints or benchmark data.""" | |
| import sys,unittest | |
| from pathlib import Path | |
| R=Path(__file__).resolve().parents[1];sys.path[:0]=[str(R),str(R/'tools')] | |
| import numpy as np | |
| import torch | |
| from omini.data.staqa_preprocessing import prepare_staqa_waveform | |
| from omini.models.st_audio_encoder import STAudioEncoder | |
| from hvs_core import perspective,circular_delta | |
| from sound_search_core import score | |
| class NumericChecks(unittest.TestCase): | |
| def test_waveform_normalization_and_resampling(self): | |
| t=np.arange(160000,dtype=np.float32)/16000 | |
| wave=np.stack([.1*np.sin(2*np.pi*440*t),.3*np.cos(2*np.pi*220*t)],1) | |
| x=prepare_staqa_waveform(wave,16000) | |
| self.assertEqual(tuple(x.shape),(2,320000));self.assertTrue(torch.isfinite(x).all()) | |
| np.testing.assert_allclose(x.square().mean(1).sqrt().numpy(),10**(-14/20),rtol=1e-4) | |
| self.assertFalse(torch.equal(x[0],x[1])) | |
| self.assertEqual(torch.count_nonzero(prepare_staqa_waveform(np.zeros((12,2)),32000)),0) | |
| def test_projection(self): | |
| pano=np.full((512,2048,3),80,dtype=np.uint8) | |
| view=perspective(pano,0,0) | |
| self.assertEqual(view.shape,(360,640,3));self.assertEqual(circular_delta(5,355),10) | |
| def test_sound_submission_gate(self): | |
| label={'target_index':0,'candidates':[{'center':[0,0],'bbox':[990,230,1058,282]},{'center':[120,0],'bbox':[1600,230,1668,282]}]} | |
| self.assertFalse(score([0,0],label,False)['success']) | |
| self.assertFalse(score([120,0],label,True)['success']) | |
| def test_encoder_token_shape(self): | |
| torch.set_num_threads(2) | |
| model=STAudioEncoder(audio_frontend='binaural',num_classes=355,embed_dim=768,depth=12,num_heads=12,audio_bins=40,temporal_layers=2).eval() | |
| with torch.inference_mode():out=model(torch.zeros(1,2,320000)) | |
| self.assertEqual(tuple(out.audio_tokens.shape),(1,41,768));self.assertTrue(torch.isfinite(out.audio_tokens).all()) | |
| if __name__=='__main__':unittest.main() | |