birdnet package

Subpackages

Submodules

birdnet_benchmark.argparse_helper module

class birdnet_benchmark.argparse_helper.ConvertToOrderedSetAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: _StoreAction

Docstring für ConvertToOrderedSetAction.

class birdnet_benchmark.argparse_helper.ConvertToSetAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: _StoreAction

birdnet_benchmark.argparse_helper.get_optional(method)
Return type:

Callable[[str], Optional[TypeVar(T)]]

birdnet_benchmark.argparse_helper.parse_codec(value)
Return type:

str

birdnet_benchmark.argparse_helper.parse_datetime(value)
Return type:

datetime

birdnet_benchmark.argparse_helper.parse_existing_directory(value)
Return type:

Path

birdnet_benchmark.argparse_helper.parse_existing_file(value)
Return type:

Path

birdnet_benchmark.argparse_helper.parse_float(value)
Return type:

float

birdnet_benchmark.argparse_helper.parse_float_greater_one(value)
Return type:

int

birdnet_benchmark.argparse_helper.parse_integer(value)
Return type:

int

birdnet_benchmark.argparse_helper.parse_integer_greater_one(value)
Return type:

int

birdnet_benchmark.argparse_helper.parse_json(value)
Return type:

dict

birdnet_benchmark.argparse_helper.parse_non_empty(value)
Return type:

str

birdnet_benchmark.argparse_helper.parse_non_empty_or_whitespace(value)
Return type:

str

birdnet_benchmark.argparse_helper.parse_non_negative_float(value)
Return type:

float

birdnet_benchmark.argparse_helper.parse_non_negative_integer(value)
Return type:

int

birdnet_benchmark.argparse_helper.parse_optional_value(value, method)
Return type:

Optional[TypeVar(T)]

birdnet_benchmark.argparse_helper.parse_path(value)
Return type:

Path

birdnet_benchmark.argparse_helper.parse_percent(value)
Return type:

float

birdnet_benchmark.argparse_helper.parse_positive_float(value)
Return type:

float

birdnet_benchmark.argparse_helper.parse_positive_integer(value)
Return type:

int

birdnet_benchmark.argparse_helper.parse_required(value)
Return type:

str

birdnet.core.backends module

class birdnet.core.backends.Backend(model_path, device_name, half_precision)

Bases: Generic[BatchT], ABC

abstractmethod copy_from_device(inference_result)
Return type:

ndarray

