Classifier
How it works
To train the model with train.py, the user first needs to convert audio data into features.
SVM
Data segmentation
The labeled audio is split into frames of 0.5 seconds with 0.25 seconds overlap.
Feature selection
When running the SVM models, features are selected in the preprocessing steps of the training script. With 1,140 acoustic features as input, exploratory recursive feature elimination indicated a broad optimum around 50 features.
In the actual preprocessing pipeline, the SVM workflow uses an Extra Trees Classifier to rank features and retain the 50 most important ones. The same ranking is saved so the same subset can be reused during training and prediction.
CNN
Training segmentation
During training, a random cropping strategy is used. Each training sample is generated by selecting a random temporal window of 64 frames from a full-length spectrogram. File selection is weighted by inverse class frequency and recording length to address class imbalance and preserve proportional sampling across recordings. The number of random crops per epoch is set to 11,200.
Evaluation segmentation
During evaluation, each recording is divided into non-overlapping sequential chunks of 64 frames. The final chunk is zero-padded if shorter than 64 frames. Chunk-level predictions are aggregated to file-level predictions by averaging predicted probabilities across all chunks for each file. A fixed threshold of 0.5 is then applied to the positive class probability.
Data augmentation
SpecAugment is applied to each training batch to improve model robustness. The augmentation uses two frequency masks of up to 8 mel bins each and two time masks of up to 10 frames each, applied with probability 0.7 per sample.
Model architecture
The main deep learning model is CNN10, based on the architecture introduced in the PANNs paper (Kong et al., 2020). It consists of four convolutional blocks, each with two convolutional layers using 3x3 kernels and same padding, followed by batch normalization, ReLU activation, average pooling with a 2x2 kernel, and dropout. The number of filters doubles across blocks: 64, 128, 256, and 512. Global average pooling reduces the final feature maps to a 512-dimensional vector, which is passed through a fully connected layer with ReLU activation and dropout, then to a final linear layer with two outputs corresponding to background and chimpanzee classes. Weights are initialized with He normal initialization. A 12-layer variant, CNN12, is also available.
Training configuration
The model is trained with AdamW using a learning rate of 1e-4, weight decay of 1e-3, batch size 32, and 20 epochs. A dropout rate of 0.5 is applied throughout the network, and a max-norm constraint of 4 is enforced on all layers. A ReduceLROnPlateau scheduler monitors validation F1 score and reduces the learning rate by a factor of 0.5 after two stagnant epochs, down to a minimum learning rate of 1e-6. The checkpoint with the highest validation F1 score is retained for evaluation.
Software requirements
Basic usage
Train
python bioacoustics/classifier/train.py --config_file "config/testdata.yml"Evaluate
python bioacoustics/classifier/evaluate.py --config_file "config/testdata.yml"Predict
python bioacoustics/classifier/predict.py --config_file "config/testdata.yml"References
- Kong, Q., Cao, Y., Iqbal, T., Wang, Y., Wang, W., & Plumbley, M. D. (2020). PANNs: Large-Scale Pretrained Audio Neural Networks for Audio Pattern Recognition. IEEE/ACM Transactions on Audio, Speech, and Language Processing, 28, 2880–2894.^M