Skip to content

birdnet#

Warning

Additional Dependencies: To use the BirdNET model, you will need to install additional dependencies. These dependencies are optional, as they can be heavy and may not be needed in all use cases. To install them, run:

pip install "audioclass[birdnet]"

audioclass.models.birdnet #

Module for loading and using the BirdNET audio classification model.

This module provides a convenient interface for working with the BirdNET model, which is a TensorFlow Lite-based model designed for bird sound classification. It includes the BirdNET class, which is a subclass of TFLiteModel, and functions for loading the model and its associated labels.

Notes

The BirdNET model was developed by the K. Lisa Yang Center for Conservation Bioacoustics at the Cornell Lab of Ornithology, in collaboration with Chemnitz University of Technology. This package is not affiliated with the BirdNET project.

BirdNET is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

If you use the BirdNET model, please cite:

Kahl, S., Wood, C. M., Eibl, M., & Klinck, H. (2021). BirdNET: A deep
learning solution for avian diversity monitoring. Ecological Informatics,
61, 101236.

For further details, please visit the official BirdNET repository

Attributes#

INPUT_SAMPLES = 144000 module-attribute #

Default number of samples expected in the input tensor.

This value corresponds to 3 seconds of audio data at a sample rate of 48,000 Hz.

LABELS_PATH = 'https://github.com/kahst/BirdNET-Analyzer/raw/main/checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels.txt' module-attribute #

Default path to the BirdNET labels file.

MODEL_PATH = 'https://github.com/kahst/BirdNET-Analyzer/raw/main/checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Model_FP32.tflite' module-attribute #

Default path to the BirdNET TensorFlow Lite model file.

SAMPLERATE = 48000 module-attribute #

Default sample rate of the audio data expected by the model (in Hz).

This value corresponds to the sample rate used by the BirdNET model.

Classes#

BirdNET(interpreter, signature, tags, confidence_threshold, samplerate, name, logits=True) #

Bases: TFLiteModel

BirdNET audio classification model.

This class is a wrapper around a TensorFlow Lite model for bird sound classification. It provides methods for loading the model, processing audio data, and returning predictions.

Parameters:

Name Type Description Default
interpreter Interpreter

The TensorFlow Lite interpreter object.

required
signature Signature

The input and output signature of the model.

required
tags List[Tag]

The list of tags that the model can predict.

required
confidence_threshold float

The minimum confidence threshold for assigning a tag to a clip.

required
samplerate int

The sample rate of the audio data expected by the model (in Hz).

required
name str

The name of the model.

required
logits bool

Whether the model outputs logits (True) or probabilities (False). Defaults to True.

True
Functions#
load(model_path=MODEL_PATH, labels_path=LABELS_PATH, num_threads=None, confidence_threshold=DEFAULT_THRESHOLD, samplerate=SAMPLERATE, name='BirdNET', common_name=False) classmethod #

Load a BirdNET model from a file or URL.

Parameters:

Name Type Description Default
model_path Union[Path, str]

The path or URL to the TensorFlow Lite model file. Defaults to the latest version of the BirdNET model.

MODEL_PATH
labels_path Union[Path, str]

The path or URL to the labels file. Defaults to the latest version of the BirdNET labels.

LABELS_PATH
num_threads Optional[int]

The number of threads to use for inference. If None, the default number of threads will be used.

None
confidence_threshold float

The minimum confidence threshold for making predictions. Defaults to DEFAULT_THRESHOLD.

DEFAULT_THRESHOLD
samplerate int

The sample rate of the audio data expected by the model (in Hz). Defaults to 48,000 Hz.

SAMPLERATE
name str

The name of the model. Defaults to "BirdNET".

'BirdNET'
common_name bool

Whether to use common names for bird species instead of scientific names. Defaults to False.

False

Returns:

Type Description
BirdNET

An instance of the BirdNET class.

Functions#

get_signature(interpreter) #

Get the signature of a BirdNET model.

Parameters:

Name Type Description Default
interpreter Interpreter

The TensorFlow Lite interpreter object.

required

Returns:

Type Description
Signature

The signature of the BirdNET model.

load_tags(path=LABELS_PATH, common_name=False) #

Load BirdNET labels from a file.

Parameters:

Name Type Description Default
path Union[Path, str]

Path or URL to the file containing the labels. Defaults to the latest version of the BirdNET labels.

LABELS_PATH
common_name bool

Whether to return the common name instead of the scientific name. Defaults to False.

False

Returns:

Type Description
List[Tag]

List of soundevent Tag objects.