abstractmethod copy_to_device(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

abstractmethod encode(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

abstractmethod half_precision(inference_result)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

abstractmethod load()
Return type:

None

abstract property n_species: int
abstractmethod classmethod name()
Return type:

str

abstractmethod classmethod precision()
Return type:

Literal['int8', 'fp16', 'fp32']

abstractmethod predict(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

abstractmethod classmethod supports_cow()
Return type:

bool

abstractmethod classmethod supports_encoding()
Return type:

bool

abstractmethod unload()
Return type:

None

class birdnet.core.backends.BackendLoader(model_path, backend_type, backend_kwargs)

Bases: object

property backend: VersionedBackendProtocol
classmethod check_custom_tflite_model(model_path, library, prediction_to_type)

Detect the custom TFLite classifier type and number of output species in a subprocess to avoid loading TensorFlow in the main process.

Returns (n_species, classifier_type) if successful.

Return type:

tuple[int, str]

classmethod check_model_can_be_loaded(model_path, backend_type, kwargs)

Check if the model can be loaded in a subprocess to avoid loading tensorflow in the main process.

Returns the number of species in the model if successful.

Return type:

int

load_backend(device_name, half_precision)
Return type:

VersionedBackendProtocol

load_backend_in_main_process_if_possible(devices, half_precision, start_method)
Return type:

None

unload_backend()
Return type:

None

class birdnet.core.backends.OnnxBackend(model_path, device_name, half_precision, **kwargs)

Bases: Backend, ABC

copy_from_device(inference_result)
Return type:

ndarray

copy_to_device(batch)
Return type:

ndarray

final encode(batch)
Return type:

ndarray

abstractmethod classmethod encoding_out_idx()
Return type:

int | None

half_precision(inference_result)
Return type:

ndarray

load()
Return type:

None

property n_species: int
classmethod name()
Return type:

str

final predict(batch)
Return type:

ndarray

abstractmethod classmethod prediction_out_idx()
Return type:

int

abstractmethod classmethod probe_input_size_samples()
Return type:

int

final classmethod supports_cow()
Return type:

bool

unload()
Return type:

None

class birdnet.core.backends.PBBackend(model_path, device_name, half_precision, **kwargs)

Bases: Backend, ABC

copy_from_device(inference_result)
Return type:

np.ndarray

copy_to_device(batch)
Return type:

Tensor

final encode(batch)
Return type:

Tensor

abstractmethod classmethod encoding_key()
Return type:

str | None

abstractmethod classmethod encoding_signature_name()
Return type:

str | None

half_precision(inference_result)
Return type:

Tensor

abstractmethod classmethod input_key()
Return type:

str

final load()
Return type:

None

property n_species: int
classmethod name()
Return type:

str

final predict(batch)
Return type:

Tensor

abstractmethod classmethod prediction_key()
Return type:

str

abstractmethod classmethod prediction_signature_name()
Return type:

str

final classmethod supports_cow()
Return type:

bool

unload()
Return type:

None

class birdnet.core.backends.TFBackend(model_path, device_name, half_precision, **kwargs)

Bases: Backend, ABC

copy_from_device(inference_result)
Return type:

ndarray

copy_to_device(batch)
Return type:

ndarray

final encode(batch)
Return type:

ndarray

abstractmethod classmethod encoding_out_idx()
Return type:

int | None

half_precision(inference_result)
Return type:

ndarray

abstractmethod classmethod in_idx()
Return type:

int

load()
Return type:

None

property n_species: int
classmethod name()
Return type:

str

final predict(batch)
Return type:

ndarray

abstractmethod classmethod prediction_out_idx()
Return type:

int

final classmethod supports_cow()
Return type:

bool

unload()
Return type:

None

class birdnet.core.backends.TorchBackend(model_path, device_name, half_precision, **kwargs)

Bases: Backend, ABC

copy_from_device(inference_result)
Return type:

np.ndarray

copy_to_device(batch)
Return type:

TorchTensor

final encode(batch)
Return type:

TorchTensor

abstractmethod classmethod encoding_out_idx()
Return type:

int | None

half_precision(inference_result)
Return type:

TorchTensor

load()
Return type:

None

property n_species: int
classmethod name()
Return type:

str

final predict(batch)
Return type:

TorchTensor

classmethod prediction_needs_sigmoid()

Whether the model’s prediction head returns logits instead of probabilities.

The exported TorchScript modules are not consistent about this: the acoustic model applies the activation itself, the geo model does not. Backends whose model returns logits declare it here so that all backends of a model yield the same probabilities.

Return type:

bool

abstractmethod classmethod prediction_out_idx()
Return type:

int

abstractmethod classmethod probe_input_size_samples()
Return type:

int

final classmethod supports_cow()
Return type:

bool

unload()
Return type:

None

class birdnet.core.backends.VersionedAcousticBackendProtocol(model_path, device_name, **kwargs)

Bases: VersionedBackendProtocol, Protocol

class birdnet.core.backends.VersionedBackendProtocol(model_path, device_name, **kwargs)

Bases: Generic[BatchT], Protocol

copy_from_device(inference_result)
Return type:

ndarray

copy_to_device(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

encode(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

half_precision(inference_result)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

load()
Return type:

None

property n_species: int
classmethod name()
Return type:

str

classmethod precision()
Return type:

Literal['int8', 'fp16', 'fp32']

predict(batch)
Return type:

TypeVar(BatchT, ndarray, Tensor, TorchTensor)

classmethod supports_cow()
Return type:

bool

classmethod supports_encoding()
Return type:

bool

unload()
Return type:

None

class birdnet.core.backends.VersionedGeoBackendProtocol(model_path, device_name, **kwargs)

Bases: VersionedBackendProtocol, Protocol

classmethod year_round_week_inputs()
Return type:

tuple[float, ...]

birdnet.core.backends.disable_tf_logging()
Return type:

None

birdnet.core.backends.import_tf()
Return type:

None

birdnet.core.backends.litert_installed()
Return type:

bool

birdnet.core.backends.load_lib_litert_model(model_path, allocate_tensors=False)
Return type:

Interpreter

birdnet.core.backends.load_lib_tf_model(model_path, allocate_tensors=False)
Return type:

TFInterpreter

birdnet.core.backends.load_onnx_model(model_path, device)
Return type:

InferenceSession

birdnet.core.backends.load_pb_model(model_path, logical_device_name)
Return type:

Any

birdnet.core.backends.load_tf_model(model_path, library, allocate_tensors=False)
birdnet.core.backends.load_torch_model(model_path, device)
Return type:

RecursiveScriptModule

birdnet.core.backends.onnxruntime_installed()
Return type:

bool

birdnet.core.backends.set_cpu_device_tf()
Return type:

str

birdnet.core.backends.set_gpu_device_tf(device, memory_growth)
Return type:

str

birdnet.core.backends.set_torch_device(device)
Return type:

TorchDevice

birdnet.core.backends.tf_installed()
Return type:

bool

birdnet.core.backends.torch_installed()
Return type:

bool

birdnet.core.base module

class birdnet.core.base.ModelBase(model_path, species_list, is_custom_model)

Bases: ABC

property is_custom_model: bool
abstractmethod classmethod load(*args, **kwargs)
Return type:

Self

abstractmethod classmethod load_custom(*args, **kwargs)
Return type:

Self

property model_path: Path
property n_species: int
abstractmethod predict(*args, **kwargs)
Return type:

ResultBase

abstractmethod predict_session(*args, **kwargs)
Return type:

SessionBase

property species_list: OrderedSet[str]
class birdnet.core.base.ResultBase(model_path, model_version, model_precision)

Bases: ABC

classmethod load(path)
Return type:

Self

property memory_size_MiB: float
property model_path: Path
property model_precision: str
property model_version: str
save(npz_out_path, /, *, compress=True)
Return type:

None

class birdnet.core.base.SessionBase

Bases: ABC

abstractmethod run(*args, **kwargs)
Return type:

ResultBase

birdnet.core.base.get_session_id()

Get a unique session ID based on the current process and thread.

Return type:

str

Example for two processes (fork):

Process 1: 53554_127397175535424_1762165676846175803 Process 2: 53555_127397175535424_1762165676846559511

Example for two processes (spawn):

Process 1: 54155_126834937165632_1762165717644505438 Process 2: 54154_132842492557120_1762165717644777865

Example for two threads in the same process:

Thread 1: 53142_138235445503680_1762165643891762916 Thread 2: 53142_138235453896384_1762165653498085145

Example for same thread and process but different calls:

Call 1: 50179_128078941120320_1762165462208616340 Call 2: 50179_128078941120320_1762165485281125126

birdnet.core.base.get_session_id_hash(session_id)
Return type:

str

birdnet_benchmark.cli module

class birdnet_benchmark.cli.BenchmarkResultContainer(ns, model, output=None, stats=None)

Bases: object

model: AcousticModelBase
ns: Namespace
output: AcousticPredictionResultBase | None = None
stats: AcousticProgressStats | None = None
birdnet_benchmark.cli.run_benchmark()
Return type:

None

birdnet_benchmark.cli.run_benchmark_from_args(args)
Return type:

None

birdnet_benchmark.cli.run_benchmark_from_ns(ns)
Return type:

None

birdnet_benchmark.cli.save_statistics(result_container)
Return type:

None

birdnet_benchmark.cli.show_progress_stats(info, result_container)
Return type:

None

birdnet.globals module

birdnet.utils.download_progress module

Process-wide progress callback for model, label and taxonomy downloads.

birdnet.set_download_progress_callback(cb) (or the scoped download_progress_callback(cb)) replaces the default stderr tqdm bar with DownloadProgress snapshots, per downloaded file:

  • "started" once per attempt, before any I/O – a repeat with a higher attempt and bytes_done == 0 announces a retry;

  • "progress" at most every 0.1 s (first chunk of an attempt always);

  • "retrying" before each back-off, with error and retry_in_s;

  • exactly one of "finished" / "failed" (the error is raised right after).

A callback that raises aborts the download (partial file discarded, no retry, no further events) and its exception propagates out of load(..) – the way to cancel from a UI. Calls are synchronous on the load(..) thread; the callback is captured when a download starts. One load(..) may run several downloads (labels, taxonomy, model): key on description/url.

class birdnet.utils.download_progress.DownloadProgress(description, url, bytes_done, bytes_total, attempt, max_attempts, status, error=None, retry_in_s=None)

Bases: object

One update from a model/label/taxonomy download (see the module docstring).

attempt: int
bytes_done: int
bytes_total: int | None
description: str
error: str | None = None
property fraction: float | None

Progress in [0, 1], or None while the total size is unknown.

property is_terminal: bool
max_attempts: int
retry_in_s: float | None = None
status: Literal['started', 'progress', 'retrying', 'finished', 'failed']
url: str
class birdnet.utils.download_progress.DownloadReporter(url, description, max_attempts, callback)

Bases: object

Emits the events of one download (all attempts) to one captured callback.

Internal helper for download_file_tqdm; not part of the public API. With callback=None every method is a no-op, so the default path costs one attribute check per chunk.

property enabled: bool
failed(error)
Return type:

None

finished()
Return type:

None

progress(bytes_done)
Return type:

None

retrying(error, wait_s)
Return type:

None

started(attempt, bytes_total)
Return type:

None

total_known(bytes_total)
Return type:

None

birdnet.utils.download_progress.download_progress_callback(callback)

Scoped alternative to set_download_progress_callback().

Registers callback for the duration of the with block and restores whatever was registered before on exit (including None).

Return type:

Generator[None, None, None]

birdnet.utils.download_progress.get_download_progress_callback()
Return type:

Callable[[DownloadProgress], None] | None

birdnet.utils.download_progress.set_download_progress_callback(callback)

Register a process-wide callback for download progress; returns the previous one.

Pass None to unregister. With no callback registered (the default), downloads behave exactly as before: a tqdm bar on stderr. While a callback is registered the tqdm bar is disabled. An exception raised by the callback aborts the running download without a retry and propagates out of load(..) (see the module docstring).

Return type:

Callable[[DownloadProgress], None] | None

birdnet.utils.helper module

exception birdnet.utils.helper.DownloadError(message, *, status_code=None)

Bases: ValueError

A download did not complete successfully.

Subclasses ValueError because that is what this helper has always raised for a failed download; status_code is exposed so callers (and the retry loop below) can tell a permanent client error from a retriable one.

class birdnet.utils.helper.ModelInfo(dl_url, dl_size, file_size, dl_file_name)

Bases: object

dl_file_name: str
dl_size: int
dl_url: str
file_size: int
birdnet.utils.helper.apply_speed_to_duration(duration_s, speed)
Return type:

float

birdnet.utils.helper.apply_speed_to_samples(samples, speed)
Return type:

int

birdnet.utils.helper.assert_queue_is_empty(queue)
Return type:

None

birdnet.utils.helper.bandpass_signal(audio_signal, rate, fmin, fmax, new_fmin, new_fmax)
Return type:

GenericAlias[float32]

birdnet.utils.helper.check_is_intel_macos()
Return type:

bool

birdnet.utils.helper.check_is_python_312()
Return type:

bool

birdnet.utils.helper.check_protobuf_model_files_exist(folder)
Return type:

bool

birdnet.utils.helper.check_source_marker(model_dir, dl_url)
Return type:

bool

birdnet.utils.helper.download_file_tqdm(url, file_path, *, download_size=None, description=None)
Return type:

int

birdnet.utils.helper.duration_as_samples(duration_s, sample_rate)
Return type:

int

birdnet.utils.helper.fillup_with_silence(audio_segment, target_length)
Return type:

GenericAlias[float32]

birdnet.utils.helper.flat_sigmoid_logaddexp_fast(x, sensitivity, clip_val=15.0, bias=1.0)
Return type:

TypeAliasType

birdnet.utils.helper.flat_softmax_fast(x)
Return type:

TypeAliasType

birdnet.utils.helper.format_input_for_csv(input_value)
Return type:

str

birdnet.utils.helper.get_file_formats(file_paths)
Return type:

str

birdnet.utils.helper.get_float_dtype(max_value)

Magnitude-based: returns the smallest float dtype whose range covers max_value. Use for bulk arrays where memory matters and per-element rounding is acceptable (e.g. lists of file durations).

Return type:

TypeAliasType

birdnet.utils.helper.get_hash(session_id)
Return type:

str

birdnet.utils.helper.get_hop_duration_s(segment_size_s, overlap_duration_s, speed)
Return type:

float

birdnet.utils.helper.get_lossless_float_dtype(value)
Return type:

dtype

birdnet.utils.helper.get_n_segments_speed(duration_s, segment_size_s, overlap_duration_s, speed)
Return type:

int

birdnet.utils.helper.get_species_from_file(species_file, /, *, encoding='utf8')
Return type:

OrderedSet[str]

birdnet.utils.helper.get_supported_audio_files_recursive(folder)
Return type:

Generator[Path, None, None]

birdnet.utils.helper.get_uint_dtype(max_value)

Return the narrowest unsigned-integer NumPy dtype that can represent max_value (inclusive).

Return type:

dtype

Examples

>>> get_uint_dtype(100)
dtype('uint8')
>>> get_uint_dtype(42_000)
dtype('uint16')
>>> get_uint_dtype(3_000_000_000)
dtype('uint64')

Notes

2**8 = 256 2**16 = 65,536 2**32 = 4,294,967,296 2**64 = 18,446,744,073,709,551,616

birdnet.utils.helper.hms_centis_fast(v)
Return type:

str

birdnet.utils.helper.is_supported_audio_file(file_path)
Return type:

bool

birdnet.utils.helper.itertools_batched(iterable, n)
Return type:

Generator[Any, None, None]

birdnet.utils.helper.max_value_for_uint_dtype(dtype)

Returns the maximum value that can be represented by the given NumPy dtype.

Return type:

int

birdnet.utils.helper.uint_ctype_from_dtype(dtype)
Return type:

c_ubyte | c_ushort | c_uint | c_ulong

birdnet.utils.helper.uint_dtype_for_files(n_files)
Return type:

dtype

birdnet.utils.helper.upgrade_float_dtype_for_value(dtype, value)
Return type:

dtype

birdnet.utils.helper.validate_species_list(species_list)
Return type:

OrderedSet[str]

birdnet.utils.helper.write_source_marker(model_dir, dl_url)
Return type:

None

birdnet.utils.helper.xget_max_n_segments(max_duration_s, segment_size_s, overlap_duration_s)
Return type:

int

birdnet.utils.local_data module

birdnet.utils.local_data.get_app_data_path()
Return type:

Path

birdnet.utils.local_data.get_benchmark_dir(model, dir_name)
Return type:

Path

birdnet.utils.local_data.get_birdnet_app_data_folder()
Return type:

Path

birdnet.utils.local_data.get_lang_dir(model, version, backend)
Return type:

Path

birdnet.utils.local_data.get_model_path(model, version, backend, precision)
Return type:

Path

birdnet.utils.local_data.get_model_root_dir(model, version, backend)
Return type:

Path

birdnet.utils.local_data.get_package_version()
Return type:

str

birdnet.utils.logging_utils module

birdnet.utils.logging_utils.get_logger_for_package(name)
Return type:

Logger

birdnet.utils.logging_utils.get_package_logger()
Return type:

Logger

birdnet.utils.logging_utils.get_package_logging_level()
Return type:

int

birdnet.utils.logging_utils.init_package_logger(logging_level)
Return type:

None

birdnet.utils.logging_utils.native_output_is_verbose()
Return type:

bool

birdnet.utils.logging_utils.suppress_native_stderr()

Hide what native code writes to stderr while the block runs.

TensorFlow prints its absl banner and the oneDNN notice from C++ straight to file descriptor 2, before absl logging is initialized. logging, absl’s verbosity and TF_CPP_MIN_LOG_LEVEL all act above that and cannot reach it; only redirecting the descriptor can. Every worker process imports TensorFlow, so the banner is printed once per process.

If the block raises, the captured text is written to stderr, so the native diagnostics of a failed import still reach the user. Otherwise it is emitted on the package logger at DEBUG. No handler is attached by default, and worker processes have none at all, so in practice a warning that never raises is seen by re-running with BIRDNET_TF_VERBOSE=1.

Suppression is a convenience, never a precondition: if stderr cannot be redirected the block still runs, unsuppressed. Because the descriptor is process-wide the block is serialized, which also means concurrent callers wait out an import that is already running.

Return type:

Generator[None, None, None]

birdnet.model_loader module

Module for loading models. Provides functions to load official and custom models.

birdnet.model_loader.load(model_type, version, backend, /, *, precision='fp32', lang='en_us', **model_kwargs)
Return type:

ModelBase

birdnet.model_loader.load_custom(model_type, version, backend, model, species_list, /, *, precision='fp32', check_validity=True, **model_kwargs)
Return type:

ModelBase

birdnet.model_loader.load_perch_v2(device='CPU')
Return type:

AcousticModelPerchV2

birdnet.acoustic.inference.core.shm module

class birdnet.acoustic.inference.core.shm.RingField(name, dtype, shape)

Bases: object

attach_and_get_array()
Return type:

tuple[SharedMemory, ndarray]

attach_shared_memory()

Attaches to an existing shared memory segment with the specified name.

Return type:

SharedMemory

cleanup(session_id)
Return type:

None

dtype: dtype
get_array(shm)
Return type:

ndarray

name: str
property nbytes: int
shape: tuple[int, ...]
birdnet.acoustic.inference.core.shm.create_shm_ring(session_id, ring)
Return type:

SharedMemory

birdnet.utils module

Module contents

class birdnet.AcousticDataEncodingResult(tensor, input_durations, segment_duration_s, overlap_duration_s, speed, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version)

Bases: AcousticEncodingResultBase

class birdnet.AcousticDataPredictionResult(tensor, species_list, input_durations, segment_duration_s, overlap_duration_s, speed, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version)

Bases: AcousticPredictionResultBase

class birdnet.AcousticEncodingResultBase(inputs, input_durations, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version, segment_duration_s, overlap_duration_s, speed, tensor)

Bases: AcousticResultBase

property emb_dim: int

Return the embedding dimensionality.

Returns:

Number of coefficients per embedding vector.

Return type:

int

property embeddings: ndarray

Return the raw embedding tensor produced by the encoder.

Returns:

Embeddings with shape (n_inputs, n_segments, emb_dim).

Return type:

np.ndarray

property embeddings_masked: ndarray

Return the mask that marks relevant segments across files.

Returns:

Boolean mask of the same shape as embeddings.

Return type:

np.ndarray

property max_n_segments: int

Return the maximum segment count reserved per input.

Returns:

Number of overlapping windows available per file.

Return type:

int

property memory_size_MiB: float

Return the total result memory usage including embeddings buffers.

Returns:

Memory size in mebibytes.

Return type:

float

to_arrow_table()

Produce a PyArrow table that serializes each embedding with timing metadata.

Return type:

Table

Returns:

Table containing dictionary-encoded inputs and embeddings lists.

Return type:

pa.Table

to_csv(path, *, encoding='utf-8', buffer_size_kb=1024, silent=False)

Dump the structured embeddings to a CSV file for downstream analysis.

Return type:

None

Parameters:
  • path – File path where the CSV will be written (must end with .csv).

  • encoding – Text encoding for the output file.

  • buffer_size_kb – Buffer size used when writing the file.

  • silent – Suppress progress messages when True.

to_structured_array()

Convert the embeddings and timing metadata into a structured array.

Return type:

ndarray

Returns:

Array with fields for input path, start/end times, and embedding.

Return type:

np.ndarray

unprocessable_inputs()

Return the indices of inputs that could not be processed.

Return type:

ndarray

Returns:

Boolean mask or indices for skipped inputs.

Return type:

np.ndarray

class birdnet.AcousticEncodingSession(species_list, model_path, model_segment_size_s, model_sample_rate, model_is_custom, model_sig_fmin, model_sig_fmax, model_version, model_backend_type, model_backend_custom_kwargs, model_emb_dim, *, n_producers, n_workers, batch_size, prefetch_ratio, overlap_duration_s, speed, bandpass_fmin, bandpass_fmax, half_precision, max_audio_duration_min, show_stats, progress_callback, device, max_n_files, on_file_complete=None)

Bases: AcousticSessionBase

run(inputs)
Return type:

AcousticFileEncodingResult

run_arrays(inputs)
Return type:

AcousticDataEncodingResult

class birdnet.AcousticFileEncodingResult(tensor, files, file_durations, segment_duration_s, overlap_duration_s, speed, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version)

Bases: AcousticEncodingResultBase

class birdnet.AcousticFilePredictionResult(tensor, files, species_list, file_durations, segment_duration_s, overlap_duration_s, speed, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version, species_list_array=None)

Bases: AcousticPredictionResultBase

get_unprocessed_files()
Return type:

set[Path]

class birdnet.AcousticModelPerchV2(model_path, species_list, is_custom_model, backend_type, backend_kwargs)

Bases: AcousticModelBase

encode(inp, /, *, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', on_file_complete=None)

Run encoding with the Perch V2 model on files or paths to obtain embeddings.

Return type:

AcousticEncodingResultBase

Parameters:
  • inp – Path(s) or string(s) pointing to audio files to encode.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • on_file_complete – Optional callback fired once per input file as soon as that file is fully processed, receiving a single-file AcousticFileEncodingResult (invalid files are reported with their input marked unprocessable). Enables streaming per-file persistence. Invoked from a background thread with a copy of the caller’s context; file inputs only (not encode_arrays). A callback that raises cancels the run.

Returns:

Object containing embeddings for each file.

Return type:

AcousticEncodingResultBase

encode_arrays(inp, /, *, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU')

Run encoding with the Perch V2 model directly on in-memory audio arrays.

Return type:

AcousticEncodingResultBase

Parameters:
  • inp – Tuple(s) of (audio ndarray, sampling rate).

  • n_producers – Threads generating batches from the arrays.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

Returns:

Object containing embeddings for each input array.

Return type:

AcousticEncodingResultBase

encode_session(*, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', max_n_files=65536, on_file_complete=None)

Create an encoding session with explicit resource configuration.

Return type:

AcousticEncodingSession

Parameters:
  • species_list – Ordered species collection used during the session.

  • model_path – Path to the acoustic model binary.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • max_n_files – Upper bound on files to limit resource consumption.

Returns:

Session capable of running encodings.

Return type:

AcousticEncodingSession

classmethod get_embeddings_dim()
Return type:

int

classmethod get_sample_rate()
Return type:

int

classmethod get_segment_size_s()
Return type:

float

classmethod get_segment_size_samples()
Return type:

int

classmethod get_sig_fmax()
Return type:

int

classmethod get_sig_fmin()
Return type:

int

classmethod get_version()

Return the string label that identifies the acoustic model version.

Return type:

Literal['2.4', '3.0']

Returns:

Registered enum constant for the supported version.

Return type:

ACOUSTIC_MODEL_VERSIONS

classmethod load(model_path, species_list, backend_type, backend_kwargs)
Return type:

AcousticModelPerchV2

classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)
Return type:

AcousticModelPerchV2

predict(inp, /, *, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, bandpass_fmin=0, bandpass_fmax=15000, speed=1.0, apply_sigmoid=False, apply_softmax=False, sigmoid_sensitivity=None, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, device='CPU', show_stats=None, progress_callback=None, on_file_complete=None)

Run prediction with the Perch V2 model on files or paths with configurable inference options.

Return type:

AcousticPredictionResultBase

Parameters:
  • inp – Path(s) or string(s) pointing to audio files to analyze.

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • device – Target device(s) for running the backend.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

Returns:

Object containing detected species and confidence

scores.

Return type:

AcousticPredictionResultBase

predict_arrays(inp, /, *, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, bandpass_fmin=0, bandpass_fmax=15000, speed=1.0, apply_sigmoid=False, apply_softmax=False, sigmoid_sensitivity=None, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, device='CPU', show_stats=None, progress_callback=None)

Run prediction with the Perch V2 model directly on in-memory audio arrays.

Return type:

AcousticPredictionResultBase

Parameters:
  • inp – Tuple(s) of (audio ndarray, sampling rate).

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads generating batches from the arrays.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • device – Target device(s) for running the backend.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

Returns:

Object containing detected species and confidence

scores.

Return type:

AcousticPredictionResultBase

predict_session(*, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, apply_sigmoid=False, apply_softmax=False, sigmoid_sensitivity=None, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', max_n_files=65536, on_file_complete=None)

Create a prediction session allowing manual control over the inference lifecycle.

Return type:

AcousticPredictionSession

Parameters:
  • species_list – Ordered species collection used during the session.

  • model_path – Path to the acoustic model binary.

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • max_n_files – Upper bound on files to limit resource consumption.

Returns:

Session capable of running predictions.

Return type:

AcousticPredictionSession

class birdnet.AcousticModelV2_4(model_path, species_list, is_custom_model, backend_type, backend_kwargs)

Bases: AcousticModelBase

encode(inp, /, *, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', on_file_complete=None)

Run encoding with the BirdNET 2.4 model on files or paths to obtain embeddings.

Return type:

AcousticEncodingResultBase

Parameters:
  • inp – Path(s) or string(s) pointing to audio files to encode.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • on_file_complete – Optional callback fired once per input file as soon as that file is fully processed, receiving a single-file AcousticFileEncodingResult (invalid files are reported with their input marked unprocessable). Enables streaming per-file persistence. Invoked from a background thread with a copy of the caller’s context. A callback that raises cancels the run.

Returns:

Object containing embeddings for each file.

Return type:

AcousticEncodingResultBase

encode_arrays(inp, /, *, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU')

Run encoding with the BirdNET 2.4 model directly on in-memory audio arrays.

Return type:

AcousticEncodingResultBase

Parameters:
  • inp – Tuple(s) of (audio ndarray, sampling rate).

  • n_producers – Threads generating batches from the arrays.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

Returns:

Object containing embeddings for each input array.

Return type:

AcousticEncodingResultBase

encode_session(*, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', max_n_files=65536, on_file_complete=None)

Create an encoding session with explicit resource configuration.

Return type:

AcousticEncodingSession

Parameters:
  • species_list – Ordered species collection used during the session.

  • model_path – Path to the acoustic model binary.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • max_n_files – Upper bound on files to limit resource consumption.

  • on_file_complete – Optional callback fired once per input file as soon as that file is fully processed, receiving a single-file AcousticFileEncodingResult (invalid files are reported with their input marked unprocessable). Enables streaming per-file persistence. Invoked from a background thread with a copy of the caller’s context; file inputs only (not run_arrays). A callback that raises cancels the run.

Returns:

Session capable of running encodings.

Return type:

AcousticEncodingSession

classmethod get_embeddings_dim()
Return type:

int

classmethod get_sample_rate()
Return type:

int

classmethod get_segment_size_s()
Return type:

float

classmethod get_segment_size_samples()
Return type:

int

classmethod get_sig_fmax()
Return type:

int

classmethod get_sig_fmin()
Return type:

int

classmethod get_version()

Return the string label that identifies the acoustic model version.

Return type:

Literal['2.4', '3.0']

Returns:

Registered enum constant for the supported version.

Return type:

ACOUSTIC_MODEL_VERSIONS

classmethod load(model_path, species_list, backend_type, backend_kwargs)
Return type:

AcousticModelV2_4

classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)
Return type:

AcousticModelV2_4

predict(inp, /, *, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, bandpass_fmin=0, bandpass_fmax=15000, speed=1.0, apply_sigmoid=True, sigmoid_sensitivity=1.0, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, device='CPU', show_stats=None, progress_callback=None, on_file_complete=None, apply_softmax=False)

Run prediction with the BirdNET 2.4 model on files or paths with configurable inference options.

This method creates one prediction session for the call. The session shuts down its producer and worker processes before this method returns, including when inference raises an exception.

Return type:

AcousticPredictionResultBase

Parameters:
  • inp – Path(s) or string(s) pointing to audio files to analyze.

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Number of inference worker processes. None uses the number of physical CPU cores. Pass a fixed integer to meet a process limit. Each worker holds its own copy of the model, so a high count raises peak memory use. On Linux and macOS, a worker killed by the operating system to reclaim memory while processing a batch deadlocks the run: the killed process never releases the lock it was holding, so the remaining workers wait on it forever and the call never returns (see issue #73). Lowering n_workers or batch_size reduces peak memory and with it how likely such a kill is, but cannot rule it out.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • device – Target device(s) for running the backend.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • on_file_complete – Optional callback fired once per input file as soon as that file is fully processed, receiving a single-file AcousticFilePredictionResult (invalid files are reported with their input marked unprocessable). Enables streaming per-file persistence (e.g. resumable analysis). Invoked from a background thread with a copy of the caller’s context. A callback that raises cancels the run.

Returns:

Object containing detected species and confidence

scores.

Return type:

AcousticPredictionResultBase

predict_arrays(inp, /, *, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, bandpass_fmin=0, bandpass_fmax=15000, speed=1.0, apply_sigmoid=True, sigmoid_sensitivity=1.0, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, device='CPU', show_stats=None, progress_callback=None, apply_softmax=False)

Run prediction with the BirdNET 2.4 model directly on in-memory audio arrays.

Return type:

AcousticPredictionResultBase

Parameters:
  • inp – Tuple(s) of (audio ndarray, sampling rate).

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads generating batches from the arrays.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • device – Target device(s) for running the backend.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

Returns:

Object containing detected species and confidence

scores.

Return type:

AcousticPredictionResultBase

predict_session(*, top_k=5, n_producers=1, n_workers=None, batch_size=1, prefetch_ratio=1, overlap_duration_s=0, speed=1.0, bandpass_fmin=0, bandpass_fmax=15000, apply_sigmoid=True, sigmoid_sensitivity=1.0, default_confidence_threshold=0.1, custom_confidence_thresholds=None, custom_species_list=None, half_precision=False, max_audio_duration_min=None, show_stats=None, progress_callback=None, device='CPU', max_n_files=65536, on_file_complete=None, apply_softmax=False)

Create a prediction session allowing manual control over the inference lifecycle.

Return type:

AcousticPredictionSession

Parameters:
  • species_list – Ordered species collection used during the session.

  • model_path – Path to the acoustic model binary.

  • top_k – Number of highest-confidence results to return per segment.

  • n_producers – Threads tasked with producing audio batches.

  • n_workers – Optional worker count for backend processing.

  • batch_size – Number of records evaluated per inference call.

  • prefetch_ratio – How many batches to decode ahead of processing.

  • overlap_duration_s – Seconds of overlap between sliding windows.

  • bandpass_fmin – Lower bound for the bandpass filter in Hz.

  • bandpass_fmax – Upper bound for the bandpass filter in Hz.

  • speed – Resampling multiplier to accommodate different recording speeds.

  • apply_sigmoid – Whether to transform logits with a sigmoid. When False, output scores are raw logits and thresholds are interpreted in logit space rather than as probabilities.

  • apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.

  • sigmoid_sensitivity – Optional scale for the sigmoid function.

  • default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a probability (typical range 0 to 1); when apply_sigmoid=False it is a logit value.

  • custom_confidence_thresholds – Species-specific override thresholds.

  • custom_species_list – Path or iterable defining a subset of species.

  • half_precision – Use float16 where supported for inference.

  • max_audio_duration_min – Maximum total duration per call.

  • show_stats – Level of statistics logging to emit.

  • progress_callback – Optional callback to report progress. Invoked from a background worker thread, inheriting a copy of the caller’s context (contextvars) as captured when the call starts.

  • device – Target device(s) for running the backend.

  • max_n_files – Upper bound on files to limit resource consumption.

  • on_file_complete – Optional callback fired once per input file as soon as that file is fully processed, receiving a single-file AcousticFilePredictionResult (invalid files are reported with their input marked unprocessable). Enables streaming per-file persistence (e.g. resumable analysis). Invoked from a background thread with a copy of the caller’s context; file inputs only (not run_arrays). A callback that raises cancels the run.

Returns:

Session capable of running predictions.

Return type:

AcousticPredictionSession

class birdnet.AcousticPredictionResultBase(inputs, input_durations, model_path, model_fmin, model_fmax, model_sr, model_precision, model_version, species_list, segment_duration_s, overlap_duration_s, speed, tensor, species_list_array=None)

Bases: AcousticResultBase

property max_n_segments: int
property memory_size_MiB: float

Memory usage for the base result metadata.

Returns:

Memory used by metadata buffers in mebibytes.

Return type:

float

property n_species: int
property species_ids: ndarray
property species_list: ndarray
property species_masked: ndarray
property species_probs: ndarray
to_arrow_table()
Return type:

Table

to_csv(path, *, encoding='utf-8', buffer_size_kb=1024, silent=False)
Return type:

None

to_structured_array()
Return type:

ndarray

property top_k: int
property unprocessable_inputs: ndarray
class birdnet.AcousticPredictionSession(species_list, model_path, model_segment_size_s, model_sample_rate, model_is_custom, model_sig_fmin, model_sig_fmax, model_version, model_backend_type, model_backend_custom_kwargs, *, top_k, n_producers, n_workers, batch_size=1, prefetch_ratio=1, overlap_duration_s, speed, bandpass_fmin, bandpass_fmax, apply_sigmoid, apply_softmax, sigmoid_sensitivity, default_confidence_threshold, custom_confidence_thresholds, custom_species_list, half_precision=True, max_audio_duration_min, show_stats, progress_callback, device, max_n_files, on_file_complete=None)

Bases: AcousticSessionBase

run(inputs)
Return type:

AcousticFilePredictionResult

run_arrays(inputs)
Return type:

AcousticDataPredictionResult

class birdnet.AcousticProgressStats(finished, buffer_stats, producer_stats, worker_stats, wall_time_s, memory_usage_MiB, memory_usage_max_MiB, cpu_usage_pct, cpu_usage_max_pct, progress_pct, est_remaining_time_s, processed_segments, processed_batches, total_segments, speed_xrt, speed_seg_per_s)

Bases: object

buffer_stats: BufferStats
cpu_usage_max_pct: float
cpu_usage_pct: float
property est_remaining_time_hhmmss: str | None
est_remaining_time_s: float | None
finished: bool
memory_usage_MiB: float
memory_usage_max_MiB: float
processed_batches: int
processed_segments: int
producer_stats: ProducerStats
progress_pct: float
speed_seg_per_s: float | None
speed_xrt: float | None
total_segments: int | None
wall_time_s: float
worker_stats: WorkerStats | None
class birdnet.DownloadProgress(description, url, bytes_done, bytes_total, attempt, max_attempts, status, error=None, retry_in_s=None)

Bases: object

One update from a model/label/taxonomy download (see the module docstring).

attempt: int
bytes_done: int
bytes_total: int | None
description: str
error: str | None = None
property fraction: float | None

Progress in [0, 1], or None while the total size is unknown.

property is_terminal: bool
max_attempts: int
retry_in_s: float | None = None
status: Literal['started', 'progress', 'retrying', 'finished', 'failed']
url: str
class birdnet.GeoModelV2_4(model_path, species_list, is_custom_model, backend_type, backend_kwargs)

Bases: GeoModelBase

classmethod get_model_type()
Return type:

Literal['acoustic', 'geo']

classmethod get_version()
Return type:

Literal['2.4', '3.0']

classmethod load(model_path, species_list, backend_type, backend_kwargs)
Return type:

GeoModelV2_4

classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)
Return type:

GeoModelV2_4

predict(latitude, longitude, /, *, week=None, year_round_aggregation='max', min_confidence=0.03, half_precision=False, device='CPU')
Return type:

GeoPredictionResult

predict_session(*, min_confidence=0.03, half_precision=False, device='CPU')
Return type:

GeoPredictionSession

class birdnet.GeoPredictionResult(model_path, model_version, model_precision, latitude, longitude, week, species_masked, species_ids, species_probs, species_list)

Bases: ResultBase

property latitude: int
property longitude: int
property memory_size_MiB: float
property n_species: int
property species_ids: ndarray
property species_list: ndarray
property species_masked: ndarray
property species_probs: ndarray
to_arrow_table(sort_by='species')
Return type:

Table

to_csv(csv_out_path, sort_by='species', encoding='utf8')
Return type:

None

to_dataframe(sort_by='species')
Return type:

DataFrame

to_set()
Return type:

set[str]

to_structured_array(sort_by='species')
Return type:

ndarray

to_txt(txt_out_path, sort_by='species', encoding='utf8')
Return type:

None

property week: int
class birdnet.GeoPredictionSession(species_list, model_path, model_is_custom, model_version, model_backend_type, model_backend_custom_kwargs, *, min_confidence, half_precision, device)

Bases: GeoSessionBase

run(latitude, longitude, /, *, week=None, year_round_aggregation='max')
Return type:

GeoPredictionResult

birdnet.download_progress_callback(callback)

Scoped alternative to set_download_progress_callback().

Registers callback for the duration of the with block and restores whatever was registered before on exit (including None).

Return type:

Generator[None, None, None]

birdnet.get_download_progress_callback()
Return type:

Callable[[DownloadProgress], None] | None

birdnet.get_package_logger()
Return type:

Logger

birdnet.load(model_type, version, backend, /, *, precision='fp32', lang='en_us', **model_kwargs)
Return type:

ModelBase

birdnet.load_custom(model_type, version, backend, model, species_list, /, *, precision='fp32', check_validity=True, **model_kwargs)
Return type:

ModelBase

birdnet.load_perch_v2(device='CPU')
Return type:

AcousticModelPerchV2

birdnet.set_download_progress_callback(callback)

Register a process-wide callback for download progress; returns the previous one.

Pass None to unregister. With no callback registered (the default), downloads behave exactly as before: a tqdm bar on stderr. While a callback is registered the tqdm bar is disabled. An exception raised by the callback aborts the running download without a retry and propagates out of load(..) (see the module docstring).

Return type:

Callable[[DownloadProgress], None] | None