worldveil / dejavu

Audio fingerprinting and recognition in Python
MIT License
6.41k stars 1.43k forks source link

divide by zero warning #141

Open soroosh-rz opened 6 years ago

soroosh-rz commented 6 years ago

Hello,

I am testing and executing the code in Fedora, however during the fingerprinting of mp3 directory I receive these warnings:

dejavu/fingerprint.py:82: RuntimeWarning: divide by zero encountered in log10 arr2D = 10 * np.log10(arr2D)

I wonder if these warnings are normal and if they have impact on the finals results? I'd be grateful if you could help me to find out my answer.

Thanks,

CwbhX commented 6 years ago

Not sure how numpy's log10 function works here, but you probably have 0's in your spectrogram. no worries

mauricio-repetto commented 5 years ago

yes, that's right the problem is in the fingerprint.py file, on fingerprint method, it applies np.log10 over an array with some 0s, that causes to return -np.Inf on those cases (and thus the warning you're seeing). If you check the code the developer later replace those negative np.Inf with 0s. A more fancy solution to avoid that would be to replace those lines with:

# Apply log transform since specgram() returns linear array. 0s are excluded to avoid np warning.
arr2D = 10 * np.log10(arr2D, out=np.zeros_like(arr2D), where=(arr2D != 0))