Views
No views yet
utrechtuniversity/chimp-vocalization-cnn12-sanctuary.| Test recording | F1 | Precision | Recall | F1-macro | Precision-macro | Recall-macro | AUC |
|---|---|---|---|---|---|---|---|
| 13b | 0.6829 | 0.6829 | 0.6829 | 0.8364 | 0.8364 | 0.8364 | 0.9905 |
| 14a | 0.7059 | 0.6667 | 0.7500 | 0.8516 | 0.8323 | 0.8734 | 0.9917 |
transformers — it's a plain PyTorch model exported with PyTorchModelHubMixin. Copy the class definition below, then load the trained weights directly from the Hub.1import torch.nn as nn
2from huggingface_hub import PyTorchModelHubMixin
3
4
5def _cnn_block(in_ch, out_ch):
6 return nn.Sequential(
7 nn.Conv2d(in_ch, out_ch, kernel_size=3, padding=1),
8 nn.BatchNorm2d(out_ch),
9 nn.ReLU(inplace=True),
10 )
11
12
13class CNN12Hub(nn.Module, PyTorchModelHubMixin):
14 def __init__(self, num_channels=3, num_labels=2, dropout_rate=0.5, **kwargs):
15 super().__init__()
16 layers = [
17 _cnn_block(num_channels, 64), _cnn_block(64, 64), nn.AvgPool2d(2), nn.Dropout(dropout_rate),
18 _cnn_block(64, 128), _cnn_block(128, 128), nn.AvgPool2d(2), nn.Dropout(dropout_rate),
19 _cnn_block(128, 256), _cnn_block(256, 256), nn.AvgPool2d(2), nn.Dropout(dropout_rate),
20 _cnn_block(256, 512), _cnn_block(512, 512), nn.AvgPool2d(2), nn.Dropout(dropout_rate),
21 _cnn_block(512, 1024), _cnn_block(1024, 1024), nn.AvgPool2d(2), nn.Dropout(dropout_rate),
22 nn.AdaptiveAvgPool2d(1), nn.Dropout(dropout_rate), nn.Flatten(),
23 nn.Linear(1024, 1024), nn.ReLU(), nn.Dropout(dropout_rate),
24 nn.Linear(1024, num_labels),
25 ]
26 self.acoustic_model = nn.Sequential(*layers)
27
28 def forward(self, x):
29 return self.acoustic_model(x)
30
31
32model = CNN12Hub.from_pretrained("utrechtuniversity/chimp-vocalization-cnn12-synthetic")
33model.eval()preprocess.py (dependent only on librosa, numpy, scipy — no need to install the full source package) is included in this repo, reproducing the exact training-time feature extraction:1from huggingface_hub import hf_hub_download
2import importlib.util
3import torch
4
5path = hf_hub_download("utrechtuniversity/chimp-vocalization-cnn12-synthetic", "preprocess.py")
6spec = importlib.util.spec_from_file_location("preprocess", path)
7preprocess = importlib.util.module_from_spec(spec)
8spec.loader.exec_module(preprocess)
9
10features = preprocess.extract_features("my_recording.wav") # (3, n_mel, n_frames)
11chunks = preprocess.chunk_features(features) # (n_chunks, 3, n_mel, 64)
12
13with torch.no_grad():
14 probs = torch.softmax(model(torch.from_numpy(chunks).float()), dim=1)Zwerts, J. A., Treep, J., Kaandorp, C. S., Meewis, F., Koot, A. C., & Kaya, H. (2021).
Introducing a central african primate vocalisation dataset for automated species classification.
arXiv preprint. https://arxiv.org/pdf/2101.10390.pdf
Zwerts, J., Treep, J., Zahedi, P., & Kaandorp, C. (2024).
Central African Primate vocalization bioacoustics dataset: Yoda Data publication platform of Utrecht University.