birdbrain.songperch

Birdbrain: offline bird ID and a birdsong generator

An app (Songperch) that identifies UK birds from their song, entirely on the phone with no network. The model is distilled from a large bioacoustics model, and the app sings back with birdsong it generates itself. No agents here: this one is about training, distillation and the MLOps to do it cheaply on spot GPUs.

Why

I wanted a bird app that works in a field with no signal, and a project that exercised the whole ML lifecycle: data, licences, training, export, on-device evaluation. It will stay non-commercial, released free.

What

Perch 2.0 (Google DeepMind) as the teacher, distilled into an EfficientNet-B0 student that runs on the phone with ONNX Runtime. It covers 250 UK species plus "other bird" and "noise".

How

One GPU box that I bring up and tear down, with S3 as the source of truth. Every job checkpoints and resumes. Every training item and generated asset carries its licence.

Five slides

01 · Teacher and student

A big model teaches a small one

Perch 2.0 is a state-of-the-art bioacoustics model with about 15K classes, but it's too heavy for a phone. I put a linear probe on its embeddings for our 250 species (the teacher), then trained an EfficientNet-B0 student on a mix of true labels and the teacher's soft targets.

The student exports to ONNX at 21.8 MB, and its output matches PyTorch to within 8e-7.

02 · Data, grouped by recordist

Test on people the model has never heard

  • 37,088 Xeno-canto recordings from Europe, quality A-C, at most 150 per species and 10 per recordist, plus 3,795 noise clips.
  • That's 176,800 five-second windows, stored as 11.3 GB of uint8 log-mels.
  • Splits are grouped by recordist, so no test recordist appears in training. That's harsher than a random split, and more honest.
03 · What distillation cost

About 0.2 F1, and confidence

  • Top-1 held up well (0.787 against the teacher's 0.815), but macro-F1 fell from 0.716 to 0.499.
  • The student is under-confident: 0.71 average top probability when right, against the teacher's 0.97. Calibration is a cheap fix.
  • It makes far fewer false calls on unseen birds (0.065 against 0.336).
  • int8 halves the size but loses another 0.1 macro-F1, so it doesn't ship.
04 · Birdsong from a few KB

Cut syllables, learn the order, walk it forever

  1. Pick clean A-grade recordings. Find the song's frequency band, denoise, and cut syllables and phrases.
  2. Perch listens to every cleaned phrase. Keep it only if it hears the target species (at least 15%, top 3).
  3. Cluster syllable shapes into 6-48 types. Learn a second-order Markov chain over them, with the gaps between.
  4. Pack each species' examples into a small Opus atlas plus a JSON model. The phone walks the chain, so the song never repeats.
05 · Our own generative stack

Art from open weights on our own GPU

Every bird has four art themes (pencil to colour, anime, 16-bit, 8-bit), made by FLUX.2 klein-9B edit chains from an iNaturalist photo, on the same spot GPU box. No hosted generation APIs. Each asset's manifest records the model, config, seed and source photo licence.

Results: UK250, test split, per recording

ModelTop-1Macro-F1Recall at 0.7False calls (other / unseen / noise)
Teacher (Perch 2.0 + probe)0.8150.7160.7240.147 / 0.336 / 0.014
Student, ONNX fp32 (shipped, 21.8 MB)0.7870.4990.2440.016 / 0.065 / 0.000
Student, ONNX int8 (9.6 MB)0.7420.3990.1410.000 / 0.019 / 0.000

Broken down by how much training data each species had, the gap to the teacher is about 0.22-0.25 F1 for most species and 0.12 for the best-covered. The rarest quarter is weak for both (teacher 0.39), which points at data first: Xeno-canto worldwide roughly doubles the tail, and iNaturalist sounds add a lot for some species.

The MLOps

~$13.7
UK250 total: ingest, teacher, student, export
2.7 min
per epoch on an A10G spot (6.0 on a T4)
~$0.30
per screening experiment (8-10 epochs, 25 min)
246/250
species with a generated song on the phone
  1. The box is a cache. Raw media, manifests, features, models and runs live in S3. A job syncs down, runs and syncs back up, and the CLIs refuse to run on the laptop.
  2. Spot-safe by default. Checkpoints every epoch, synced to S3 every 2 minutes and again on the spot interruption notice. A boot service re-runs an interrupted job, up to 5 attempts. Verified unattended: stopped after epoch 2, resumed and finished.
  3. Measure the hardware. Both GPUs were the bottleneck (batch prep took 4.9 ms against 146 ms per step), so the A10G's 2.2× speed made it cheaper per run than the T4. torch.compile gave +2%, which wasn't worth it.
  4. Evaluate on the device. Every iteration ends with a release build on the phone, plus a local review tool: play each detection, approve, reject or relabel it, and score precision at several thresholds.

Listen: generated birdsong

This runs the app's song generator in your browser. Each bird is a small Opus atlas of its own syllables plus a song model, about 70-115 KB together. Every tap walks the chain afresh, so you won't hear the same song twice.

Tap a bird to start, and tap again to stop.

Credits: syllables are cut from Xeno-canto recordings shared by their recordists under Creative Commons non-commercial licences. The bird teacher is Google DeepMind's Perch 2.0. The art was made with FLUX.2 [klein] from iNaturalist photos (CC BY) by danielskatz (robin), sunjiao (blackbird), dylanfindlay1 (song thrush) and little-grey-bird (wren).