Skip to content

Commit a968ab6

Browse files
authored
actual handwritten guide (#733)
* actual handwritten guide * removed old script calls from docu * thanks copilot
1 parent 26085c1 commit a968ab6

5 files changed

Lines changed: 87 additions & 52 deletions

File tree

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(",")

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

docs/usage/cli.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ birdnet_analyzer.analyze
1010
:ref: birdnet_analyzer.cli.analyzer_parser
1111
:prog: birdnet_analyzer.analyze
1212

13-
Run ``analyzer.py`` to analyze an audio file.
13+
Run ``birdnet_analyzer.analyze`` to analyze an audio file or a directory containing audio files.
1414
You need to set paths for the audio file and selection table output. Here is an example:
1515

1616
.. code:: bash
@@ -42,7 +42,7 @@ birdnet_analyzer.embeddings
4242
:ref: birdnet_analyzer.cli.embeddings_parser
4343
:prog: birdnet_analyzer.embeddings
4444

45-
Run ``embeddings.py`` to extract feature embeddings instead of class predictions.
45+
Run ``birdnet_analyzer.embeddings`` to extract feature embeddings instead of class predictions.
4646
Result file will contain timestamps and lists of float values representing the embedding for a particular 3-second segment.
4747
Embeddings can be used for clustering or similarity analysis. Here is an example:
4848

@@ -59,7 +59,7 @@ birdnet_analyzer.segments
5959
:ref: birdnet_analyzer.cli.segments_parser
6060
:prog: birdnet_analyzer.segments
6161

62-
After the analysis, run ``segments.py`` to extract short audio segments for species detections to verify results.
62+
After the analysis, run ``birdnet_analyzer.segments`` to extract short audio segments for species detections to verify results.
6363
This way, it might be easier to review results instead of loading hundreds of result files manually.
6464

6565
.. _cli-species:
@@ -88,15 +88,15 @@ birdnet_analyzer.server
8888
Install one additional package with ``pip install bottle``.
8989

9090
Start the server with ``python -m birdnet_analyzer.server``.
91-
You can also specify a host name or IP and port number, e.g., ``python -m birdnet_analayzer.server --host localhost --port 8080``.
91+
You can also specify a host name or IP and port number, e.g., ``python -m birdnet_analyzer.server --host localhost --port 8080``.
9292

9393
The server is single-threaded, so you’ll need to start multiple instances for higher throughput. This service is intented for short audio files (e.g., 1-10 seconds).
9494

9595
Query the API with a client.
9696
You can use the provided Python client or any other client implementation.
9797
Request payload needs to be ``multipart/form-data`` with the following fields:
9898
``audio`` for raw audio data as byte code, and ``meta`` for additional information on the audio file.
99-
Take a look at our example client implementation in the ``client.py`` script.
99+
Take a look at our example client implementation in the ``birdnet_analyzer.client`` script.
100100

101101
Parse results from the server. The server will send back a JSON response with the detection results. The response also contains a msg field, indicating success or error. Results consist of a sorted list of (species, score) tuples.
102102

@@ -156,7 +156,7 @@ birdnet_analyzer.train
156156

157157
**The script saves the trained classifier model based on the best validation loss achieved during training. This ensures that the model saved is optimized for performance according to the chosen metric.**
158158

159-
After training, you can use the custom trained classifier with the ``--classifier`` argument of the ``analyze.py`` script.
159+
After training, you can use the custom trained classifier with the ``--classifier`` argument of the ``birdnet_analyzer.analyze`` script.
160160
If you want to use the custom classifier in Raven, make sure to set ``--model_format raven``.
161161

162162
.. note::

docs/usage/gui.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This can help you to choose an appropriate cut-off threshold for your specific u
2828

2929
General workflow:
3030

31-
1. Use the **Segments** tab in the GUI or the :ref:`segments.py <cli-segments>` script to extract short audio segments for species detections.
31+
1. Use the **Segments** tab in the GUI or the :ref:`birdnet_analyzer.segments <cli-segments>` script to extract short audio segments for species detections.
3232
2. Open the **Review** tab in the GUI and select the parent directory containing the directories for all the species you want to review.
3333
3. Review the segments and manually check "positive" if the segment does contain target species or "negative" if it does not.
3434

0 commit comments

Comments
 (0)