PERCH 2 PyTorch
PyTorch implementation of the complete PERCH 2 waveform model for bioacoustic classification and 1536-dimensional audio embeddings.
Load From Hugging Face
import torch
model = torch.hub.load("janclemenslab/perch2_torch", "perch_v2").eval()
waveform = torch.zeros(5 * 32_000) # Mono 32 kHz audio.
with torch.no_grad():
outputs = model(waveform)
index = outputs["label"][0].argmax()
print(model.labels[index])
This call downloads perch_v2_torch.pt from this Hugging Face repository and
caches it locally.
Inputs are mono, 32 kHz waveforms with shape (time,) or (batch, time).
Audio longer than five seconds is processed in overlapping windows and pooled.
Outputs
embedding:(batch, 1536)global embeddingspatial_embedding:(batch, time, frequency, 1536)unpooled embeddingspectrogram: log-mel spectrogramlabel:(batch, 14795)uncalibrated class logits
model.labels[index] maps a logit index to its embedded class name. Thresholds
should be calibrated for the target data.
Reproducibility
The conversion code, demo notebook, and verification command are available in janclemenslab/perch2_torch.
Attribution And License
Derived from the Apache-2.0 PERCH ONNX model and Apache-2.0 wrice EfficientNet-B3 checkpoint. The class taxonomy comes from the Apache-2.0 PERCH model release.