From ca3f9620654cd90ccce22e38046017205cbc341b Mon Sep 17 00:00:00 2001 From: Josef Haupt Date: Fri, 18 Oct 2024 16:04:44 +0200 Subject: [PATCH] incorporation of #465 --- birdnet_analyzer/analyze.py | 2 +- birdnet_analyzer/gui/analysis.py | 3 +++ birdnet_analyzer/model.py | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/birdnet_analyzer/analyze.py b/birdnet_analyzer/analyze.py index 2146c0fb..c8899926 100644 --- a/birdnet_analyzer/analyze.py +++ b/birdnet_analyzer/analyze.py @@ -519,7 +519,7 @@ def analyzeFile(item): pred = p[i] # Assign scores to labels - p_labels = zip(cfg.LABELS, pred) + p_labels = zip(cfg.LABELS, pred, strict=True) # Sort by score p_sorted = sorted(p_labels, key=operator.itemgetter(1), reverse=True) diff --git a/birdnet_analyzer/gui/analysis.py b/birdnet_analyzer/gui/analysis.py index 90c514c8..486f4be8 100644 --- a/birdnet_analyzer/gui/analysis.py +++ b/birdnet_analyzer/gui/analysis.py @@ -5,6 +5,7 @@ import gradio as gr import birdnet_analyzer.analyze as analyze +import birdnet_analyzer.model as model import birdnet_analyzer.config as cfg import birdnet_analyzer.localization as loc import birdnet_analyzer.utils as utils @@ -100,6 +101,8 @@ def runAnalysis( if custom_classifier_file is None: raise gr.Error(loc.localize("validation-no-custom-classifier-selected")) + model.resetCustomClassifier() + # Set custom classifier? cfg.CUSTOM_CLASSIFIER = ( custom_classifier_file # we treat this as absolute path, so no need to join with dirname diff --git a/birdnet_analyzer/model.py b/birdnet_analyzer/model.py index e695585b..b4bbf648 100644 --- a/birdnet_analyzer/model.py +++ b/birdnet_analyzer/model.py @@ -35,6 +35,14 @@ C_PBMODEL = None +def resetCustomClassifier(): + global C_INTERPRETER + global C_PBMODEL + + C_INTERPRETER = None + C_PBMODEL = None + + def loadModel(class_output=True): """Initializes the BirdNET Model.