kitzeslab / bioacoustics-model-zoo

Pre-trained models for bioacoustic classification tasks
30 stars 7 forks source link

BirdNET raises error if OpenSoundscape version 0.10.2 is used #14

Open louisfh opened 1 month ago

louisfh commented 1 month ago

This may already be fixed for future versions, posting here in case others have the same issue.

I tried to use BirdNET in OpenSoundscape v0.10.2. I used torch.hub.load with the appropriate tag. Code:

import opensoundscape
assert opensoundscape.__version__ == "0.10.2"
import torch
m = torch.hub.load('kitzeslab/bioacoustics-model-zoo:0.10.2', 'BirdNET', trust_repo=True, force_reload=True)
data = pd.read_csv('clips.csv', index_col=[0,1,2])
preds = m.predict(data)

This raises the error below. However if I have OpensoundScape v0.10.1 installed it appears to work fine. I used the same environment in both cases.

RuntimeError                              Traceback (most recent call last)
Cell In[1], line 11
      8 # try with just the first 10 rows
      9 data = data.iloc[:100]
---> 11 preds = m.predict(data)

File ~/miniconda3/envs/opso_010_pip_py39_tfGPU/lib/python3.9/site-packages/opensoundscape/ml/cnn.py:244, in BaseClassifier.predict(self, samples, batch_size, num_workers, activation_layer, split_files_into_clips, overlap_fraction, final_clip, bypass_augmentations, invalid_samples_log, raise_errors, wandb_session, return_invalid_samples, progress_bar, **kwargs)
    232     wandb_session.log(
    233         {
    234             "Samples / Preprocessed samples": wandb_table(
   (...)
    238         }
    239     )
    241 ### Prediction/Inference ###
    242 # iterate dataloader and run inference (forward pass) to generate scores
    243 # TODO: allow arbitrary **kwargs to be passed to __call__?
--> 244 pred_scores = self.__call__(
    245     dataloader=dataloader,
    246     wandb_session=wandb_session,
    247     progress_bar=progress_bar,
    248 )
    250 ### Apply activation layer ### #TODO: test speed vs. doing it in __call__ on batches
    251 pred_scores = apply_activation_layer(pred_scores, activation_layer)

File ~/.cache/torch/hub/kitzeslab_bioacoustics-model-zoo_0.10.2/bioacoustics_model_zoo/birdnet.py:140, in BirdNET.__call__(self, dataloader, return_embeddings, return_logits, **kwargs)
    138 # send data to model
    139 self.network.set_tensor(input_details["index"], np.float32(batch))
--> 140 self.network.invoke()  # forward pass
    141 logits.extend(self.network.get_tensor(output_details["index"]))
    142 embeddings.extend(self.network.get_tensor(embedding_idx))

File ~/miniconda3/envs/opso_010_pip_py39_tfGPU/lib/python3.9/site-packages/tensorflow/lite/python/interpreter.py:941, in Interpreter.invoke(self)
    929 """Invoke the interpreter.
    930 
    931 Be sure to set the input sizes, allocate tensors and fill values before
   (...)
    938   ValueError: When the underlying interpreter fails raise ValueError.
    939 """
    940 self._ensure_safe()
--> 941 self._interpreter.Invoke()

RuntimeError: tensorflow/lite/kernels/concatenation.cc:159 t->dims->data[d] != t0->dims->data[d] (854 != 856)Node number 101 (CONCATENATION) failed to prepare.
sammlapp commented 1 month ago

weird. was the tensorflow version the same in both cases?