BatSpot ONNX Model (search-call classifier)
ONNX conversion of the BatSpot search-phase call classifier, a ResNet18 convolutional neural network that classifies bat echolocation calls to species (or species complex) from true ultrasonic audio recorded at 250 kHz.
BatSpot is described in:
Smeele, S.Q., Hauer, C., Bergler, C., Dechmann, D.K., Dietzer, M.T., Elmeros, M., Fjederholt, E.T., Fogato, A., Kohles, J.E., Nöth, E. and Brinkløv, S.M. (2026). BatSpot: a retrainable neural network for automatic detection and classification of bat echolocation and detection of buzzes and social calls. Biological Conservation, 321, 111975.
It is built on ANIMAL-SPOT (Bergler et al.). This ONNX file is a numerically verified conversion of the published PyTorch checkpoint. The model was not retrained or modified.
Purpose
This conversion exists so that BatSpot can run inside BirdNET-Go, a real-time acoustic monitoring application, next to the bird models and the other bat model there (BSG-BAT). It also works with any ONNX Runtime pipeline in Python, Go, C++ or other languages, without PyTorch.
Why BatSpot in addition to BSG-BAT:
- It is a different, independently trained model: a ResNet18 on 20 ms linear-frequency spectrograms rather than a CNN on 1 s mel spectrograms. Agreement between the two is useful evidence when deciding whether a detection is real.
- It covers species that BSG-BAT does not: Myotis dasycneme, Myotis nattereri and the Myotis brandtii/mystacinus complex.
- It recognises feeding buzzes and social calls as their own classes rather than mislabelling them as a species.
- The original pipeline is designed to be retrained with small amounts of local data (see the article).
Only the search-phase call classifier (models_call_classifier/m09) is converted here. The original release also contains a call detector, a buzz detector and a social-call detector. Those are not included yet.
How it works
mono audio, resampled to 250 kHz
-> sliding window 5000 samples (20 ms), hop 1250 samples (5 ms) in the original predict.py
-> pre-emphasis y[n] = x[n] - 0.98 x[n-1] (y[0] = x[0]), per window
-> STFT n_fft 256, hop 128, periodic Hann, no centering, power = |X|^2 / 96
-> frequency crop bins 10..127 (~9.8-124 kHz), stretched to 256 bins (nearest, j*118//256)
-> dB 10*log10(max(P, 1e-10))
-> min-max normalise per window, to [0, 1] (a constant window becomes all zeros)
-> ResNet18 [1,1,38,256] -> [1,15] logits
-> softmax; argmax is a detection when its probability >= 0.5 (original default threshold)
reference_frontend.py is a standalone numpy implementation of this front end. It matches ANIMAL-SPOT's torch data pipeline to 5.6e-6 on real recordings, and every constant is documented in it.
Model architecture
- Input:
spectrogram[batch, 1, frames, 256]float32.frames= 38 for a full 20 ms window. Batch and frames are dynamic axes. - Output:
logits[batch, 15]float32, raw logits. Apply softmax: the model is single-label and was trained with cross-entropy. - Backbone: ANIMAL-SPOT ResNet18 encoder (7x7 conv stem, no max-pool), global average pooling, Linear(512 -> 15). See
original_code/models/.
Classes (output index order)
batspot_labels.txt lists the 15 classes in model index order, as Scientific name_Common name for species:
0 B (feeding buzz / approach phase) 8 noise
1 Barbastella barbastellus 9 Plecotus auritus
2 Eptesicus serotinus 10 Pipistrellus nathusii
3 Myotis brandtii/mystacinus 11 Pipistrellus pipistrellus
4 Myotis dasycneme 12 Pipistrellus pygmaeus
5 Myotis daubentonii 13 s (social call)
6 Myotis nattereri 14 Vespertilio murinus
7 Nyctalus noctula
noise, B and s are not species. Applications should report them separately or drop them. labels_map.md maps the original short codes (bbar, eser, mbramys, ...) to these names.
Files
| File | Description |
|---|---|
batspot_m09.onnx |
The call classifier (FP32, opset 17, ~43 MB, weights inline) |
batspot_labels.txt |
15 class labels in output index order |
labels_map.md |
Original class codes -> labels |
reference_frontend.py |
numpy reference implementation of the preprocessing |
export_onnx.py |
The script used to convert the PyTorch checkpoint and verify parity |
original_code/ |
ANIMAL-SPOT model, data and predict code used by BatSpot (GPL-3.0, see original_code/LICENSE) and the m09 train/predict configs |
SHA256SUMS |
Checksums for all files |
Usage with Python (ONNX Runtime)
import numpy as np, soundfile as sf, resampy, onnxruntime as ort
from reference_frontend import frontend # see reference_frontend.py
y, sr = sf.read("bat_recording.wav", dtype="float32", always_2d=True)
y = resampy.resample(y.mean(axis=1), sr, 250000, filter="kaiser_best")
wins = [y[i:i + 5000] for i in range(0, len(y) - 5000 + 1, 1250)]
x = np.concatenate([frontend(w) for w in wins]) # [n, 1, 38, 256]
sess = ort.InferenceSession("batspot_m09.onnx", providers=["CPUExecutionProvider"])
logits = sess.run(["logits"], {"spectrogram": x})[0]
p = np.exp(logits - logits.max(1, keepdims=True)); p /= p.sum(1, keepdims=True)
labels = [l.strip() for l in open("batspot_labels.txt") if l.strip()]
for i in np.where(p.max(1) >= 0.5)[0]:
k = p[i].argmax()
if labels[k] not in ("noise", "B", "s"):
print(f"{i * 0.005:.3f}s {labels[k]} {p[i, k]:.2f}")
Conversion details
- Source:
BatSpot_article/batspot/models_call_classifier/m09/train/ANIMAL-SPOT.pkfrom the Zenodo release. - Exported with
torch.onnx.export(PyTorch 2.15, opset 17), dynamic batch and time axes, constant folding on. - Verified: PyTorch vs ONNX Runtime max absolute logit difference 2.1e-5 over 12 inputs (batch 1/2/4, 38 and 20 frames). End to end, the numpy front end plus ONNX differs from the full original torch path by 1.4e-4 in logits.
- The original
predict.pyreferences an undefinednum_classesand fails as shipped. The behaviour documented above (softmax, argmax, threshold) is the evident intent of that code.
Audio requirements and limitations
- Sample rate: 250 kHz mono. Recordings at 256, 384 or 500 kHz can be resampled down. Lower rates lose part of the 10-125 kHz band the model reads.
- Codec: lossless (WAV/FLAC) only. Lossy codecs discard ultrasonic content.
- Level is discarded: min-max normalisation runs per 20 ms window, so faint background noise gets stretched to full range. Gate windows on signal energy before classifying, and skip digital silence: an all-zero window yields a meaningless low-confidence species guess.
- Standalone use: in the original pipeline this classifier runs on calls already found by the call detector. Used alone, it relies on its
noiseclass and on the application's own gating. - Cost: about 60 ms of CPU per 20 ms window on a low-power x86 core (single thread). Scoring every 5 ms hop in real time is not practical on small devices, so select candidate windows first.
- Geographic scope: the classifier covers 12 European species or complexes; see the article for where its training data come from. It cannot recognise species outside this list.
License
- Model weights and this ONNX conversion: CC-BY-4.0, following the original Zenodo release. You may use, share and adapt them, including commercially, with attribution.
original_code/: GPL-3.0, from Hauechri/BatSpot (ANIMAL-SPOT), redistributed unmodified with its licence.
Citation and attribution
If you use this model, please cite the original article and data release:
Smeele, S.Q., Hauer, C., Bergler, C., Dechmann, D.K., Dietzer, M.T., Elmeros, M., Fjederholt, E.T., Fogato, A., Kohles, J.E., Nöth, E. and Brinkløv, S.M. (2026). BatSpot: a retrainable neural network for automatic detection and classification of bat echolocation and detection of buzzes and social calls. Biological Conservation, 321, 111975.
Data, code and models: Zenodo, https://doi.org/10.5281/zenodo.18977979
and ANIMAL-SPOT:
Bergler, C. et al. (2022). ANIMAL-SPOT enables animal-independent signal detection and classification using deep learning. Scientific Reports, 12, 21966.
Acknowledgments
- Simeon Q. Smeele, Christian Hauer, Christian Bergler and the BatSpot co-authors for the model, training data, code and open release (CC-BY-4.0).
- Christian Bergler and the ANIMAL-SPOT team for the underlying framework.
- tphakala for BirdNET-Go and the BSG-BAT conversion that this card follows.
- Conversion to ONNX by alexbelgium for use with BirdNET-Go and other ONNX Runtime pipelines.