Skip to content

Commit

Permalink
updated usage of older models (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Haupt authored Jan 21, 2025
1 parent d4402cd commit 7490991
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions birdnet_analyzer/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,10 @@ def __call__(self, parser, args, values, option_string=None):

if args.classifier.endswith(".tflite"):
cfg.LABELS_FILE = args.classifier.replace(".tflite", "_Labels.txt") # same for labels file

if not os.path.isfile(cfg.LABELS_FILE):
cfg.LABELS_FILE = args.classifier.replace("Model_FP32.tflite", "Labels.txt")

cfg.LABELS = utils.readLines(cfg.LABELS_FILE)
else:
cfg.APPLY_SIGMOID = False
Expand Down
10 changes: 4 additions & 6 deletions birdnet_analyzer/checkpoints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

This repository contains only the latest version of the BirdNET-Analyzer model. We will track the changes in this document and also provide permanent download links to previous versions for testing and/or other use cases.

You can download and unzip previous model versions, make sure to update the `MODEL_PATH` and `LABELS_FILE` variable in the `config.py` file to the version you want to use.
Older models can also be used as custom classifiers in the GUI or using the `--classifier` argument in the `birdnet_analyzer.analyze` command line.

Older models can also be used as custom classifiers in the GUI.

To do this download und unzip the model version you wish to use, then copy the model variant (e.g. FP32) and the labels file into a separate folder.
Then rename the labels file to match the name of the model file + "_Labels" (e.g. "model.tflite" and "model_Labels.txt").
After that you can select the model as a custom classifier in the GUI.
Just download your desired model version and unzip.
GUI: Select the `*_Model_FP32.tflite` file under **Species selection** > **Custom classifier**
CLI: `python -m birdnet_analyzer ... --classifier <path_to_*_Model_FP32.tflite>`

Model update history:

Expand Down
4 changes: 4 additions & 0 deletions birdnet_analyzer/gui/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def runAnalysis(
custom_classifier_file # we treat this as absolute path, so no need to join with dirname
)
cfg.LABELS_FILE = custom_classifier_file.replace(".tflite", "_Labels.txt") # same for labels file

if not os.path.isfile(cfg.LABELS_FILE):
cfg.LABELS_FILE = custom_classifier_file.replace("Model_FP32.tflite", "Labels.txt")

cfg.LABELS = utils.readLines(cfg.LABELS_FILE)
cfg.LATITUDE = -1
cfg.LONGITUDE = -1
Expand Down
3 changes: 3 additions & 0 deletions birdnet_analyzer/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ def on_custom_classifier_selection_click():
if file:
labels = os.path.splitext(file)[0] + "_Labels.txt"

if not os.path.isfile(labels):
labels = file.replace("Model_FP32.tflite", "Labels.txt")

return file, gr.File(value=[file, labels], visible=True)

return None, None
Expand Down

0 comments on commit 7490991

Please sign in to comment.