Skip to main content

Deep learning model for detecting and classifying bat echolocation calls in high frequency audio recordings.

Project description

BatDetect2

Code for detecting and classifying bat echolocation calls in high frequency audio recordings.

Getting started

Python Environment

We recommend using an isolated Python environment to avoid dependency issues. Choose one of the following options:

  • Install the Anaconda Python 3.10 distribution for your operating system from here. Create a new environment and activate it:
conda create -y --name batdetect2 python==3.10
conda activate batdetect2
  • If you already have Python installed (version >= 3.8,< 3.11) and prefer using virtual environments then:
python -m venv .venv
source .venv/bin/activate

Installing BatDetect2

You can use pip to install batdetect2:

pip install batdetect2

Alternatively, download this code from the repository (by clicking on the green button on top right) and unzip it. Once unziped, run this from extracted folder.

pip install .

Make sure you have the environment activated before installing batdetect2.

Try the model

  1. You can try a demo of the model (for UK species) on huggingface.

  2. Alternatively, click here to run the model using Google Colab. You can also run this notebook locally.

Running the model on your own data

After following the above steps to install the code you can run the model on your own data.

Using the command line

You can run the model by opening the command line and typing:

batdetect2 detect AUDIO_DIR ANN_DIR DETECTION_THRESHOLD

e.g.

batdetect2 detect example_data/audio/ example_data/anns/ 0.3

AUDIO_DIR is the path on your computer to the audio wav files of interest. ANN_DIR is the path on your computer where the model predictions will be saved. The model will output both .csv and .json results for each audio file. DETECTION_THRESHOLD is a number between 0 and 1 specifying the cut-off threshold applied to the calls. A smaller number will result in more calls detected, but with the chance of introducing more mistakes.

There are also optional arguments, e.g. you can request that the model outputs features (i.e. estimated call parameters) such as duration, max_frequency, etc. by setting the flag --spec_features. These will be saved as *_spec_features.csv files: batdetect2 detect example_data/audio/ example_data/anns/ 0.3 --spec_features

You can also specify which model to use by setting the --model_path argument. If not specified, it will default to using a model trained on UK data e.g. batdetect2 detect example_data/audio/ example_data/anns/ 0.3 --model_path models/Net2DFast_UK_same.pth.tar

Using the Python API

If you prefer to process your data within a Python script then you can use the batdetect2 Python API.

from batdetect2 import api

AUDIO_FILE = "example_data/audio/20170701_213954-MYOMYS-LR_0_0.5.wav"

# Process a whole file
results = api.process_file(AUDIO_FILE)

# Or, load audio and compute spectrograms
audio = api.load_audio(AUDIO_FILE)
spec = api.generate_spectrogram(audio)

# And process the audio or the spectrogram with the model
detections, features, spec = api.process_audio(audio)
detections, features = api.process_spectrogram(spec)

# Do something else ...

You can integrate the detections or the extracted features to your custom analysis pipeline.

Training the model on your own data

Take a look at the steps outlined in fintuning readme here for a description of how to train your own model.

Data and annotations

The raw audio data and annotations used to train the models in the paper will be added soon. The audio interface used to annotate audio data for training and evaluation is available here.

Warning

The models developed and shared as part of this repository should be used with caution. While they have been evaluated on held out audio data, great care should be taken when using the model outputs for any form of biodiversity assessment. Your data may differ, and as a result it is very strongly recommended that you validate the model first using data with known species to ensure that the outputs can be trusted.

FAQ

For more information please consult our FAQ.

Reference

If you find our work useful in your research please consider citing our paper which you can find here:

@article{batdetect2_2022,
    title     = {Towards a General Approach for Bat Echolocation Detection and Classification},
    author    = {Mac Aodha, Oisin and  Mart\'{i}nez Balvanera, Santiago and  Damstra, Elise and  Cooke, Martyn and  Eichinski, Philip and  Browning, Ella and  Barataudm, Michel and  Boughey, Katherine and  Coles, Roger and  Giacomini, Giada and MacSwiney G., M. Cristina and  K. Obrist, Martin and Parsons, Stuart and  Sattler, Thomas and  Jones, Kate E.},
    journal   = {bioRxiv},
    year      = {2022}
}

Acknowledgements

Thanks to all the contributors who spent time collecting and annotating audio data.

TODOs

  • Release the code and pretrained model
  • Release the datasets and annotations used the experiments in the paper
  • Add the scripts used to generate the tables and figures from the paper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batdetect2-1.0.4.tar.gz (7.1 MB view details)

Uploaded Source

Built Distribution

batdetect2-1.0.4-py3-none-any.whl (7.1 MB view details)

Uploaded Python 3

File details

Details for the file batdetect2-1.0.4.tar.gz.

File metadata

  • Download URL: batdetect2-1.0.4.tar.gz
  • Upload date:
  • Size: 7.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for batdetect2-1.0.4.tar.gz
Algorithm Hash digest
SHA256 4fadcf603ccdbd26a578ac5f8aaa225a29d7b249ebcf099b97ab9d48cc6184b5
MD5 de228453dd3b0ce251407ddd44b5a343
BLAKE2b-256 c178d302225d7f93f8ea07b621dd698a5263f8fc0c45c6be21d7131be6b63b3a

See more details on using hashes here.

File details

Details for the file batdetect2-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: batdetect2-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for batdetect2-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0e9e1e0b70eeef2ae8d79bdfaeaf0dbe2a02982911fe8da427e0700790f07095
MD5 ff03e4cdba2ebfae1dd91406c188bcd8
BLAKE2b-256 04a6ca81db8e69a0125d53cdfafaf50a689d0107b86b225f50c96c45b147436b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page