Skip to content

birdnet analyzer#

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_analyzer]"

audioclass.models.birdnet_analyzer #

Audio Classification Module for Bird Sound Detection.

This module provides tools for loading and using the BirdNET sound event detection model. BirdNET is a deep learning model designed to classify bird species from audio recordings.

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.

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.

SAVED_MODEL_PATH = DATA_DIR / 'BirdNET_GLOBAL_6K_V2.4' module-attribute #

Classes#

BirdNETAnalyzer(callable, signature, tags, confidence_threshold, samplerate, name, logits=True) #

Bases: TensorflowModel

BirdNET sound event detection model.

This class loads and wraps the BirdNET TensorFlow SavedModel for bird sound classification and embedding extraction.

Parameters:

Name Type Description Default
callable Callable

The TensorFlow callable representing the model.

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_url=SAVED_MODEL_PATH, tags_url=LABELS_PATH, confidence_threshold=DEFAULT_THRESHOLD, samplerate=SAMPLERATE, name='BirdNET') classmethod #

Load a BirdNET model from a saved model directory.

Parameters:

Name Type Description Default
model_url Union[Path, str]

The path to the saved model directory. Defaults to a local copy of the BirdNET model.

SAVED_MODEL_PATH
tags_url Union[Path, str]

The URL or path to the file containing the labels. Defaults to the labels file in the BirdNET repository.

LABELS_PATH
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 SAMPLERATE.

SAMPLERATE
name str

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

'BirdNET'

Returns:

Type Description
BirdNETAnalyzer

An instance of the BirdNET model.

Functions#

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.