Skip to content

Commit b36e6ed

Browse files
committed
Merge branch 'main' into segments-collection-mode
2 parents fe1725b + a968ab6 commit b36e6ed

13 files changed

Lines changed: 112 additions & 71 deletions

File tree

birdnet_analyzer/analyze/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ def combine_kaleidoscope_files(saved_results: list[str]):
365365
continue
366366

367367
# skip header and add to file
368-
for line in lines[1:]:
369-
f.write(line)
368+
f.writelines(lines[1:])
370369

371370
except Exception as ex:
372371
print(f"Error: Cannot combine results from {rfile}.\n", flush=True)
@@ -545,13 +544,12 @@ def iterate_audio_chunks(fpath: str, embeddings: bool = False):
545544
break
546545

547546
for chunk_index, chunk in enumerate(chunks):
547+
t_start = start + (chunk_index * (cfg.SIG_LENGTH - cfg.SIG_OVERLAP) * cfg.AUDIO_SPEED)
548+
end = min(t_start + cfg.SIG_LENGTH * cfg.AUDIO_SPEED, fileLengthSeconds)
549+
548550
# Add to batch
549551
samples.append(chunk)
550-
timestamps.append([round(start, 1), round(end, 1)])
551-
552-
# Advance start and end
553-
start += (cfg.SIG_LENGTH - cfg.SIG_OVERLAP) * cfg.AUDIO_SPEED
554-
end = min(start + cfg.SIG_LENGTH * cfg.AUDIO_SPEED, fileLengthSeconds)
552+
timestamps.append([round(t_start, 2), round(end, 2)])
555553

556554
# Check if batch is full or last chunk
557555
if len(samples) < cfg.BATCH_SIZE and chunk_index < len(chunks) - 1:
@@ -571,6 +569,8 @@ def iterate_audio_chunks(fpath: str, embeddings: bool = False):
571569
samples = []
572570
timestamps = []
573571

572+
start += len(chunks) * (cfg.SIG_LENGTH - cfg.SIG_OVERLAP) * cfg.AUDIO_SPEED
573+
574574

