macaodha / batdetect2

Other
48 stars 9 forks source link

IndexError: list index out of range #10

Closed NoxTheXelor closed 1 year ago

NoxTheXelor commented 1 year ago

Hello, I was using the batdetect2 api (the 1.0.4) on a raspberry pi with high frequence microphone. It worked very well (thanks to your work) few hours, but I encountered this error

File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
  self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run 
   self._target (self._args, **self._kwargs)
File "/usr/local/bin/server.py", line 178, in handle_client 
   results = api.process_file(file_path) ["pred_dict"]
File "/home/bird/BirdNET-Pi/scripts/batdetect2/api.py", line 262, in process_file 
   return du.process_file(
File "/home/bird/BirdNET-Pi/scripts/batdetect2/utils/detector_utils.py", line 785,  in process_file 
   predictions, spec_feats, cnn_feats, spec_slices = _merge_results( 
 File "/home/bird/BirdNET-Pi/scripts/batdetect2/utils/detector_utils.py", line 157, in _merge_results( 
    predictions_m=predictions[0]
IndexError: list index out of range

I only used this line results = api.process_file(file_path) ["pred_dict"] in my code

I have not dived in the concerned code yet so I don't have any other info but don't hesitate to ask. Could you give it a look ? I joind a picture of the error as the code above is the result of a image to text and may contains error. Thanks in advance 1683751572362

mbsantiago commented 1 year ago

Hi @NoxTheXelor!

Thanks for filing this issue. I have looked into it, and it seems that the problem was caused by the code not handling situations where the model did not produce any detections. I have fixed this issue and released a new version, 1.0.5. Please upgrade to the latest version and let me know if the issue has been resolved.

In my testing, I tried creating scenarios where the model did not output any detections by running it on random noise and silent recordings, but the model was still able to find bat calls (albeit with a low probability). However, the only way I was able to replicate the issue you reported was by running the API on an empty WAV file with zero samples. This suggests that there may be an issue with the recordings made on your device. Thought it might be useful info.

Again, thanks for your interest in batdetect2, happy to hear what you are using it for.

Cheers, Santiago

NoxTheXelor commented 1 year ago

Thanks for the quick reply, I'll run a new instance soon and update you. For my thesis I'm working on a bat version of BirdNET-Pi (https://github.com/mcguirepr89/BirdNET-Pi). I tried different ai model but yours gave the best processing speed so thanks again for that.