This repository contains the solution for detecting European Bee-eater (Merops apiaster, eBird code: #eubeat1) vocalizations in audio recordings using Google's Perch v2 bioacoustics model.
The solution uses a transfer learning approach with Google's pre-trained Perch v2 model:
repo/
├── perch2/ # Main Perch-based solution
│ ├── train_perch.py # Training script
│ ├── predict_perch.py # Prediction script
│ ├── evaluate_perch.py # Evaluation and hyperparameter tuning
│ ├── calculate_fbeta.py # F-beta score calculation
│ ├── merge_predictions.py # Merge multiple prediction files
│ ├── generate_baseline.py # Generate baseline predictions
│ ├── perch.py # Perch model wrapper utilities
│ ├── requirements.txt # Python dependencies
│ └── run_complete_workflow.sh # Complete workflow automation
├── automathon.py # Initial exploration with NatureLM
├── nature.py # NatureLM model setup
├── victory.py # Refinement pipeline (not used in final)
├── iterative_prediction_tuning.py # Iterative prediction optimization
├── generate_variations.py # Generate prediction variations
└── compute_timestamp_difference.py # Compare predictions
cd repo/perch2
python3 -m venv .venvperch
source .venvperch/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
Note: Installation includes TensorFlow with CUDA support for GPU acceleration. ⚡
Train the classifier on the bird songs dataset:
python train_perch.py
This will:
../models/perch_beeeater_classifier.pklTraining time: ~10-30 minutes depending on hardware ⏱️
Generate predictions on validation dataset:
python predict_perch.py \
--input-dir ../dataset_validation \
--output ../predictions_perch.json \
--threshold 0.4 \
--min-duration 0.5 \
--merge-gap 2.0 \
--hop 1.0
Parameters:
--threshold: Detection confidence threshold (0-1). Lower = more detections, higher recall--min-duration: Minimum detection duration in seconds (default: 0.5)--merge-gap: Merge detections within this gap in seconds (default: 2.0)--hop: Sliding window hop size in seconds (default: 1.0). Smaller = more precise but slowerFor high recall (recommended for rare species) 🎯:
python predict_perch.py --threshold 0.3 --min-duration 0.3 --hop 0.5
Evaluate predictions against ground truth:
python calculate_fbeta.py \
--ground-truth ../dataset/parc_audios/timestamps.json \
--predictions ../predictions_perch.json \
--beta 1.0
The prediction scripts generate JSON files in the required format:
{
"audios": {
"1": {
"id": "1",
"timestamps": []
},
"3": {
"id": "3",
"timestamps": [
[29.71, 103.14],
[150.22, 165.88]
]
}
}
}
Where each timestamp is [start_time, end_time] in seconds.
Use the evaluation script to find optimal parameters:
python evaluate_perch.py \
--mode grid \
--ground-truth ../dataset/parc_audios/timestamps.json \
--audio-dir ../dataset/parc_audios/data
This will test multiple combinations of threshold, min_duration, merge_gap, and hop parameters to maximize F-beta score.
For processing large datasets, use the array job script:
# Process files in parallel (requires SLURM)
sbatch predict_perch_array.sbatch
# Merge results
python merge_predictions.py
Generate multiple prediction variations for ensemble or optimization:
python generate_variations.py \
--base-predictions predictions_perch.json \
--num-variations 10 \
--output-dir variations/
Analyze differences between prediction files:
python compute_timestamp_difference.py \
--prediction1 predictions_v1.json \
--prediction2 predictions_v2.json
The repository includes experimental code for NatureLM, a large language model for bioacoustics that can identify species from audio. While not used in the final competition solution, it can serve as an additional filter or validation tool:
from NatureLM.models import NatureLM
from NatureLM.infer import Pipeline
model = NatureLM.from_pretrained("EarthSpeciesProject/NatureLM-audio")
model = model.eval().to("cuda")
pipeline = Pipeline(model=model)
queries = ["What is the common name for the bird species in the audio?"]
# Run over audio segments
results = pipeline(audio_paths, queries, window_length_seconds=10.0)
Use cases for NatureLM:
Note: NatureLM was not included in the final solution due to computational requirements and optimization for the competition's scoring metric.
Based on validation results:
Reduce batch size in prediction or use CPU mode:
export CUDA_VISIBLE_DEVICES="" # Force CPU mode
Ensure Kaggle API credentials are configured:
pip install kaggle
# Place kaggle.json in ~/.kaggle/
chmod 600 ~/.kaggle/kaggle.json
Install additional audio backends:
pip install soundfile pysoundfile audioread
This solution uses Google's Perch model:
@article{perch2024,
title={Perch: A Scalable Bioacoustic Foundation Model},
author={Google Research},
year={2024}
}
This code is provided for the competition. Please respect the licenses of the underlying models:
4 commits
Python
96.7%
Shell
3.3%
This repository contains the solution for detecting European Bee-eater (Merops apiaster, eBird code: #eubeat1) vocalizations in audio recordings using Google's Perch v2 bioacoustics model.
The solution uses a transfer learning approach with Google's pre-trained Perch v2 model:
repo/
├── perch2/ # Main Perch-based solution
│ ├── train_perch.py # Training script
│ ├── predict_perch.py # Prediction script
│ ├── evaluate_perch.py # Evaluation and hyperparameter tuning
│ ├── calculate_fbeta.py # F-beta score calculation
│ ├── merge_predictions.py # Merge multiple prediction files
│ ├── generate_baseline.py # Generate baseline predictions
│ ├── perch.py # Perch model wrapper utilities
│ ├── requirements.txt # Python dependencies
│ └── run_complete_workflow.sh # Complete workflow automation
├── automathon.py # Initial exploration with NatureLM
├── nature.py # NatureLM model setup
├── victory.py # Refinement pipeline (not used in final)
├── iterative_prediction_tuning.py # Iterative prediction optimization
├── generate_variations.py # Generate prediction variations
└── compute_timestamp_difference.py # Compare predictions
cd repo/perch2
python3 -m venv .venvperch
source .venvperch/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
Note: Installation includes TensorFlow with CUDA support for GPU acceleration. ⚡
Train the classifier on the bird songs dataset:
python train_perch.py
This will:
../models/perch_beeeater_classifier.pklTraining time: ~10-30 minutes depending on hardware ⏱️
Generate predictions on validation dataset:
python predict_perch.py \
--input-dir ../dataset_validation \
--output ../predictions_perch.json \
--threshold 0.4 \
--min-duration 0.5 \
--merge-gap 2.0 \
--hop 1.0
Parameters:
--threshold: Detection confidence threshold (0-1). Lower = more detections, higher recall--min-duration: Minimum detection duration in seconds (default: 0.5)--merge-gap: Merge detections within this gap in seconds (default: 2.0)--hop: Sliding window hop size in seconds (default: 1.0). Smaller = more precise but slowerFor high recall (recommended for rare species) 🎯:
python predict_perch.py --threshold 0.3 --min-duration 0.3 --hop 0.5
Evaluate predictions against ground truth:
python calculate_fbeta.py \
--ground-truth ../dataset/parc_audios/timestamps.json \
--predictions ../predictions_perch.json \
--beta 1.0
The prediction scripts generate JSON files in the required format:
{
"audios": {
"1": {
"id": "1",
"timestamps": []
},
"3": {
"id": "3",
"timestamps": [
[29.71, 103.14],
[150.22, 165.88]
]
}
}
}
Where each timestamp is [start_time, end_time] in seconds.
Use the evaluation script to find optimal parameters:
python evaluate_perch.py \
--mode grid \
--ground-truth ../dataset/parc_audios/timestamps.json \
--audio-dir ../dataset/parc_audios/data
This will test multiple combinations of threshold, min_duration, merge_gap, and hop parameters to maximize F-beta score.
For processing large datasets, use the array job script:
# Process files in parallel (requires SLURM)
sbatch predict_perch_array.sbatch
# Merge results
python merge_predictions.py
Generate multiple prediction variations for ensemble or optimization:
python generate_variations.py \
--base-predictions predictions_perch.json \
--num-variations 10 \
--output-dir variations/
Analyze differences between prediction files:
python compute_timestamp_difference.py \
--prediction1 predictions_v1.json \
--prediction2 predictions_v2.json
The repository includes experimental code for NatureLM, a large language model for bioacoustics that can identify species from audio. While not used in the final competition solution, it can serve as an additional filter or validation tool:
from NatureLM.models import NatureLM
from NatureLM.infer import Pipeline
model = NatureLM.from_pretrained("EarthSpeciesProject/NatureLM-audio")
model = model.eval().to("cuda")
pipeline = Pipeline(model=model)
queries = ["What is the common name for the bird species in the audio?"]
# Run over audio segments
results = pipeline(audio_paths, queries, window_length_seconds=10.0)
Use cases for NatureLM:
Note: NatureLM was not included in the final solution due to computational requirements and optimization for the competition's scoring metric.
Based on validation results:
Reduce batch size in prediction or use CPU mode:
export CUDA_VISIBLE_DEVICES="" # Force CPU mode
Ensure Kaggle API credentials are configured:
pip install kaggle
# Place kaggle.json in ~/.kaggle/
chmod 600 ~/.kaggle/kaggle.json
Install additional audio backends:
pip install soundfile pysoundfile audioread
This solution uses Google's Perch model:
@article{perch2024,
title={Perch: A Scalable Bioacoustic Foundation Model},
author={Google Research},
year={2024}
}
This code is provided for the competition. Please respect the licenses of the underlying models:
4 commits
Python
96.7%
Shell
3.3%