575575
def predict(samples):
576576
"""Predicts the classes for the given samples.

birdnet_analyzer/gui/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def select_directory_on_empty(): # Nishant - Function modified for For Folder s
379379

380380
if folder:
381381
files = get_selection_tables(folder)
382-
files_to_display = files[:100] + [["..."]] if len(files) > 100 else files
382+
files_to_display = [*files[:100], ["..."]] if len(files) > 100 else files
383383
return [files, files_to_display, gr.update(visible=True), *on_select(files)]
384384

385385
return ["", [[loc.localize("eval-tab-no-files-found")]]]

birdnet_analyzer/gui/multi_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def select_directory_on_empty(): # Nishant - Function modified for For Folder s
119119
if folder:
120120
files_and_durations = gu.get_audio_files_and_durations(folder)
121121
if len(files_and_durations) > 100:
122-
return [folder, files_and_durations[:100] + [["..."]]] # hopefully fixes issue#272
122+
return [folder, *files_and_durations[:100], ["..."]] # hopefully fixes issue#272
123123
return [folder, files_and_durations]
124124

125125
return ["", [[loc.localize("multi-tab-samples-dataframe-no-files-found")]]]

birdnet_analyzer/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,7 @@ def save_linear_classifier(classifier, model_path: str, labels: list[str], mode=
872872

873873
# Save labels
874874
with open(model_path.replace(".tflite", "_Labels.txt"), "w", encoding="utf-8") as f:
875-
for label in labels:
876-
f.write(label + "\n")
875+
f.writelines(label + "\n" for label in labels)
877876

878877
save_model_params(model_path.replace(".tflite", "_Params.csv"))
879878

birdnet_analyzer/species/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,4 @@ def run(output_path, lat, lon, week, threshold, sortby):
7070

7171
# Save species list
7272
with open(cfg.OUTPUT_PATH, "w") as f:
73-
for s in species_list:
74-
f.write(s + "\n")
73+
f.writelines(s + "\n" for s in species_list)

birdnet_analyzer/train/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def _load_audio_file(f, label_vector, config):
6363
# Load audio
6464
sig, rate = audio.open_audio_file(
6565
f,
66+
sample_rate=cfg.SAMPLE_RATE,
6667
duration=cfg.SIG_LENGTH if cfg.SAMPLE_CROP_MODE == "first" else None,
6768
fmin=cfg.BANDPASS_FMIN,
6869
fmax=cfg.BANDPASS_FMAX,
@@ -136,7 +137,7 @@ def _load_training_data(cache_mode=None, cache_file="", progress_callback=None):
136137
train_folders = sorted(utils.list_subdirectories(cfg.TRAIN_DATA_PATH))
137138

138139
# Read all individual labels from the folder names
139-
labels = []
140+
labels: list[str] = []
140141

141142
for folder in train_folders:
142143
labels_in_folder = folder.split(",")

birdnet_analyzer/translate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def save_labels_file(labels: list[str], locale: str):
119119
cfg.TRANSLATED_LABELS_PATH, "{}_{}.txt".format(os.path.basename(cfg.LABELS_FILE).rsplit(".", 1)[0], locale)
120120
)
121121
with open(fpath, "w", encoding="utf-8") as f:
122-
for label in labels:
123-
f.write(label + "\n")
122+
f.writelines(label + "\n" for label in labels)
124123

125124

126125
if __name__ == "__main__":

docs/best-practices/segment-review.rst

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Segment Review
2-
=================================
2+
==============
33

4-
Get started by listening to this AI-generated summary of segments review:
4+
This document provides a quick overview of the segment review process in BirdNET-Analyzer, which is essential for validating species detection results.
5+
You can also listen to an AI-generated summary of this guide in the audio player below.
56

67
.. raw:: html
78

@@ -13,64 +14,97 @@ Get started by listening to this AI-generated summary of segments review:
1314
|
1415
| `Source: Google NotebookLM`
1516
16-
1. Prepare Audio and Result Files
17-
---------------------------------
17+
Prepare Audio and Result Files
18+
------------------------------
1819

19-
- | **Collect Audio Recordings and Corresponding BirdNET Result Files**: Organize them into separate folders.
20-
- | **Result File Formats**: BirdNET-Analyzer typically produces result files with extensions ".BirdNET.txt" or ".BirdNET.csv". It can process various result file formats, including "table", "kaleidoscope", "csv", and "audacity".
21-
- | **Understanding Confidence Values**: Note that BirdNET confidence values are not probabilities and are not directly transferable between different species or recording conditions.
20+
The BirdNET Analyzer uses the batch analysis result tables, such as the output formats "table", "kaleidoscope" or "csv".
21+
To obtain batch analysis result tables, run the analysis via the GUI or the :ref:`command line <cli-docs>`, which automatically generates the result files.
2222

23-
2. Using the "Segments" Function in the GUI or Command Line
24-
-----------------------------------------------------------
23+
.. warning::
2524

26-
- | **Segments Function**: BirdNET provides the "segments" function to create a collection of species-specific predictions that exceed a user-defined confidence value. This function is available in the graphical user interface (GUI) under the "segments" tab or via the "segments.py" script in the command line.
27-
- | **GUI Usage**: In the GUI, you can select audio, result, and output directories. You can also set additional parameters such as the minimum confidence value, the maximum number of segments per species, the audio speed, and the segment length.
25+
The output format "audacity" is not supported for the segments tool since it is missing certain columns. Use "table", "kaleidoscope", or "csv" formats instead.
2826

29-
3. Setting Parameters
30-
---------------------
27+
Using the "Segments" Tool in the GUI or Command Line
28+
-----------------------------------------------------
3129

32-
- | **Minimum Confidence (min_conf)**: Set a minimum confidence value for predictions to be considered. Note that this value may vary by species. It is recommended to determine the threshold by reviewing precision and recall.
33-
- | **Maximum Number of Segments (num_seq)**: Specify how many segments per species should be extracted.
34-
- | **Audio Speed (audio_speed)**: Adjust the playback speed. Extracted segments will be saved with the adjusted speed (e.g., to listen to ultrsonic calls).
35-
- | **Segment Length (seq_length)**: Define how long the extracted audio segments should be. If you set to more than 3 seconds, each segment will be padded with audio from the source recording. For example, for 5-second segment length, 1 second of audio before and after each extracted segment will be included. For 7 seconds, 2 seconds will be included, and so on. The first and last segment of each audio file might be shorter than the specified length.
30+
The BirdNET Analyzer provides the "segments" tool to extract short audio segments from the result files and place them into separate species-specific folders.
31+
This tool is available in the graphical user interface (GUI) under the "segments" tab or via the :ref:`birdnet_analyzer.segments <cli-segments>` script in the command line.
3632

37-
4. Extracting Segments
38-
----------------------
33+
Setting Parameters
34+
------------------
35+
36+
The GUI and command line tool allow you to set various parameters to customize the segment extraction process:
37+
38+
* **Minimum Confidence** (``min_conf``): Set a minimum confidence value for predictions to be considered. It is recommended to determine the threshold by reviewing precision and recall.
39+
* **Maximum Number of Segments** (``num_seq``): Specify how many segments per species should be extracted.
40+
* **Audio Speed** (``audio_speed``): Adjust the playback speed. Extracted segments will be saved with the adjusted speed (e.g., to listen to ultrasonic calls).
41+
* **Segment Length** (``seq_length``): Define how long the extracted audio segments should be. If you set to more than 3 seconds, each segment will be padded with audio from the source recording. For example, for 5-second segment length, 1 second of audio before and after each extracted segment will be included. For 7 seconds, 2 seconds will be included, and so on. The first and last segment of each audio file might be shorter than the specified length.
42+
43+
.. note::
44+
45+
The desired minimum confidence value can be different for each species.
46+
47+
Extracting Segments
48+
-------------------
49+
50+
After setting all parameters, start the extraction process. BirdNET will create subfolders for each identified species and save audio clips of the corresponding recordings.
51+
The progress of the process will be displayed.
52+
The resulting audio segments will be saved in the following format:
53+
54+
.. code-block::
55+
56+
{c}_{i}_{fname}_{start}s_{end}s.wav
3957
40-
- | **Start the Extraction Process**: After setting all parameters, start the extraction process. BirdNET will create subfolders for each identified species and save audio clips of the corresponding recordings.
41-
- | **Progress Display**: The progress of the process will be displayed.
58+
where:
4259

43-
5. Reviewing Results
44-
--------------------
60+
* ``{c}``: confidence value of the prediction (e.g., 0.835)
61+
* ``{i}``: index of the segment inside the file
62+
* ``{fname}``: name of the original audio file without the extension
63+
* ``{start}``: start time of the segment inside the file in seconds
64+
* ``{end}``: end time of the segment inside the file in seconds
4565

46-
- | **Manual Review of Audio Segments**: The resulting audio segments can be manually reviewed to assess the accuracy of the predictions. It is important to note that BirdNET confidence values are not probabilities but a measure of the algorithm's prediction reliability.
47-
- | **Systematic Review**: It is recommended to start with the highest confidence scores and work down to the lower scores.
48-
- | **File Naming**: Files are named with confidence values, allowing for sorting by values.
4966

50-
6. Using the Review Tab in the GUI
67+
Using the Review Tab in the GUI
5168
----------------------------------
5269

53-
- | **Review Tab Overview**: The review tab in the GUI allows you to systematically review and label the extracted segments. It provides tools for visualizing spectrograms, listening to audio segments, and categorizing them as positive or negative detections.
54-
- | **Collect Segments**: Use the review tab to collect segments from the specified directory. You can shuffle the segments for a randomized review process.
55-
- | **Create Log Plot**: The review tab can generate a logistic regression plot to visualize the relationship between confidence values and the likelihood of correct detections.
56-
- **Review Process**:
70+
The resulting audio segments can be manually reviewed to assess the accuracy of the predictions.
71+
It is important to note that BirdNET *confidence values are not probabilities* but a measure of the algorithm's prediction reliability.
72+
We recommended to start with the highest confidence scores and work down to the lower scores.
5773

58-
- | **Select Directory**: Choose the directory containing the segments to be reviewed.
59-
- | **Species Dropdown**: Select the species to review from the dropdown menu.
60-
- | **File Count Matrix**: View the count of files to be reviewed, positive detections, and negative detections.
61-
- | **Spectrogram and Audio**: Visualize the spectrogram and listen to the audio segment.
62-
- | **Label Segments**: Use the buttons to label segments as positive or negative detections. You can also use the left and right arrow keys to assign labels.
63-
- | **Undo**: Undo the last action if needed.
64-
- | **Download Plots**: Download the spectrogram and regression plots for further analysis.
74+
The review tab in the GUI allows you to systematically review and label the extracted segments.
75+
It provides tools for visualizing spectrograms, listening to audio segments, and categorizing them as positive or negative detections.
76+
The review tab can generate a logistic regression plot to visualize the relationship between confidence values and the likelihood of correct detections.
6577

66-
7. Alternative Approaches
67-
-------------------------
78+
In the GUI select the "Review" tab and select the segments directory you want to review.
79+
You can now either select the parent directory containing all the different species subfolders or a specific species subfolder to review.
80+
If you select the parent directory, the GUI will automatically select the first species subfolder, but you can switch between species via a dropdown menu.
81+
82+
Depending on your selection the segments will be shuffled or sorted by confidence value.
83+
Each segment will be displayed with an audio player and its spectrogram.
84+
After listening to a segment, you can either mark it as a positive detection (if you hear the species) or a negative detection (if you do not hear the species).
85+
The BirdNET Analyzer will create two directories: one for positive detections and one for negative detections, and move the marked segments accordingly.
86+
The "Undo" button allows you to revert the last action if needed.
87+
88+
.. note::
89+
90+
You can also use the up (positive) and down (negative) arrow keys to assign labels. The left arrow key will undo the last action and the right arrow key will skip to the next segment without labeling it.
91+
92+
With the number of segments reviewed, the GUI will also display a logistic regression plot.
93+
This plot shows the relationship between the confidence values and the likelihood of correct detections.
94+
All of the plots including the spectrogram can be downloaded as PNG files for further analysis or documentation.
95+
96+
.. note::
97+
98+
The review tab can be used on any directory containing audio files, not just those created by the segments tool. This allows you to review any set of audio files, including those from other sources.
99+
100+
Alternative Approaches
101+
----------------------
68102

69103
- | **Raven Pro**: BirdNET result tables can be imported into Raven Pro and reviewed using the selection review function.
70104
- | **Converting Confidence Values to Probabilities**: Another approach is converting confidence values to probabilities using logistic regression in R. However, this still requires manual evaluation of predictions.
71105

72-
8. Important Notes
73-
------------------
106+
Important Notes
107+
---------------
74108

75109
- | **Non-Transferability of Confidence Values**: BirdNET confidence values are not easily transferable between species.
76110
- | **Audio Quality**: The accuracy of results heavily depends on the quality of audio recordings, such as sample rate and microphone quality.

docs/best-practices/species-lists.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can find label files in the checkpoints folder, e.g., `checkpoints/V2.4/Bird
77

88
Species names need to consist of `scientific name_common name` to be valid.
99

10-
You can generate a species list for a given location using :ref:`species.py <cli-species>`.
10+
You can generate a species list for a given location using :ref:`birdnet_analyzer.species <cli-species>`.
1111

1212
Practical Information and Considerations
1313
----------------------------------------
@@ -29,7 +29,7 @@ In cases where eBird does not have enough observations (i.e., checklists), the d
2929
If you know which species to expect in your area, it is recommended to compile your own species list. This can help improve the accuracy of BirdNET-Analyzer for your specific use case.
3030

3131
1. **Collect Species Names**: Use the labels file from the model checkpoints to get the correct species names. Ensure the names are in the format `scientific name_common name`.
32-
2. **Generate Species List**: Use the `species.py` script to generate a species list for a given location and time. This script uses the GeoModel to predict species occurrence based on latitude, longitude, and week of the year.
32+
2. **Generate Species List**: Use the `birdnet_analyzer.species` script to generate a species list for a given location and time. This script uses the GeoModel to predict species occurrence based on latitude, longitude, and week of the year.
3333

3434
**Example of Training Data**
3535

0 commit comments

Comments
 (0)