Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions birdnet_analyzer/analyze/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ def analyze(
effective_sensitivity,
run_geomodel,
run_inference,
validate_min_conf,
)
from birdnet_analyzer.utils import save_params_file

# Settled before the params file, result columns and resume fingerprint see it.
sensitivity = effective_sensitivity(sensitivity, model, birdnet, classifier)
validate_min_conf(min_conf)

species_list_file = slist if isinstance(slist, (str, Path)) else ""
rtypes: list[RESULT_TYPES] = [rtype] if isinstance(rtype, str) else rtype
Expand Down
5 changes: 4 additions & 1 deletion birdnet_analyzer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ def min_conf_args():
"--min_conf",
default=0.25,
type=lambda a: max(0.00001, min(0.99, float(a))),
help="Minimum confidence threshold. Values in [0.00001, 0.99].",
help="Minimum confidence threshold. Values in [0.00001, 0.99]. Perch "
"confidences are softmax probabilities: simultaneous vocalizations "
"share the probability mass, so dense soundscapes may need a lower "
"threshold than BirdNET models.",
)

return p
Expand Down
15 changes: 15 additions & 0 deletions birdnet_analyzer/gui/single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from birdnet_analyzer.gui.state import TabState

MATPLOTLIB_FIGURE_NUM = "single-file-tab-spectrogram-plot"
MAX_TABLE_ROWS = 50
HEADER_START_LBL = loc.localize("single-tab-output-header-start")
HEADER_END_LBL = loc.localize("single-tab-output-header-end")
HEADER_SCI_NAME_LBL = loc.localize("single-tab-output-header-sci-name")
Expand Down Expand Up @@ -91,6 +92,20 @@ def convert_to_time_str(seconds: float) -> str:
return time_str

table = predictions.to_dataframe()
n_total = table.shape[0]

if n_total > MAX_TABLE_ROWS:
# nlargest has no float16 kernel
table["confidence"] = table["confidence"].astype("float32")
table = table.nlargest(MAX_TABLE_ROWS, "confidence").sort_values(
["start_time", "end_time"]
)
gr.Warning(
loc.localize("single-tab-results-truncated-warning").format(
shown=MAX_TABLE_ROWS, total=n_total
)
)

n_rows = table.shape[0]

