Views
No views yet

1from huggingface_hub import snapshot_download
2
3# Download the model to local directory
4model_path = snapshot_download(
5 repo_id="yucongzh/echo-small-0824",
6 local_dir="./echo-small",
7 local_dir_use_symlinks=False
8)
9print(f"Model downloaded to: {model_path}")1import torch
2import torchaudio
3import sys
4
5# Add the model path to Python path
6sys.path.append('./echo-small')
7
8# Import the model architecture
9from audioMAE_band_upgrade import AudioMAEWithBand
10
11# Create model instance with your configuration
12model = AudioMAEWithBand(
13 spec_len=2000,
14 band_width=32,
15 shift_size=16,
16 in_chans=1,
17 embed_dim=384,
18 encoder_depth=12,
19 num_heads=6,
20 mlp_ratio=4.0,
21 freq_pos_emb_dim=384
22)
23
24# Load pre-trained weights
25from safetensors.torch import load_file
26state_dict = load_file('model.safetensors')
27model.load_state_dict(state_dict, strict=False)
28
29# Set to evaluation mode
30model.eval()
31
32# Example usage
33audio_signal = torch.randn(1, 240000) # 5 seconds at 48kHz
34sample_rate = 48000
35
36# Method 1: Extract features directly from audio (Recommended)
37with torch.inference_mode():
38 utterance_level_features, segment_level_features = model.extract_features_from_audio(audio_signal, sample_rate=sample_rate)
39print(f"Utterance-level Feature shape: {utterance_level_features.shape}")
40print(f"Segment-level Feature shape: {segment_level_features.shape}")
41
42# Method 2: Use preprocessing separately, then extract features
43spec = model.preprocess_audio_to_spectrogram(audio_signal, sample_rate=sample_rate)
44print(f"Spectrogram shape: {spec.shape}")
45
46# Extract features from preprocessed spectrogram
47with torch.inference_mode():
48 utterance_level_features, segment_level_features = model.extract_features(spec, sample_rate=sample_rate)
49print(f"Utterance-level Feature shape: {utterance_level_features.shape}")
50print(f"Segment-level Feature shape: {segment_level_features.shape}")[NxD, ] (concatenated CLS tokens from all frequency bands)[T, NxD] (temporal features for each patch, concatenated across bands)1@article{echo2025,
2 title={ECHO: Frequency-aware Hierarchical Encoding for Variable-length Signal},
3 author={Yucong Zhang and Juan Liu and Ming Li},
4 journal={arXiv preprint arXiv:2508.14689},
5 year={2025},
6}