Views
No views yet
vit_small_patch16_224)[B, 1, 192, 128]) generated from 2-second audio clips at 16 kHzpooler_output with shape [B, 384]config.json: model config and auto_mapconfiguration_hear_canon.py: custom PretrainedConfigmodeling_hear_canon.py: custom PreTrainedModel with integrated audio preprocessingpytorch_model.bin: distilled student weightspreprocessor_config.json: preprocessing metadatamodel_shapes.json: structure and tensor shape inventorytraining_args.json: training/checkpoint args captured from the source checkpoint.gitattributes: git/LFS attributes for model artifactssmoke_test.py: local verification scriptpip install -U "transformers>=4.50.0" timm torch scipy soundfilepython3 trained_model_hf_upload/smoke_test.py1import torch
2from transformers import AutoModel
3
4model = AutoModel.from_pretrained(
5 "trained_model_hf_upload",
6 trust_remote_code=True,
7)
8model.eval()
9
10# 4 clips, each 2 seconds at 16 kHz => 32000 samples
11raw_audio_batch = torch.rand((4, 32000), dtype=torch.float32)
12
13with torch.inference_mode():
14 out = model(input_values=raw_audio_batch, return_dict=True)
15
16embeddings = out.pooler_output
17print(embeddings.shape) # torch.Size([4, 384]).wav file1import torch
2import soundfile as sf
3from scipy import signal
4from transformers import AutoModel
5
6
7def load_wav_mono_16k(path: str, target_sr: int = 16000) -> torch.Tensor:
8 audio, sr = sf.read(path, dtype="float32", always_2d=False)
9 if audio.ndim == 2:
10 audio = audio.mean(axis=1)
11 if sr != target_sr:
12 new_len = int(round(audio.shape[0] * (target_sr / sr)))
13 audio = signal.resample(audio, new_len)
14 return torch.from_numpy(audio).float()
15
16
17model = AutoModel.from_pretrained("trained_model_hf_upload", trust_remote_code=True)
18model.eval()
19
20waveform = load_wav_mono_16k("example.wav")
21
22with torch.inference_mode():
23 embedding = model.embed_audio(waveform)
24
25print(embedding.shape) # torch.Size([1, 384])1import torch
2from transformers import AutoModel
3
4model = AutoModel.from_pretrained("trained_model_hf_upload", trust_remote_code=True)
5model.eval()
6
7raw_audio = torch.rand((2, 32000), dtype=torch.float32)
8spectrogram = model.preprocess_audio(raw_audio)
9
10with torch.inference_mode():
11 out = model(pixel_values=spectrogram, return_dict=True)
12
13print(spectrogram.shape) # torch.Size([2, 1, 192, 128])
14print(out.pooler_output.shape) # torch.Size([2, 384])22,140,288384[B, 1, 192, 128][B, 384]model_shapes.json.