joeweiss / birdnetlib

A python api for BirdNET-Lite and BirdNET-Analyzer
https://joeweiss.github.io/birdnetlib/
Apache License 2.0
41 stars 14 forks source link

Crash when instantiating Analyzer() (from 0.14.0) #109

Closed jaro-kunzelmann closed 2 months ago

jaro-kunzelmann commented 7 months ago

Hello!

First of all, thank you very much for this great project!

Description I am encountering an issue in versions 0.14 and 0.15. I tested with versions 0.8, 0.10, and 0.13.2 and there, the error didn't happen.

When I create an Analyzer object as follows...

from birdnetlib.analyzer import Analyzer
analyzer = Analyzer()

...I get the following output:

Labels loaded.
load model True
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Model loaded.
Labels loaded.
load_species_list_model
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jaro\AppData\Local\mambaforge\envs\EA2\lib\site-packages\birdnetlib\analyzer.py", line 127, in __init__
    self.species_class = SpeciesList()
  File "C:\Users\jaro\AppData\Local\mambaforge\envs\EA2\lib\site-packages\birdnetlib\species.py", line 40, in __init__
    self.load_species_list_model()
  File "C:\Users\jaro\AppData\Local\mambaforge\envs\EA2\lib\site-packages\birdnetlib\species.py", line 107, in load_species_list_model
    self.meta_interpreter.allocate_tensors()
  File "C:\Users\jaro\AppData\Local\mambaforge\envs\EA2\lib\site-packages\tensorflow\lite\python\interpreter.py", line 513, in allocate_tensors
    return self._interpreter.AllocateTensors()
ValueError: vector too long

Note: "EA2" is my mamba environment.

System Windows 10 Python 3.9.15 (via conda/mamba) I installed BirdNET requirements (Tensorflow, Librosa, NumPy, FFmpeg etc., as per BirdNET-Analyzer github page) via conda/mamba

What I tried I tried to track down the problem and installed previous versions of birdnetlib. It seems the problem occurs starting from version 0.14.0. In this version a new metadata species model was added (BirdNET_GLOBAL_6K_V2.4_MData_Model_V2_FP16.tflite). As far as I understand it, when Analyzer is initialized, it tries to load this model (when instantiating SpeciesList), which for some reason then causes the this vector too long error when allocating tensors.

For now I will just stick to version 0.13.2, as I don't need the metadata species model at the moment. Let me know if I can assist you with further info and thank you very much for looking into it.

Cheers, Jaro

joeweiss commented 7 months ago

Hi @jaro-kunzelmann, thanks for the kind words, and for opening this issue.

Which version of tensorflow do you have installed in your Mamba environment? I'd like to try to replicate the crash here with your exact version.

Thanks!

jaro-kunzelmann commented 7 months ago

I'm using tensorflow 2.10.0.

I also attached a full requirements file (with birdnetlib 0.14.0, the version starting from which the crash is caused). requirements.txt

Thank you for looking into this!

jaro-kunzelmann commented 2 months ago

Dear @joeweiss,

I just set up a new Python environment and freshly installed all dependencies (as per the documents). birdnetlib works fine now. I'm not sure what caused the error in the first place.

requirements.txt

Thanks for your work!

joeweiss commented 2 months ago

Hi @jaro-kunzelmann,

Thanks for the follow-up. I wasn't able to track down a cause, or replicate the crash on my machines.

I'm glad to hear that it is working now.

jaro-kunzelmann commented 2 months ago

The problem might have been caused by some incompatible libraries, since I installed some with mamba and some with pip (which is not recommended...). Anyhow, installing everything with pip fixed it.