Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
max-mapper opened this issue Jul 31, 2024 · 4 comments

Comments

@max-mapper
Copy link

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

cfg.ERROR_LOG_FILE = os.path.join(script_dir, cfg.ERROR_LOG_FILE)
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
Copy link
Author

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

@Spifffff
Copy link

Spifffff commented Aug 1, 2024

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
Copy link
Author

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
Copy link

Spifffff commented Aug 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants