rdz-oss / BattyBirdNET-Analyzer

BattyBirdNET analyzer for scientific audio data processing.
Other
32 stars 5 forks source link

"Tensor data is null. Run allocate_tensors() first" when running on Arch Linux #19

Open max-mapper opened 4 months ago

max-mapper commented 4 months ago

Hi, I am trying to run the bat_ident.py on Arch Linux. I did the following:

git clone https://github.com/rdz-oss/BattyBirdNET-Analyze
cd BattyBirdNET-Analyze
docker build . -t batty
docker run -v ~/bats:/home/bats -it batty bat_ident.py --area USA --i /home/bats/ --o /home/bats/out/ --rtype csv

But it printed e.g. Error: Cannot analyze audio file /home/bats/NoID_20240726_211812.wav.. After patching https://github.com/rdz-oss/BattyBirdNET-Analyzer/blob/0412be3c081126ef973438c9de1304311f2ab996/bat_ident.py#L473 to /home/bats/error.log I could see the full error:

Traceback (most recent call last):
  File "//bat_ident.py", line 281, in analyze_file
    prediction = predict(samples)
  File "//bat_ident.py", line 217, in predict
    prediction = model.predict(data)
  File "/model.py", line 308, in predict
    return predictWithCustomClassifier(sample)
  File "/model.py", line 351, in predictWithCustomClassifier
    feature_vector = embeddings(sample)
  File "/model.py", line 387, in embeddings
    features = INTERPRETER.get_tensor(OUTPUT_LAYER_INDEX)
  File "/usr/local/lib/python3.9/site-packages/tensorflow/lite/python/interpreter.py", line 888, in get_tensor
    return self._interpreter.GetTensor(tensor_index, subgraph_index)
ValueError: Tensor data is null. Run allocate_tensors() first

I can see in the code that allocate_tensors() is always run after tflite.Interpreter() calls so I'm not sure whats going on, maybe a version mismatch from the known working version (since the dockerfile installs the latest of everything)?

max-mapper commented 4 months ago

As a follow up request, maybe you can publish your working docker image to the docker hub?

Spifffff commented 4 months ago

Same issue here on Windows:

Traceback (most recent call last):
  File "D:\misc\battybirdnet analyzer\bat_ident.py", line 279, in analyze_file
    prediction = predict(samples)
                 ^^^^^^^^^^^^^^^^
  File "D:\misc\battybirdnet analyzer\bat_ident.py", line 217, in predict
    prediction = model.predict(data)
                 ^^^^^^^^^^^^^^^^^^^
  File "D:\misc\battybirdnet analyzer\model.py", line 308, in predict
    return predictWithCustomClassifier(sample)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\misc\battybirdnet analyzer\model.py", line 351, in predictWithCustomClassifier
    feature_vector = embeddings(sample)
                     ^^^^^^^^^^^^^^^^^^
  File "D:\misc\battybirdnet analyzer\model.py", line 387, in embeddings
    features = INTERPRETER.get_tensor(OUTPUT_LAYER_INDEX)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensorflow\lite\python\interpreter.py", line 888, in get_tensor
    return self._interpreter.GetTensor(tensor_index, subgraph_index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Tensor data is null. Run allocate_tensors() first

Running analyze.py works fine, until I add a --classifier parameter

max-mapper commented 3 months ago

I noticed the upstream Dockerfile is practically identical https://github.com/kahst/BirdNET-Analyzer/blob/main/Dockerfile. I just tested building it and it worked. So it must not be a problem with the Dockerfile in this repo...

$ docker build -t birdnet .
$ docker run -v $PWD/example:/audio birdnet analyze.py
Species list contains 6522 species
Found 1 files to analyze
Analyzing example/soundscape.wav
zINFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Finished example/soundscape.wav in 13.56 seconds
Spifffff commented 3 months ago

I noticed the upstream Dockerfile is practically identical https://github.com/kahst/BirdNET-Analyzer/blob/main/Dockerfile. I just tested building it and it worked. So it must not be a problem with the Dockerfile in this repo...

$ docker build -t birdnet .
$ docker run -v $PWD/example:/audio birdnet analyze.py
Species list contains 6522 species
Found 1 files to analyze
Analyzing example/soundscape.wav
zINFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Finished example/soundscape.wav in 13.56 seconds

Have you tried running bat_ident.py instead of analyze.py? I get the allocate_tensors error with the first, but not with the latter.