macaodha / batdetect2

Other
53 stars 10 forks source link

Latest numpy results in error when detecting bat calls #29

Open fhaefele opened 4 months ago

fhaefele commented 4 months ago

I just noticed that when I installed your package using pip install batdetect2 as well as installing it from source (cloning and pip install . that the latest numpy version results in an error when I try to detect calls.

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

The suggested fix worked nicely. I was able to run batdetect2 after downgrading numpy. Perhaps you should specify "numpy<2" in your pyproject.toml which will force pip to install a Numpy version 1.x. as it might take time for other dependencies to support Numpy version 2.x

revilodarnoc commented 3 months ago

Thanks the hint. I run pip uninstall numpy for the 2.0.x. I run pip install numpy==1.26.4. Now batdetect2 doesn't crash anymore.

Errors while running as below.

Loading model: /home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/models/Net2DFast_UK_same.pth.tar

Input directory: Expand/ Number of audio files: 2257

Saving results to: batdetect/

Processing Configuration: Time Expansion Factor: 1 Detection Threshold: 0.3

0 Expand/20240726_192212_000.WAV 1 call(s) detected above the threshold. species name probablity present Nyctalus leisleri 0.977 Nyctalus noctula 0.011 Eptesicus serotinus 0.007

1 Expand/20240726_192217_000.WAV 9 call(s) detected above the threshold. species name probablity present Pipistrellus pipistrellus 0.278 Pipistrellus nathusii 0.224 Myotis nattereri 0.133

2 Expand/20240726_192222_000.WAV 3 call(s) detected above the threshold. species name probablity present Pipistrellus pygmaeus 0.56 Pipistrellus pipistrellus 0.431 Pipistrellus nathusii 0.007

3 Expand/20240726_192227_000.WAV 2 call(s) detected above the threshold. species name probablity present Pipistrellus pipistrellus 0.661 Nyctalus leisleri 0.182 Eptesicus serotinus 0.097

4 Expand/20240726_192232_000.WAV Traceback (most recent call last): File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/utils/detector_utils.py", line 239, in format_single_result class_overall = pp.overall_class_pred( File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/detector/post_process.py", line 39, in overall_class_pred weighted_pred = (class_prob * det_prob).sum(1) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/numpy/_core/_methods.py", line 52, in _sum return umr_sum(a, axis, dtype, out, keepdims, initial, where) numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/oliver/anaconda3/envs/batdetect2/bin/batdetect2", line 8, in sys.exit(cli()) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/click/core.py", line 783, in invoke return __callback(args, **kwargs) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/cli.py", line 125, in detect results = api.process_file(audio_file, model, config=config) File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/api.py", line 262, in process_file return du.process_file( File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/utils/detector_utils.py", line 817, in process_file results = convert_results( File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/utils/detector_utils.py", line 290, in convert_results pred_dict = format_single_result( File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/batdetect2/utils/detector_utils.py", line 245, in format_single_result except (np.AxisError, ValueError): File "/home/oliver/anaconda3/envs/batdetect2/lib/python3.10/site-packages/numpy/init.py", line 410, in getattr raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'AxisError' (

padpadpadpad commented 1 week ago

Am helping a student run Batdetect2, and he gets this exact error:

AttributeError: module 'numpy' has no attribute 'AxisError

when running some, but not all files.

mbsantiago commented 1 week ago

Thanks for the issue! I will be working on fixing bugs this in November and will attend to this in particular.

padpadpadpad commented 1 week ago

Thanks for the issue! I will be working on fixing bugs this in November and will attend to this in particular.

Hi @mbsantiago I have an example of a file that does (and one that does not) have this issue collected by the same student if this helps?

mbsantiago commented 1 week ago

That would be very helpful, thanks! Please attach here as a zip file

padpadpadpad commented 1 week ago

Attached here, it has a readme explaining each file (as the undergraduate student has told me). Any issues let me know, sorry it is not more reproducible and cleaner!

Bat Detect 2 Files and Error messages.zip