birdnet package¶
Subpackages¶
- birdnet.acoustic.models package
- Subpackages
- birdnet.acoustic.inference.core package
- Subpackages
- Submodules
- birdnet.acoustic.inference.core.benchmarking module
- birdnet.acoustic.inference.core.consumer module
- birdnet.acoustic.inference.core.input_analyzer module
- birdnet.acoustic.inference.core.perf_tracker module
- birdnet.acoustic.inference.core.producer module
- birdnet.acoustic.inference.core.result_base module
- birdnet.acoustic.inference.core.tensor module
- birdnet.acoustic.inference.core.worker module
- Module contents
- birdnet.acoustic.inference package
- Submodules
- birdnet.acoustic.inference.benchmarking module
- birdnet.acoustic.inference.configs module
- birdnet.acoustic.inference.encoding_strategy module
- birdnet.acoustic.inference.file_writer module
- birdnet.acoustic.inference.prediction_strategy module
- birdnet.acoustic.inference.process_manager module
- birdnet.acoustic.inference.resources module
- birdnet.acoustic.inference.session module
- birdnet.acoustic.inference.strategy module
- Module contents
- birdnet.acoustic.models.perch_v2 package
- birdnet.acoustic.models.v2_4 package
- birdnet.acoustic.models.v3_0 package
- birdnet.acoustic.inference.core package
- Submodules
- birdnet.acoustic.models.base module
AcousticModelBaseAcousticModelBase.backend_kwargsAcousticModelBase.backend_typeAcousticModelBase.encode()AcousticModelBase.encode_arrays()AcousticModelBase.encode_session()AcousticModelBase.get_sample_rate()AcousticModelBase.get_segment_size_s()AcousticModelBase.get_segment_size_samples()AcousticModelBase.get_sig_fmax()AcousticModelBase.get_sig_fmin()AcousticModelBase.get_version()AcousticModelBase.load()AcousticModelBase.load_custom()AcousticModelBase.predict()AcousticModelBase.predict_arrays()AcousticModelBase.predict_session()
resolve_in_graph_sigmoid_options()validate_batch_size_for_backend()validate_segment_size_for_backend()
- Module contents
- Subpackages
- birdnet.geo.models package
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:
_StoreActionDocstring 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- classmethod applies_sigmoid()¶
Whether the sigmoid is applied inside the model graph.
A model that applies the sigmoid inside its graph must not get the pipeline’s sigmoid on top: that squashes every score into [0.5, 0.73]. The prediction worker recovers the logits from such a model’s scores when a non-default sigmoid sensitivity asks for the pipeline sigmoid after all.
- Return type:
bool
- 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)
- classmethod fixed_input_samples()¶
The only input length, in samples, the model accepts, or None for any.
Exports compiled with a static input length fail inside the worker for any other segment length, so the session rejects such a length up front.
- Return type:
int|None
- abstractmethod half_precision(inference_result)¶
- Return type:
TypeVar(BatchT,ndarray, Tensor, TorchTensor)
- abstractmethod load()¶
- Return type:
None
- classmethod max_batch_size()¶
The largest batch the model accepts, or None when the batch is dynamic.
Exports compiled with a static batch dimension fail inside the worker for anything larger, so the session rejects such a batch size up front.
- Return type:
int|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_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
- classmethod inspect_custom_tflite_model(model_path, library, legacy_prediction_indices)¶
Describe a custom TFLite classifier in a subprocess.
The subprocess keeps TensorFlow (or LiteRT) out of the calling process, so an application can inspect a file before deciding how to load it.
- Return type:
CustomTFLiteInfo
- load_backend(device_name, half_precision)¶
- Return type:
- 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 sigmoid scores.
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 scores.
- 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- classmethod applies_sigmoid()¶
- Return type:
bool
- classmethod fixed_input_samples()¶
- Return type:
int|None
- classmethod max_batch_size()¶
- Return type:
int|None
- 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.cpu_threads_per_worker(n_workers)¶
Intra-op threads for each of
n_workersCPU inference processes.ONNX Runtime, PyTorch and TensorFlow size their thread pools to all cores in every process, so
n_workersworkers runn_workerstimes as many busy threads as there are cores. On 8 cores with 8 workers that made the 3.0 ONNX model 8.6x slower than one thread per worker.- Return type:
int
- 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, preserve_all_tensors=False)¶
- Return type:
Interpreter
- birdnet.core.backends.load_lib_tf_model(model_path, allocate_tensors=False, preserve_all_tensors=False)¶
- Return type:
TFInterpreter
- birdnet.core.backends.load_onnx_model(model_path, device, cpu_threads=None)¶
- 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, preserve_all_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.run_in_subprocess(fn, args, timeout_s)¶
Run fn(*args) in a fresh process and return what it returns.
A model that hangs while opening would otherwise hold up the caller, and a pool worker cannot be killed, so this is a process of its own: the timeout terminates it, and an exception raised inside is raised here. Only builtin exceptions arrive as themselves; any other becomes a RuntimeError naming its type, because unpickling it would import its module (TensorFlow, for a TensorFlow error) into this process.
- Return type:
Any
- birdnet.core.backends.set_cpu_device_tf(cpu_threads=None)¶
- 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:
- abstractmethod predict_session(*args, **kwargs)¶
- Return type:
- 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
- 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¶
-
model:
- 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 higherattemptandbytes_done == 0announces a retry;"progress"at most every 0.1 s (first chunk of an attempt always);"retrying"before each back-off, witherrorandretry_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:
objectOne 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
Nonewhile 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¶
-
attempt:
- class birdnet.utils.download_progress.DownloadReporter(url, description, max_attempts, callback)¶
Bases:
objectEmits the events of one download (all attempts) to one captured callback.
Internal helper for
download_file_tqdm; not part of the public API. Withcallback=Noneevery 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
callbackfor the duration of thewithblock and restores whatever was registered before on exit (includingNone).- 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
Noneto 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 ofload(..)(see the module docstring).- Return type:
Callable[[DownloadProgress],None] |None
birdnet.utils.helper module¶
- exception birdnet.utils.helper.DownloadError(message, *, status_code=None)¶
Bases:
ValueErrorA download did not complete successfully.
Subclasses
ValueErrorbecause that is what this helper has always raised for a failed download;status_codeis 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, sha256=None)¶
Bases:
object- property content_tag: str¶
Checksum prefix embedded in the cached file’s name.
The name then identifies the release content itself: a release that expects different bytes looks for a different file, so it can neither serve another release’s model nor overwrite it in a shared app data directory.
-
dl_file_name:
str¶
-
dl_size:
int¶
-
dl_url:
str¶
-
file_size:
int¶
-
sha256:
str|None= None¶
- 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_protobuf_model_files_exist(folder)¶
- Return type:
bool
- birdnet.utils.helper.check_source_marker(model_dir, dl_url)¶
- Return type:
bool
- birdnet.utils.helper.directory_lock(lock_dir, description, timeout_s=300.0)¶
Serialize one-time setup across processes by creating a directory.
mkdir is atomic on every platform this runs on, which a lock file is not. The holder records its pid inside, so a lock left behind by a process that no longer exists is reclaimed rather than waited out.
A holder in a long step keeps a beat going with lock_heartbeat; timeout_s then bounds the time since the beat last changed, not the wait as a whole.
- Return type:
Generator[None,None,None]
- 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.ensure_single_file_model(info, model_path, legacy_path, description)¶
Put the model file info describes at model_path, downloading if needed.
A hit is by byte size alone: model_path carries info.content_tag, so a file there at the declared size is the one this release published. Hashing it on every load would cost seconds for the ~540 MB acoustic models. Byte size alone is not identity (see label_manifest.artifact_is_current).
- Return type:
None
- birdnet.utils.helper.fillup_with_silence(audio_segment, target_length)¶
- Return type:
GenericAlias[float32]
- birdnet.utils.helper.flat_logit_fast(x)¶
Invert a plain sigmoid: the logit each score came from,
log(p) - log1p(-p).Saturated scores (0.0 and 1.0) give
-infandinf, whichflat_sigmoid_logaddexp_fastclips like any logit beyondclip_val.- Return type:
TypeAliasType
- 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_species_from_raven_labels(labels_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(5_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.lock_heartbeat(lock_dir, interval_s)¶
Touch a file inside the held lock_dir every interval_s, from a thread.
The beat proves that the holder’s process is alive and still inside the step, not that it is making progress: a holder hung in a call that never returns keeps beating until its process ends. Waiters give up only once the beat stops changing.
- Return type:
Generator[None,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.sha256_file(path)¶
- Return type:
str
- birdnet.utils.helper.uint_ctype_from_dtype(dtype)¶
- Return type:
c_ubyte|c_ushort|c_uint|c_ulong
- 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.write_text_atomic(path, content, encoding='utf-8')¶
Write via a temporary file in the same directory, then rename over.
A reader either sees the previous content or the new one, never a partial file, and an interrupted write leaves nothing behind but a .tmp scratch file.
Newlines are written through unchanged, so the same content yields the same bytes on every platform. Without that, files generated on Windows and on Linux differ, and anything that records a checksum of them records a different one per operating system.
- Return type:
None
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, content_tag=None)¶
- 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.inspect_custom_tflite(model, /, *, library='tflite')¶
Describe a custom TFLite classifier exported by BirdNET-Analyzer.
Reports the BirdNET version the classifier was trained on (“2.4” or “3.0”), whether it replaces the official species or appends to them, its number of species (the length its labels file must have), whether it applies the sigmoid itself, whether it exposes embeddings for encode(..) and the input length it fixes, if any. The version is read from the input length and the embeddings width, not from the file name. The file is opened, with its tensors allocated, in a subprocess: a file the interpreter cannot run is rejected, and TensorFlow (or LiteRT) is never imported into the calling process.
- Return type:
- Parameters:
model – Path to the
.tflitefile.library – Interpreter to open it with,
"tflite"(TensorFlow) or"litert".
- Raises:
ValueError – The file is not a BirdNET classifier, e.g. a detached head that takes embeddings instead of audio.
- birdnet.model_loader.load(model_type, version, backend, /, *, precision='fp32', lang='en_us', **model_kwargs)¶
- Return type:
- birdnet.model_loader.load_custom(model_type, version, backend, model, species_list, /, *, precision='fp32', check_validity=True, **model_kwargs)¶
Load a custom model, e.g. a classifier trained with BirdNET-Analyzer.
For acoustic
tf(TFLite) classifiersversionmay be"auto": the BirdNET version the classifier was trained on is then read from the file (see inspect_custom_tflite). Withcheck_validity(the default) the file is inspected in a subprocess before loading, which also rejects a version that does not match the file and a species list of the wrong length.- Return type:
- birdnet.model_loader.load_perch_v2(device='CPU')¶
- Return type:
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]
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:
- run_arrays(inputs)¶
- Return type:
- 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.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:
- run_arrays(inputs)¶
- Return type:
- 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¶
-
buffer_stats:
- class birdnet.AcousticSessionBase(conf, strategy, specific_config)¶
Bases:
Generic[ResultType,ConfigType,TensorType],SessionBase,ABC- cancel()¶
- Return type:
None
- end()¶
- Return type:
None
- class birdnet.CustomTFLiteInfo(version, mode, n_species, applies_sigmoid, supports_encoding, input_samples=None)¶
Bases:
objectWhat birdnet.inspect_custom_tflite reports about a custom classifier.
- version¶
The BirdNET model the classifier was trained on (“2.4” or “3.0”).
- mode¶
“append” when the official species precede the custom ones in the output, “replace” when the output holds the custom species only.
- n_species¶
Width of the prediction output, i.e. the length its labels file must have.
- applies_sigmoid¶
True when the sigmoid is applied inside the graph (every 3.0 export); False when the output holds logits (the 2.4 exports), which the prediction session turns into scores itself.
- supports_encoding¶
Whether the file exposes the backbone’s embeddings, so encode(..) works on it.
- input_samples¶
Length of the audio input in samples when the file fixes it, or None when it takes any length. A 3.0 classifier with a fixed input runs only with
segment_size_s=3.0.
-
applies_sigmoid:
bool¶
-
input_samples:
int|None= None¶
-
mode:
Literal['replace','append']¶
-
n_species:
int¶
-
supports_encoding:
bool¶
-
version:
Literal['2.4','3.0']¶
- class birdnet.DownloadProgress(description, url, bytes_done, bytes_total, attempt, max_attempts, status, error=None, retry_in_s=None)¶
Bases:
objectOne 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
Nonewhile 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¶
-
attempt:
- class birdnet.GeoPredictionResult(model_path, model_version, model_precision, latitude, longitude, week, species_masked, species_ids, species_probs, species_list)¶
Bases:
ResultBase- property latitude: float¶
- property longitude: float¶
- 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:
- birdnet.download_progress_callback(callback)¶
Scoped alternative to
set_download_progress_callback().Registers
callbackfor the duration of thewithblock and restores whatever was registered before on exit (includingNone).- 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.inspect_custom_tflite(model, /, *, library='tflite')¶
Describe a custom TFLite classifier exported by BirdNET-Analyzer.
Reports the BirdNET version the classifier was trained on (“2.4” or “3.0”), whether it replaces the official species or appends to them, its number of species (the length its labels file must have), whether it applies the sigmoid itself, whether it exposes embeddings for encode(..) and the input length it fixes, if any. The version is read from the input length and the embeddings width, not from the file name. The file is opened, with its tensors allocated, in a subprocess: a file the interpreter cannot run is rejected, and TensorFlow (or LiteRT) is never imported into the calling process.
- Return type:
- Parameters:
model – Path to the
.tflitefile.library – Interpreter to open it with,
"tflite"(TensorFlow) or"litert".
- Raises:
ValueError – The file is not a BirdNET classifier, e.g. a detached head that takes embeddings instead of audio.
- birdnet.load(model_type, version, backend, /, *, precision='fp32', lang='en_us', **model_kwargs)¶
- Return type:
- birdnet.load_custom(model_type, version, backend, model, species_list, /, *, precision='fp32', check_validity=True, **model_kwargs)¶
Load a custom model, e.g. a classifier trained with BirdNET-Analyzer.
For acoustic
tf(TFLite) classifiersversionmay be"auto": the BirdNET version the classifier was trained on is then read from the file (see inspect_custom_tflite). Withcheck_validity(the default) the file is inspected in a subprocess before loading, which also rejects a version that does not match the file and a species list of the wrong length.- Return type:
- birdnet.load_perch_v2(device='CPU')¶
- Return type:
- birdnet.set_download_progress_callback(callback)¶
Register a process-wide callback for download progress; returns the previous one.
Pass
Noneto 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 ofload(..)(see the module docstring).- Return type:
Callable[[DownloadProgress],None] |None
- class birdnet.AcousticModelPerchV2(model_path, species_list, is_custom_model, backend_type, backend_kwargs)¶
Bases:
AcousticModelBase- property backend_kwargs: dict[str, Any]¶
- property backend_type: type[VersionedAcousticBackendProtocol]¶
- 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:
- Parameters:
inp – Path(s) or string(s) pointing to audio files to encode.
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- 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:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- 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:
- Parameters:
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- final classmethod get_embeddings_dim()¶
- Return type:
int
- final classmethod get_sample_rate()¶
- Return type:
int
- final classmethod get_segment_size_s()¶
- Return type:
float
- final classmethod get_segment_size_samples()¶
- Return type:
int
- final classmethod get_sig_fmax()¶
- Return type:
int
- final classmethod get_sig_fmin()¶
- Return type:
int
- final 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
- property is_custom_model: bool¶
- classmethod load(model_path, species_list, backend_type, backend_kwargs)¶
- Return type:
Self
- classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)¶
- Return type:
Self
- property model_path: Path¶
- property n_species: int¶
- 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:
- 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 – Processes 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 sigmoid scores.
apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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; file inputs only (not predict_arrays). A callback that raises cancels the run.
- Returns:
- Object containing detected species and confidence
scores.
- Return type:
- 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:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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 sigmoid scores.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.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 sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- 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:
- Parameters:
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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 sigmoid scores.
apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- property species_list: OrderedSet[str]¶
- class birdnet.AcousticModelV2_4(model_path, species_list, is_custom_model, backend_type, backend_kwargs)¶
Bases:
AcousticModelBase- property backend_kwargs: dict[str, Any]¶
- property backend_type: type[VersionedAcousticBackendProtocol]¶
- 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:
- Parameters:
inp – Path(s) or string(s) pointing to audio files to encode.
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- 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:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- 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:
- Parameters:
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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:
- final classmethod get_embeddings_dim()¶
- Return type:
int
- final classmethod get_sample_rate()¶
- Return type:
int
- final classmethod get_segment_size_s()¶
- Return type:
float
- final classmethod get_segment_size_samples()¶
- Return type:
int
- final classmethod get_sig_fmax()¶
- Return type:
int
- final classmethod get_sig_fmin()¶
- Return type:
int
- final 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
- property is_custom_model: bool¶
- classmethod load(model_path, species_list, backend_type, backend_kwargs)¶
- Return type:
Self
- classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)¶
- Return type:
Self
- property model_path: Path¶
- property n_species: int¶
- 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:
- 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 – Processes tasked with producing audio batches.
n_workers – Number of inference worker processes.
Noneuses the number of physical CPU cores. Pass a fixed integer to meet a scheduler or container process limit. Each worker holds its own copy of the model, so a high count raises peak memory use. In the cases the pipeline guards against, a worker killed by the operating system to reclaim memory, including while it is processing a batch, is reported as an error naming the dead worker rather than hanging the call (see issue #73). Loweringn_workersorbatch_sizereduces 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 sigmoid scores.
apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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; file inputs only (not predict_arrays). A callback that raises cancels the run.
A Raven export (
load_custom(.., "pb", .., is_raven=True)) applies the sigmoid inside its graph, soapply_sigmoid=Truereturns its scores as they are. Asigmoid_sensitivityother than1.0is applied on logits recovered from those scores;apply_sigmoid=Falsereturns the raw scores and ignores the sensitivity, as for a TFLite export.apply_softmax=Trueraises aValueError, as for the V3.0 models.- Returns:
- Object containing detected species and confidence
scores.
- Return type:
- 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:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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 sigmoid scores.
apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
A Raven export (
load_custom(.., "pb", .., is_raven=True)) applies the sigmoid inside its graph, soapply_sigmoid=Truereturns its scores as they are. Asigmoid_sensitivityother than1.0is applied on logits recovered from those scores;apply_sigmoid=Falsereturns the raw scores and ignores the sensitivity, as for a TFLite export.apply_softmax=Trueraises aValueError, as for the V3.0 models.- Returns:
- Object containing detected species and confidence
scores.
- Return type:
- 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:
- Parameters:
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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 sigmoid scores.
apply_softmax – Whether to transform logits with a softmax. When False, output scores are raw logits unless apply_sigmoid=True.
sigmoid_sensitivity – Shifts the logits by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection. When apply_sigmoid=True this is a sigmoid score (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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
A Raven export (
load_custom(.., "pb", .., is_raven=True)) applies the sigmoid inside its graph, soapply_sigmoid=Truereturns its scores as they are. Asigmoid_sensitivityother than1.0is applied on logits recovered from those scores;apply_sigmoid=Falsereturns the raw scores and ignores the sensitivity, as for a TFLite export.apply_softmax=Trueraises aValueError, as for the V3.0 models.- Returns:
Session capable of running predictions.
- Return type:
- property species_list: OrderedSet[str]¶
- class birdnet.AcousticModelV3_0(model_path, species_list, is_custom_model, backend_type, backend_kwargs)¶
Bases:
AcousticModelBase- property backend_kwargs: dict[str, Any]¶
- property backend_type: type[VersionedAcousticBackendProtocol]¶
- 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', segment_size_s=3.0, on_file_complete=None)¶
Run encoding with the BirdNET 3.0 model on files or paths to obtain embeddings.
- Return type:
- Parameters:
inp – Path(s) or string(s) pointing to audio files to encode.
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.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:
- 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', segment_size_s=3.0)¶
Run encoding with the BirdNET 3.0 model directly on in-memory audio arrays.
- Return type:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.
- Returns:
Object containing embeddings for each input array.
- Return type:
- 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, segment_size_s=3.0, on_file_complete=None)¶
Create an encoding session with explicit resource configuration.
- Return type:
- Parameters:
n_producers – Processes 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 – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.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:
- final classmethod get_embeddings_dim()¶
- Return type:
int
- final classmethod get_sample_rate()¶
- Return type:
int
- final classmethod get_segment_size_s()¶
- Return type:
float
- final classmethod get_segment_size_samples()¶
- Return type:
int
- final classmethod get_sig_fmax()¶
- Return type:
int
- final classmethod get_sig_fmin()¶
- Return type:
int
- final 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
- property is_custom_model: bool¶
- classmethod load(model_path, species_list, backend_type, backend_kwargs)¶
- Return type:
Self
- classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)¶
- Return type:
Self
- property model_path: Path¶
- property n_species: int¶
- 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, apply_softmax=False, 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, segment_size_s=3.0, on_file_complete=None)¶
Run prediction with the BirdNET 3.0 model on files or paths.
Scores are returned as the model emits them: the V3.0 exports apply the sigmoid inside the model graph.
apply_sigmoid=True(the default) returns them unchanged andapply_sigmoid=Falsereturns the identical raw model output, so confidence thresholds are sigmoid scores either way. Asigmoid_sensitivityother than1.0is applied as it is to the 2.4 models, on logits recovered from the scores, and is ignored withapply_sigmoid=Falseas there.apply_softmax=Trueraises aValueError. Custom V3.0 models are expected to apply the sigmoid as well.This method creates one prediction session for the call. That session shuts down its producer and worker processes before this method returns, including when inference raises an exception.
- Return type:
- 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 – Processes tasked with producing audio batches.
n_workers – Number of inference worker processes.
Noneuses the number of physical CPU cores. Pass a fixed integer to meet a scheduler or container process limit. Each worker holds its own copy of the model, so a high count raises peak memory use. In the cases the pipeline guards against, a worker killed by the operating system to reclaim memory, including while it is processing a batch, is reported as an error naming the dead worker rather than hanging the call (see issue #73). Loweringn_workersorbatch_sizereduces 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 – The 3.0 exports apply the sigmoid inside the model graph, so False returns the model’s scores unchanged, as does True (the default) at the default
sigmoid_sensitivityof 1.0. False ignoressigmoid_sensitivity.apply_softmax – Must stay False; True raises a
ValueErrorfor the 3.0 models.sigmoid_sensitivity – Shifts the logits, recovered from the model’s scores, by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection, as a sigmoid score (range 0 to 1).
custom_confidence_thresholds – Species-specific override thresholds.
custom_species_list – Path or iterable defining a subset of species.
half_precision – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.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 predict_arrays). A callback that raises cancels the run.
- Returns:
- Object containing detected species and confidence
scores.
- Return type:
- 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, apply_softmax=False, 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, segment_size_s=3.0)¶
Run prediction with the BirdNET 3.0 model directly on in-memory audio arrays.
- Return type:
- Parameters:
inp – Tuple(s) of (audio ndarray, sampling rate).
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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 – The 3.0 exports apply the sigmoid inside the model graph, so False returns the model’s scores unchanged, as does True (the default) at the default
sigmoid_sensitivityof 1.0. False ignoressigmoid_sensitivity.apply_softmax – Must stay False; True raises a
ValueErrorfor the 3.0 models.sigmoid_sensitivity – Shifts the logits, recovered from the model’s scores, by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection, as a sigmoid score (range 0 to 1).
custom_confidence_thresholds – Species-specific override thresholds.
custom_species_list – Path or iterable defining a subset of species.
half_precision – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.
- Returns:
- Object containing detected species and confidence
scores.
- Return type:
- 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, apply_softmax=False, 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, segment_size_s=3.0, on_file_complete=None)¶
Create a prediction session for the BirdNET 3.0 model.
Scores: every V3.0 export (tf, pb, pt, onnx — official and custom alike) applies the sigmoid inside the model graph, so scores leave the model with the sigmoid applied.
apply_sigmoid=True(the default) returns them unchanged — no second sigmoid is applied — andapply_sigmoid=Falsereturns the identical raw model output. Asigmoid_sensitivityother than1.0is applied as it is to the 2.4 models: the logits are recovered from the model’s scores and the pipeline’s sigmoid runs on them, so thresholds see the transformed scores; withapply_sigmoid=Falsethe sensitivity is ignored, as for the 2.4 models.apply_softmax=Trueraises aValueError.The
tfandpbexports (official and custom) have a static batch dimension of 1, sobatch_sizeabove 1 raises aValueErrorfor them;onnxandpttake any batch size.- Return type:
- Parameters:
top_k – Number of highest-confidence results to return per segment.
n_producers – Processes 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.
apply_sigmoid – The 3.0 exports apply the sigmoid inside the model graph, so False returns the model’s scores unchanged, as does True (the default) at the default
sigmoid_sensitivityof 1.0. False ignoressigmoid_sensitivity.apply_softmax – Must stay False; True raises a
ValueErrorfor the 3.0 models.sigmoid_sensitivity – Shifts the logits, recovered from the model’s scores, by
10 * (sigmoid_sensitivity - 1)before the sigmoid, so values above 1.0 raise the scores and values below lower them; between 0.5 and 1.5,Nonemeans 1.0. Ignored withapply_sigmoid=False.default_confidence_threshold – Base threshold to emit a detection, as a sigmoid score (range 0 to 1).
custom_confidence_thresholds – Species-specific override thresholds.
custom_species_list – Path or iterable defining a subset of species.
half_precision – Cast the model’s outputs to float16 after inference; inference itself runs at the model’s precision.
max_audio_duration_min – Longest single input, in minutes, the segment indices are sized for;
Nonesizes them for any length. An input with more segments than they can hold raises an error.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.
segment_size_s – Length in seconds of the audio segments passed to the model. The official
tf,onnxandptexports accept lengths other than the default 3.0 s.pband the custom classifier exports take only 3.0 s and raise aValueErrorfor any other length; a custom TFLite export loaded withcheck_validity=Falseand an explicit version fails during the run instead.overlap_duration_smust be smaller than this value.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:
- property species_list: OrderedSet[str]¶
- class birdnet.GeoModelV2_4(model_path, species_list, is_custom_model, backend_type, backend_kwargs)¶
Bases:
GeoModelBase- property backend_kwargs: dict[str, Any]¶
- property backend_type: type[VersionedGeoBackendProtocol]¶
- final classmethod get_model_type()¶
- Return type:
Literal['acoustic','geo']
- final classmethod get_version()¶
- Return type:
Literal['2.4','3.0']
- property is_custom_model: bool¶
- classmethod load(model_path, species_list, backend_type, backend_kwargs)¶
- Return type:
Self
- classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)¶
- Return type:
Self
- property model_path: Path¶
- property n_species: int¶
- predict(latitude, longitude, /, *, week=None, year_round_aggregation='max', min_confidence=0.03, half_precision=False, device='CPU')¶
- Return type:
- predict_session(*, min_confidence=0.03, half_precision=False, device='CPU')¶
- Return type:
- property species_list: OrderedSet[str]¶
- class birdnet.GeoModelV3_0(model_path, species_list, is_custom_model, backend_type, backend_kwargs)¶
Bases:
GeoModelBase- property backend_kwargs: dict[str, Any]¶
- property backend_type: type[VersionedGeoBackendProtocol]¶
- final classmethod get_model_type()¶
- Return type:
Literal['acoustic','geo']
- final classmethod get_version()¶
- Return type:
Literal['2.4','3.0']
- property is_custom_model: bool¶
- classmethod load(model_path, species_list, backend_type, backend_kwargs)¶
- Return type:
Self
- classmethod load_custom(model_path, species_list, backend_type, backend_kwargs, check_validity)¶
- Return type:
Self
- property model_path: Path¶
- property n_species: int¶
- predict(latitude, longitude, /, *, week=None, year_round_aggregation='max', min_confidence=0.03, half_precision=False, device='CPU')¶
- Return type:
- predict_session(*, min_confidence=0.03, half_precision=False, device='CPU')¶
- Return type:
- property species_list: OrderedSet[str]¶