Run this model with HF Jobs
Run labhamlet/PinnaNet on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/labhamlet/PinnaNet. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/labhamlet/PinnaNet on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use labhamlet/PinnaNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use labhamlet/PinnaNet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="labhamlet/PinnaNet", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("labhamlet/PinnaNet", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Model Card for PinnaNet
PinnaNet is a self-supervised audio representation model for binaural (two-channel) audio. It follows GRAM-Binaural (labhamlet/gramt-binaural-frame), a multi-channel masked auto-encoder trained on naturalistic sound scenes, and adds the interaural time difference (ITD) as a third input channel. The ITD channel is masked and reconstructed together with the log-mel spectrograms of the two ears. In our evaluation this lowers the sound localisation error (see Results).
Model Details
Model Description
PinnaNet takes three feature channels as input:
- the log-mel spectrogram of the left ear,
- the log-mel spectrogram of the right ear,
- the ITD of every mel band and time frame, in seconds.
The spectrograms use 128 mel filters between 50 and 16,000 Hz, a 1,024-sample window and a 320-sample hop (10 ms) at a sampling rate of 32 kHz.
The ITD is computed from the interaural phase difference (IPD): the phase of the right ear minus the phase of the left ear in every STFT bin, with cos(IPD) and sin(IPD) projected through the mel filterbank. The ITD of a mel band is the angle of that pair divided by 2πf, where f is the centre frequency of the band. Values are clipped to ±1 ms. Inside the model the ITD channel is standardised with the mean and standard deviation of the training data (1.7 µs and 236.6 µs), which are stored with the weights.
The three channels are divided into patches of 16 mel bands by 8 frames. The encoder is a 12-layer ViT-Base Transformer (768 dimensions, 12 heads). The decoder, used only during pre-training, consists of 8 multi-window attention blocks (512 dimensions) as in MW-MAE. The repository holds the weights of both.
- Model type: Transformers, Audio Foundation Models
- Input: binaural audio at 32 kHz, left ear first. Mono audio is accepted and treated as the same signal in both ears.
Model Sources
- GRAM paper: https://arxiv.org/abs/2506.00934
- GRAM-Binaural model: https://huggingface.co/labhamlet/gramt-binaural-frame
Uses
PinnaNet can be used as a feature extractor for downstream tasks on binaural audio, such as sound localisation, environmental sound classification and speech tasks. A small classifier or regressor trained on top of the frozen features gives a model for the task at hand.
How to Get Started with the Model
The model code needs torch, torchaudio, torchvision, timm, einops and matplotlib next to transformers.
PinnaNet has three strategies to choose from: "raw", "mean" or "cls". We advise the "raw" strategy, as it produces embeddings over the time frames.
- Raw: breaks the audio into non-overlapping 2-second chunks and concatenates their features in time. The output has shape (batch, time steps, 6144), with 25 time steps per 2 seconds. Take the mean over the time axis for one vector per clip.
- Mean: breaks the audio into non-overlapping 2-second chunks and takes the mean over all patches of a chunk. The output has shape (batch, chunks, 768).
- Cls: breaks the audio into non-overlapping 2-second chunks and returns the "[CLS]" token of each chunk. The output has shape (batch, chunks, 768).
import torch
from transformers import AutoModel, AutoFeatureExtractor
model = AutoModel.from_pretrained("labhamlet/PinnaNet", trust_remote_code=True)
extractor = AutoFeatureExtractor.from_pretrained("labhamlet/PinnaNet", trust_remote_code=True)
audio = torch.zeros([1, 2, 320000]) # batch, ears (left first), samples at 32 kHz
extracted = extractor(audio, sampling_rate=32000, return_tensors="pt")
features = extracted["input_values"] # batch, 3 channels (log-mel left, log-mel right, ITD), frames, 128
print(model(features, strategy="raw").shape)
Loudness normalisation
The feature extractor does not change the level of the audio by default. Pass loudness_normalise=True to scale every clip to an RMS level of -14 dBFS before the features are computed, either for one call or when you load the feature extractor:
# For one call
extracted = extractor(audio, sampling_rate=32000, return_tensors="pt", loudness_normalise=True)
# For every call
extractor = AutoFeatureExtractor.from_pretrained("labhamlet/PinnaNet", trust_remote_code=True, loudness_normalise=True)
The results below were obtained without loudness normalisation.
Training Details
Training Data
PinnaNet was trained with the naturalistic training pipeline of GRAM-Binaural: clips of the unbalanced training set of AudioSet are convolved with binaural room impulse responses and mixed with background noise that is convolved with its own room impulse responses. No clean (unprocessed) clips were used.
Training Procedure
For every sound scene we computed the three feature channels described above. From every scene we randomly sampled 16 partially overlapping segments of 2 seconds (200 frames), which turns a batch of 96 scenes into an effective batch of 1,536 samples.
Each segment is divided into 200 patches (3 × 16 × 8 values per patch). We randomly masked 160 of the 200 patches (masking ratio 0.8). The model was optimised with the mean squared error between the predicted and the true values of the masked patches, as the sum of a log-mel term and an ITD term. All mel bands count equally in the ITD term.
Training Hyperparameters
- Steps: 500,000 on one GPU
- Optimizer: AdamW, learning rate 0.0002, betas (0.9, 0.95), weight decay 0.01
- Schedule: cosine with 10,000 warm-up steps, decaying to 0
- Gradient clipping: norm 5
- Training regime: bf16 mixed precision, torch.compile and flash attention
Evaluation
Testing Data, Factors & Metrics
We evaluated the frozen "raw" embeddings with the HEAR evaluation kit, without loudness normalisation, on:
- ESC-50 from the HEAR benchmark (environmental sound classification, accuracy over five folds);
- SC-5h localisation and ESC-50 localisation from Nat-HEAR in the binaural format, where the model output is the estimated 3D Cartesian direction of the source. We report the median and the mean angular error.
GRAM-Binaural (labhamlet/gramt-binaural-frame) was evaluated under the same conditions for comparison. Values after ± are the standard deviation across the five folds.
Results
| Task | Metric | PinnaNet | GRAM-Binaural |
|---|---|---|---|
| ESC-50 | Accuracy (%, higher is better) | 85.4 ± 2.0 | 87.1 ± 2.2 |
| SC-5h localisation | Median angular error (lower is better) | 18.3° | 23.0° |
| SC-5h localisation | Mean angular error (lower is better) | 25.5° | 29.7° |
| ESC-50 localisation | Median angular error (lower is better) | 31.4° ± 3.2 | 33.9° ± 1.7 |
| ESC-50 localisation | Mean angular error (lower is better) | 38.6° ± 1.9 | 41.4° ± 0.7 |
Summary
Adding the ITD as an input channel lowers the localisation error on both localisation tasks. ESC-50 classification accuracy is 1.7 points lower than that of GRAM-Binaural, which is within the spread across folds.
- Downloads last month
- 36