if n_rows > 0:
Expand Down
6 changes: 4 additions & 2 deletions birdnet_analyzer/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ def _show_download_update(update, progress: "gr.Progress | None") -> None:
if update.status == "started" and progress is None:
gr.Info(label)
elif update.status in ("progress", "finished") and progress is not None:
# "progress" is throttled, so only "finished" reliably shows the bar full.
if update.status == "finished":
progress(1.0, desc=f"{label} ({_format_bytes(update.bytes_done)})")
progress(
1.0,
desc=f"{loc.localize('progress-preparing-model')}: {name} ...",
)
elif update.bytes_total:
done = _format_bytes(update.bytes_done)
total = _format_bytes(update.bytes_total)
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Modell wird heruntergeladen",
"progress-extracting-segments": "Segmente extrahieren",
"progress-loading-data": "Daten für",
"progress-preparing-model": "Modell wird vorbereitet",
"progress-saving": "Gespeichert unter",
"progress-search": "Dateien suchen",
"progress-starting": "Starten",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Ende",
"single-tab-output-header-sci-name": "Wissenschaftlicher Name",
"single-tab-output-header-start": "Start",
"single-tab-results-truncated-warning": "Angezeigt werden die {shown} Erkennungen mit den höchsten Werten von insgesamt {total}. Die vollständigen Ergebnisse gibt es über die Download-Buttons.",
"single-tab-select-file-button-label": "Audiodatei auswählen",
"single-tab-spectrogram-checkbox-info": "Potentiell langsam für sehr lange Dateien.",
"single-tab-spectrogram-checkbox-label": "Spektrogramm generieren",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Downloading model",
"progress-extracting-segments": "Extracting segments",
"progress-loading-data": "Loading data for",
"progress-preparing-model": "Preparing model",
"progress-saving": "Saving at",
"progress-search": "Searching files",
"progress-starting": "Starting",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "End",
"single-tab-output-header-sci-name": "Scientific name",
"single-tab-output-header-start": "Start",
"single-tab-results-truncated-warning": "Showing the {shown} highest-scoring of {total} detections. Use the download buttons for the complete results.",
"single-tab-select-file-button-label": "Select Audio File",
"single-tab-spectrogram-checkbox-info": "Potentially slow for long audio files.",
"single-tab-spectrogram-checkbox-label": "Generate spectrogram",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Ladataan mallia",
"progress-extracting-segments": "Segmenttejä puretaan",
"progress-loading-data": "Ladataan dataa kohteelle",
"progress-preparing-model": "Valmistellaan mallia",
"progress-saving": "Tallennetaan kohteeseen",
"progress-search": "Haetaan tiedostoja",
"progress-starting": "Aloitetaan",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Loppu",
"single-tab-output-header-sci-name": "Tieteellinen nimi",
"single-tab-output-header-start": "Alku",
"single-tab-results-truncated-warning": "Näytetään {shown} korkeimman pistemäärän havaintoa {total} havainnosta. Täydelliset tulokset saat latauspainikkeilla.",
"single-tab-select-file-button-label": "Valitse äänitiedosto",
"single-tab-spectrogram-checkbox-info": "Saattaa olla hidasta pitkillä äänitiedostoilla.",
"single-tab-spectrogram-checkbox-label": "Luo spektrogrammi",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Téléchargement du modèle",
"progress-extracting-segments": "Extraction des segments",
"progress-loading-data": "Chargement des données pour",
"progress-preparing-model": "Préparation du modèle",
"progress-saving": "Enregistrement à",
"progress-search": "Recherche des fichier...",
"progress-starting": "Démarrage...",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Arrêter",
"single-tab-output-header-sci-name": "Nom scientifique",
"single-tab-output-header-start": "Commencer",
"single-tab-results-truncated-warning": "Affichage des {shown} détections aux scores les plus élevés sur {total}. Utilisez les boutons de téléchargement pour les résultats complets.",
"single-tab-select-file-button-label": "Sélectionner un fichier audio",
"single-tab-spectrogram-checkbox-info": "Potentiellement lent pour les fichiers audio longs.",
"single-tab-spectrogram-checkbox-label": "Générer le spectrogramme",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Mengunduh model",
"progress-extracting-segments": "Mengekstrak segmen",
"progress-loading-data": "Memuat data untuk",
"progress-preparing-model": "Menyiapkan model",
"progress-saving": "Menyimpan di",
"progress-search": "Mencari file",
"progress-starting": "Memulai",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Selesai",
"single-tab-output-header-sci-name": "Nama ilmiah",
"single-tab-output-header-start": "Mulai",
"single-tab-results-truncated-warning": "Menampilkan {shown} deteksi dengan skor tertinggi dari {total}. Gunakan tombol unduh untuk hasil lengkap.",
"single-tab-select-file-button-label": "Pilih Berkas Audio",
"single-tab-spectrogram-checkbox-info": "Berpotensi lambat untuk file audio yang panjang.",
"single-tab-spectrogram-checkbox-label": "Hasilkan spektrogram",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Baixando modelo",
"progress-extracting-segments": "Extraindo segmentos",
"progress-loading-data": "Carregando os dados para",
"progress-preparing-model": "Preparando modelo",
"progress-saving": "slvando em",
"progress-search": "Procurando arquivos",
"progress-starting": "Começando",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Fim",
"single-tab-output-header-sci-name": "Nome científico",
"single-tab-output-header-start": "Início",
"single-tab-results-truncated-warning": "Exibindo as {shown} detecções com maior pontuação de {total}. Use os botões de download para os resultados completos.",
"single-tab-select-file-button-label": "Selecionar Arquivo de Áudio",
"single-tab-spectrogram-checkbox-info": "Pode ser lento para arquivos de áudio longos.",
"single-tab-spectrogram-checkbox-label": "Gerar espectrograma",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Загрузка модели",
"progress-extracting-segments": "Извлечение сегментов",
"progress-loading-data": "Загрузка данных для",
"progress-preparing-model": "Подготовка модели",
"progress-saving": "Сохранение в",
"progress-search": "Поиск файлов",
"progress-starting": "Начать",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Конец (сек)",
"single-tab-output-header-sci-name": "Научное название",
"single-tab-output-header-start": "Старт (сек)",
"single-tab-results-truncated-warning": "Показаны {shown} обнаружений с наивысшими оценками из {total}. Полные результаты доступны по кнопкам скачивания.",
"single-tab-select-file-button-label": "Выбрать аудиофайл",
"single-tab-spectrogram-checkbox-info": "Потенциально медленная операция для длинных аудиофайлов.",
"single-tab-spectrogram-checkbox-label": "Генерирование спектрограммы",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "Laddar ner modell",
"progress-extracting-segments": "Extraherar segment",
"progress-loading-data": "Laddar data för",
"progress-preparing-model": "Förbereder modell",
"progress-saving": "Sparar i",
"progress-search": "Söker filer",
"progress-starting": "Startar",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Slut",
"single-tab-output-header-sci-name": "Vetenskapligt namn",
"single-tab-output-header-start": "Start",
"single-tab-results-truncated-warning": "Visar de {shown} detektioner med högst poäng av {total}. Använd nedladdningsknapparna för de fullständiga resultaten.",
"single-tab-select-file-button-label": "Välj ljudfil",
"single-tab-spectrogram-checkbox-info": "Kan vara långsamt för långa ljudfiler.",
"single-tab-spectrogram-checkbox-label": "Generera spektrogram",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/tlh.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "model'e' Downloadlu'",
"progress-extracting-segments": "'ay'mey lInglu'",
"progress-loading-data": "De' poQ",
"progress-preparing-model": "model'e' ghuHlu'",
"progress-saving": "pol",
"progress-search": "wavmey qel",
"progress-starting": "tagh",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "Dor (s)",
"single-tab-output-header-sci-name": "Hol qonwI' pong",
"single-tab-output-header-start": "Tagh (s)",
"single-tab-results-truncated-warning": "{total} Sammey'e' {shown} nIvbogh mI'mey neH cha'lu'. Hoch Sammey DaneHchugh Download leQmey yIlo'.",
"single-tab-select-file-button-label": "QoQ teywI' yIwIv",
"single-tab-spectrogram-checkbox-info": "wavmey tInmo' QapHa'laH.",
"single-tab-spectrogram-checkbox-label": "nuvmey vItlhutlh",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "正在下载模型",
"progress-extracting-segments": "正在提取片段",
"progress-loading-data": "正在为以下内容加载数据",
"progress-preparing-model": "正在准备模型",
"progress-saving": "正在保存至",
"progress-search": "正在搜索文件",
"progress-starting": "正在开始",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "结束",
"single-tab-output-header-sci-name": "学名",
"single-tab-output-header-start": "开始",
"single-tab-results-truncated-warning": "仅显示 {total} 条检测结果中分数最高的 {shown} 条。完整结果请使用下载按钮。",
"single-tab-select-file-button-label": "选择音频文件",
"single-tab-spectrogram-checkbox-info": "对于较长的音频文件可能较慢。",
"single-tab-spectrogram-checkbox-label": "生成频谱图",
Expand Down
2 changes: 2 additions & 0 deletions birdnet_analyzer/lang/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"progress-downloading-model": "正在下載模型",
"progress-extracting-segments": "正在擷取片段",
"progress-loading-data": "載入資料中",
"progress-preparing-model": "正在準備模型",
"progress-saving": "儲存中",
"progress-search": "找尋檔案中",
"progress-starting": "正在開始",
Expand Down Expand Up @@ -334,6 +335,7 @@
"single-tab-output-header-end": "結束",
"single-tab-output-header-sci-name": "學名",
"single-tab-output-header-start": "開始",
"single-tab-results-truncated-warning": "僅顯示 {total} 筆偵測結果中分數最高的 {shown} 筆。完整結果請使用下載按鈕。",
"single-tab-select-file-button-label": "選擇音訊檔案",
"single-tab-spectrogram-checkbox-info": "對於長音頻文件可能較慢。",
"single-tab-spectrogram-checkbox-label": "產生頻譜圖",
Expand Down
19 changes: 17 additions & 2 deletions birdnet_analyzer/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def supports_sensitivity(

BirdNET 2.4 and custom classifiers (which run on the 2.4 base) do. BirdNET 3.0
applies the sigmoid inside the model graph, and the birdnet library rejects a
sensitivity other than 1.0 for it. Perch outputs raw logits and is run without a
sigmoid here (its scores are not probabilities), so sensitivity does not apply.
sensitivity other than 1.0 for it. Perch outputs logits that are normalized
with a softmax (not a sigmoid), so sensitivity does not apply.
Newer BirdNET versions are assumed to behave like 3.0 until known otherwise.
"""
if classifier:
Expand All @@ -344,6 +344,20 @@ def effective_sensitivity(
return 1.0


def validate_min_conf(min_conf: float) -> None:
"""Rejects confidence thresholds outside [0, 1).

Every model's scores are normalized to probabilities (sigmoid for BirdNET
and custom classifiers, softmax for Perch), so a threshold of 1 or more
would silently discard every detection.
"""
if not 0 <= min_conf < 1:
raise ValueError(
f"min_conf {min_conf} is out of range: confidence scores are "
"probabilities, so the threshold must lie in [0, 1)."
)


def run_inference(
path,
model="birdnet",
Expand Down Expand Up @@ -433,6 +447,7 @@ def run_inference(
n_workers=n_workers,
n_producers=n_producers,
apply_sigmoid=model != "perch",
apply_softmax=model == "perch",
max_n_files=len(input_files),
on_file_complete=on_file_complete,
) as session:
Expand Down
1 change: 1 addition & 0 deletions docs/implementation-details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Implementation details
implementation-details/training-hyperparameters
implementation-details/segment-collection-mode
implementation-details/sensitivity
implementation-details/resumable-analysis
Loading