Skip to content

Commit b12b16d

Browse files
Josef-HauptCopilot
andauthored
Cc with slist (#827)
* Custom classifier with custom species list * Added species list dataframe to gui * . * i8n * Update tests/analyze/test_analyze.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/analyze/test_analyze.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * timeout???? --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1cb03c5 commit b12b16d

22 files changed

Lines changed: 234 additions & 119 deletions

birdnet_analyzer/analyze/core.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,28 +242,26 @@ def _set_params(
242242
if overlap >= cfg.SIG_LENGTH:
243243
raise ValueError(f"Overlap must be less than {cfg.SIG_LENGTH} seconds.")
244244

245-
# Custom classifier trained with the Analyzer, not arbitrary models, meaning; A a tflite model or B a raven model
246-
if custom_classifier is None:
247-
# TODO: does species list even make sense with Perch?
248-
cfg.LATITUDE, cfg.LONGITUDE, cfg.WEEK = lat, lon, week
249-
cfg.CUSTOM_CLASSIFIER = None
250-
251-
if cfg.LATITUDE == -1 and cfg.LONGITUDE == -1:
252-
if not slist:
253-
cfg.SPECIES_LIST_FILE = None
254-
else:
255-
cfg.SPECIES_LIST_FILE = slist
256-
257-
if os.path.isdir(cfg.SPECIES_LIST_FILE):
258-
cfg.SPECIES_LIST_FILE = os.path.join(cfg.SPECIES_LIST_FILE, "species_list.txt")
245+
cfg.CUSTOM_CLASSIFIER = custom_classifier # we treat this as absolute path, so no need to join with dirname
246+
cfg.LATITUDE, cfg.LONGITUDE, cfg.WEEK = lat, lon, week
259247

260-
cfg.SPECIES_LIST = read_lines(cfg.SPECIES_LIST_FILE, trim=True, fail_on_blank_lines=True)
261-
else:
248+
# TODO: Should really be None instead of -1
249+
if cfg.LATITUDE == -1 and cfg.LONGITUDE == -1:
250+
if not slist:
262251
cfg.SPECIES_LIST_FILE = None
263-
cfg.SPECIES_LIST = get_species_list(cfg.LATITUDE, cfg.LONGITUDE, cfg.WEEK, cfg.LOCATION_FILTER_THRESHOLD)
252+
else:
253+
cfg.SPECIES_LIST_FILE = slist
254+
255+
if os.path.isdir(cfg.SPECIES_LIST_FILE):
256+
cfg.SPECIES_LIST_FILE = os.path.join(cfg.SPECIES_LIST_FILE, "species_list.txt")
257+
258+
cfg.SPECIES_LIST = read_lines(cfg.SPECIES_LIST_FILE, trim=True, fail_on_blank_lines=True)
264259
else:
265-
cfg.CUSTOM_CLASSIFIER = custom_classifier # we treat this as absolute path, so no need to join with dirname
260+
# TODO: What if only one of the two is given?
261+
cfg.SPECIES_LIST_FILE = None
262+
cfg.SPECIES_LIST = get_species_list(cfg.LATITUDE, cfg.LONGITUDE, cfg.WEEK, cfg.LOCATION_FILTER_THRESHOLD)
266263

264+
if custom_classifier:
267265
if custom_classifier.endswith(".tflite"):
268266
cfg.LABELS_FILE = custom_classifier.replace(".tflite", "_Labels.txt") # same for labels file
269267

birdnet_analyzer/gui/analysis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def run_analysis(
5252
week: int,
5353
use_yearlong: bool,
5454
sf_thresh: float,
55+
selected_model: str,
5556
custom_classifier_file,
5657
output_types: str,
5758
additional_columns: list[str] | None,
@@ -101,8 +102,8 @@ def run_analysis(
101102
from birdnet_analyzer.analyze.core import _set_params
102103

103104
locale = locale.lower()
104-
custom_classifier = custom_classifier_file if species_list_choice == gu._CUSTOM_CLASSIFIER else None
105-
use_perch = species_list_choice == gu._USE_PERCH
105+
custom_classifier = custom_classifier_file if selected_model == gu._CUSTOM_CLASSIFIER else None
106+
use_perch = selected_model == gu._USE_PERCH
106107
slist = species_list_file if species_list_choice == gu._CUSTOM_SPECIES else None
107108
lat = lat if species_list_choice == gu._PREDICT_SPECIES else -1
108109
lon = lon if species_list_choice == gu._PREDICT_SPECIES else -1

birdnet_analyzer/gui/embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def select_file_output_directory_and_update_tb(current):
256256
show_progress="hidden",
257257
)
258258

259-
progress_plot = gr.Plot()
259+
progress_plot = gr.Plot(show_label=False)
260260
start_btn = gr.Button(loc.localize("embeddings-tab-start-button-label"), variant="huggingface")
261261

262262
start_btn.click(

birdnet_analyzer/gui/multi_file.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def run_batch_analysis(
4141
week,
4242
use_yearlong,
4343
sf_thresh,
44+
selected_model,
4445
custom_classifier_file,
4546
output_type,
4647
additional_columns,
@@ -83,6 +84,7 @@ def run_batch_analysis(
8384
week,
8485
use_yearlong,
8586
sf_thresh,
87+
selected_model,
8688
custom_classifier_file,
8789
output_type,
8890
additional_columns,
@@ -146,7 +148,7 @@ def select_directory_wrapper(): # Nishant - Function modified for For Folder se
146148
show_progress="hidden",
147149
)
148150

149-
sample_settings, species_settings = gu.sample_and_species_settings(opened=False)
151+
sample_settings, species_settings, model_settings = gu.sample_species_model_settings(opened=False)
150152

151153
with gr.Accordion(loc.localize("multi-tab-output-accordion-label"), open=True), gr.Group():
152154
output_type_radio = gr.CheckboxGroup(
@@ -220,7 +222,8 @@ def select_directory_wrapper(): # Nishant - Function modified for For Folder se
220222
species_settings["week_number"],
221223
species_settings["yearlong_checkbox"],
222224
species_settings["sf_thresh_number"],
223-
species_settings["selected_classifier_state"],
225+
model_settings["model_selection_radio"],
226+
model_settings["selected_classifier_state"],
224227
output_type_radio,
225228
additional_columns_,
226229
combine_tables_checkbox,

birdnet_analyzer/gui/review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def create_log_plot(positives, negatives, fig_num=None):
142142

143143
with gr.Column() as review_item_col, gr.Row():
144144
with gr.Column(), gr.Group():
145-
spectrogram_image = gr.Plot(label=loc.localize("review-tab-spectrogram-plot-label"), show_label=False)
145+
spectrogram_image = gr.Plot(show_label=False)
146146
spectrogram_dl_btn = gr.Button("Download spectrogram", size="sm")
147147

148148
with gr.Column():

birdnet_analyzer/gui/single_file.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def run_single_file_analysis(
2929
week,
3030
use_yearlong,
3131
sf_thresh,
32+
selected_model,
3233
custom_classifier_file,
3334
locale,
3435
):
@@ -64,6 +65,7 @@ def run_single_file_analysis(
6465
week=week,
6566
use_yearlong=use_yearlong,
6667
sf_thresh=sf_thresh,
68+
selected_model=selected_model,
6769
custom_classifier_file=custom_classifier_file,
6870
output_types="csv",
6971
additional_columns=None,
@@ -113,7 +115,7 @@ def build_single_analysis_tab():
113115
)
114116
audio_path_state = gr.State()
115117
table_path_state = gr.State()
116-
sample_settings, species_settings = gu.sample_and_species_settings(opened=False)
118+
sample_settings, species_settings, model_settings = gu.sample_species_model_settings(opened=False)
117119
locale_radio = gu.locale()
118120

119121
single_file_analyze = gr.Button(loc.localize("analyze-start-button-label"), variant="huggingface", interactive=False)
@@ -195,7 +197,8 @@ def try_generate_spectrogram(audio_path, generate_spectrogram):
195197
species_settings["week_number"],
196198
species_settings["yearlong_checkbox"],
197199
species_settings["sf_thresh_number"],
198-
species_settings["selected_classifier_state"],
200+
model_settings["model_selection_radio"],
201+
model_settings["selected_classifier_state"],
199202
locale_radio,
200203
]
201204

birdnet_analyzer/gui/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def on_autotune_change(value):
597597
info=loc.localize("training-tab-model-save-mode-radio-info"),
598598
)
599599

600-
train_history_plot = gr.Plot()
600+
train_history_plot = gr.Plot(show_label=False)
601601
metrics_table = gr.Dataframe(
602602
headers=["Class", "Precision", "Recall", "F1 Score", "AUPRC", "AUROC", "Samples"],
603603
visible=False,

0 commit comments

Comments
 (0)