Skip to content

Commit cf5925e

Browse files
Sensitivity test (#765)
* small sanity check for the sensitivity setting, needs some cleanup * cleaned up the test and added docu + demo for sensitivity * ruff fix
1 parent b56bb11 commit cf5925e

5 files changed

Lines changed: 3947 additions & 2 deletions

File tree

docs/_static/birdnet_sigmoid_sensitivity_old_vs_new.html

Lines changed: 3885 additions & 0 deletions
Large diffs are not rendered by default.

docs/implementation-details.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Implementation details
44
.. toctree::
55
:maxdepth: 1
66

7-
implementation-details/crop-modes
7+
implementation-details/crop-modes
8+
implementation-details/sensitivity
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Sensitivity
2+
===============================
3+
4+
Starting with version 2.0.0, the BirdNET-Analyzer uses a new sensitivity implementation.
5+
Our goal with this change is to make the sensitivity more intuitive by changing it so that higher sensitivity values always lead to higher confidence scores.
6+
7+
Comparison to the previous implementation
8+
--------------------------------------------------------
9+
10+
Where the old implementation changed the slope of the sigmoid function, the new implementation performs a shift of the function.
11+
12+
We have a little demo where you can explore the behavior of the old and the new sensitivity implementations `here <../_static/birdnet_sigmoid_sensitivity_old_vs_new.html>`_.

tests/analyze/test_analyze.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,50 @@ def test_analyze_with_additional_columns(mock_ensure_model, setup_test_environme
426426
assert float(row["sensitivity"]) == cfg.SIGMOID_SENSITIVITY, "Sensitivity value does not match expected value"
427427
assert row["species_list"] == "", "Species list value does not match expected value"
428428
assert float(row["min_conf"]) == 0, "Min confidence value does not match expected value"
429+
430+
def test_sensitivity(setup_test_environment):
431+
"""Test sensitivity setting."""
432+
env = setup_test_environment
433+
434+
soundscape_path = "birdnet_analyzer/example/soundscape.wav"
435+
436+
assert os.path.exists(soundscape_path), "Soundscape file does not exist"
437+
438+
normal_sensitivity_result = {}
439+
low_sensitivity_result = {}
440+
high_sensitivity_result = {}
441+
442+
# Call function under test
443+
analyze(soundscape_path, env["output_dir"], top_n=1)
444+
output_file = os.path.join(env["output_dir"], "soundscape.BirdNET.selection.table.txt")
445+
assert os.path.exists(output_file)
446+
447+
def extract_confidence_from_output(output_file, result_dict):
448+
with open(output_file) as f:
449+
lines = f.readlines()[1:]
450+
for line in lines:
451+
parts = line.strip().split("\t")
452+
start = float(parts[3])
453+
end = float(parts[4])
454+
confidence = float(parts[9])
455+
result_dict[(start, end)] = confidence
456+
457+
extract_confidence_from_output(output_file, normal_sensitivity_result)
458+
459+
analyze(soundscape_path, env["output_dir"], top_n=1, sensitivity=0.75)
460+
output_file = os.path.join(env["output_dir"], "soundscape.BirdNET.selection.table.txt")
461+
assert os.path.exists(output_file)
462+
463+
extract_confidence_from_output(output_file, low_sensitivity_result)
464+
465+
analyze(soundscape_path, env["output_dir"], top_n=1, sensitivity=1.25)
466+
output_file = os.path.join(env["output_dir"], "soundscape.BirdNET.selection.table.txt")
467+
assert os.path.exists(output_file)
468+
469+
extract_confidence_from_output(output_file, high_sensitivity_result)
470+
471+
for key in normal_sensitivity_result:
472+
assert key in low_sensitivity_result, "Low sensitivity result missing key from normal sensitivity result"
473+
assert key in high_sensitivity_result, "High sensitivity result missing key from normal sensitivity result"
474+
assert low_sensitivity_result[key] <= normal_sensitivity_result[key], "Low sensitivity confidence should be less than or equal to normal sensitivity"
475+
assert high_sensitivity_result[key] >= normal_sensitivity_result[key], "High sensitivity confidence should be greater than or equal to normal sensitivity"

0 commit comments

Comments
 (0)