Automatic Bird Sound Identification
Deep Learning & Transfer Learning on 397 Species

MSc Independent Project - University of Peradeniya, Sri Lanka
ResNet Transfer Learning, Mel-Spectrograms

MSc in Data Science · Postgraduate Institute of Science, University of Peradeniya · Sri Lanka · 2021

Automatic Bird Sound Identification Using Machine Learning

Classifying 397 bird species from 62,874 field recordings by transforming raw audio into Mel-spectrograms and fine-tuning pretrained ResNet models.

MSc Independent Project University of Peradeniya Sri Lanka
PyTorch ResNet Transfer Learning Librosa Mel-Spectrograms

Supervisor: Mr. Prabath Gunathilake (Lecturer, Department of Statistics and Computer Science, University of Peradeniya, Sri Lanka)

Additional Resources: Project Report (PDF) · Dataset (Xeno-canto)

Identifying bird species from their calls matters for conservation, many species are endangered, and protecting them starts with knowing which species is present and where. But audio is a much harder classification problem than images: recordings are noisy, calls overlap with background species, and traditional machine learning approaches don't hold up well against that noise. Deep learning has changed that, though it typically demands more labeled data and compute than a single independent project can gather from scratch.

This project sidesteps that data bottleneck with transfer learning. Using 62,874 recordings across 397 bird species from Xeno-canto, a citizen-science bird sound archive, I converted each clip into a Mel-spectrogram and fine-tuned ImageNet-pretrained ResNet models to classify species from that image representation, rather than training a network from scratch on a comparatively small bioacoustic dataset. The best model, ResNet18, reached an average precision of 0.62 across all 397 species.

Methodology

From field recordings to a species classifier

Four stages take raw, variable-length field recordings to a fine-tuned image classifier.

01

Dataset & Long-Tail Imbalance

62,874 recordings across 397 species, capped at 500 recordings per species, still a steep long-tail distribution. Recordings span the globe, are variable length, and are only weakly labeled: a clip's target species doesn't necessarily vocalize throughout.

02

Audio → Mel-Spectrogram

Every recording is resampled and converted to a Mel-spectrogram with Librosa. Window length and chunk duration were tested directly against each other before settling on 7-second segments, padded or randomly sampled to a fixed size, and saved as precomputed arrays.

03

Transfer Learning with ResNet

ImageNet-pretrained ResNet18, ResNet101, ResNet152, and resnext50_32x4d each had their final layer swapped for a 397-way classifier head, then fine-tuned with Adam (learning rate 0.005, categorical cross-entropy) for 20 epochs, roughly 5–6 hours per model.

04

Evaluation

Training and validation precision and F1-score were tracked across all four architectures to compare how well each generalized to species it hadn't overfit to, rather than relying on raw accuracy alone in a heavily imbalanced, 397-class setting.

Built With

Tools & Stack

PyTorch ResNet18 / 101 / 152 resnext50_32x4d Librosa Mel-Spectrograms Transfer Learning Adam Optimizer Xeno-canto
Results

What actually moved the needle

Comparing four architectures under identical training conditions isolated what mattered, and what didn't.

Model Comparison

Which pretrained architecture generalizes best to 397 overlapping, noisy bird calls?

Four ImageNet-pretrained backbones: ResNet18, ResNet101, ResNet152, and resnext50_32x4d, were fine-tuned identically: same Mel-spectrogram input, same 20-epoch schedule, same learning rate, to isolate the effect of architecture alone.

Solution

The smallest model won. ResNet18 reached an average precision of 0.62, ahead of resnext50_32x4d at 0.57. More capacity didn't help here, deeper networks weren't the bottleneck; the audio representation and the long-tail, weakly-labeled dataset were.

Class Imbalance & Weak Labels

Can species with only a handful of recordings be classified at all?

Training data follows a steep long-tail distribution capped at 500 recordings for the most common species, and individual clips are only weakly labeled, the target species doesn't necessarily vocalize during every extracted chunk.

Solution

Segments were extracted at a 7-second sweet spot, balancing memory against how much of a call gets captured, with padding for short clips and random-start sampling for long ones. The project's own conclusion flags better handling of this weak labeling as the most promising lever left to pull.

The on-device side of this project, using the trained model to build a low-power TinyML bird call identification device on a microcontroller, was scoped but ultimately set aside due to time constraints. It remains the most concrete next step: on-sensor inference would cut both the power cost and the privacy concerns of streaming raw audio to the cloud for classification.