Skip to content

Commit d31af6e

Browse files
authored
fixed bug that saves faulty custom classifier if 'both' was selected (#783)
1 parent 45e997d commit d31af6e

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

birdnet_analyzer/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def _focal_loss(y_true, y_pred):
816816
return classifier, history
817817

818818

819-
def save_linear_classifier(classifier, model_path: str, labels: list[str], mode="replace"):
819+
def save_linear_classifier(classifier, model_path: str, labels: list[str], mode="replace", pop_last_layer=True):
820820
"""Saves the classifier as a tflite model, as well as the used labels in a .txt.
821821
822822
Args:
@@ -836,7 +836,8 @@ def save_linear_classifier(classifier, model_path: str, labels: list[str], mode=
836836
saved_model = PBMODEL
837837

838838
# Remove activation layer
839-
classifier.pop()
839+
if pop_last_layer:
840+
classifier.pop()
840841

841842
if mode == "replace":
842843
combined_model = tf.keras.Sequential([saved_model.embeddings_model, classifier], "basic")

birdnet_analyzer/train/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def run_trial(self, trial, *args, **kwargs):
573573
try:
574574
if cfg.TRAINED_MODEL_OUTPUT_FORMAT == "both":
575575
model.save_raven_model(classifier, cfg.CUSTOM_CLASSIFIER, labels, mode=cfg.TRAINED_MODEL_SAVE_MODE)
576-
model.save_linear_classifier(classifier, cfg.CUSTOM_CLASSIFIER, labels, mode=cfg.TRAINED_MODEL_SAVE_MODE)
576+
model.save_linear_classifier(classifier, cfg.CUSTOM_CLASSIFIER, labels, mode=cfg.TRAINED_MODEL_SAVE_MODE, pop_last_layer=False)
577577
elif cfg.TRAINED_MODEL_OUTPUT_FORMAT == "tflite":
578578
model.save_linear_classifier(classifier, cfg.CUSTOM_CLASSIFIER, labels, mode=cfg.TRAINED_MODEL_SAVE_MODE)
579579
elif cfg.TRAINED_MODEL_OUTPUT_FORMAT == "raven":

0 commit comments

Comments
 (0)