CPJKU / madmom

Python audio and music signal processing library
https://madmom.readthedocs.io
Other
1.35k stars 206 forks source link

No-beat log density of RNNDownBeatTrackingObservationModel can be invalid #489

Closed omareldeeb closed 2 years ago

omareldeeb commented 2 years ago

Expected behaviour

Log densities of the observations should be valid, non-inf, and non-nan floating-point numbers.

Actual behaviour

If np.sum(observations, axis=1) is greater than 1, the log of a negative number is attempted to be calculated in line 629 of beats_hmm.py, causing a nan to be stored in log_densities. This behavior causes the viterbi algorithm to potentially fail.

Steps needed to reproduce the behaviour

import madmom
import numpy as np
import scipy

beat_decoder = madmom.features.downbeats.DBNDownBeatTrackingProcessor(fps=100.0,
                                                                      correct=True,
                                                                      beats_per_bar=4)
beat_activation = np.random.uniform(0, 1, 100)
downbeat_activation = np.random.uniform(0, 1, 100)
observations = np.dstack((beat_activation, downbeat_activation))[0]

print(beat_decoder.hmms[0].observation_model.log_densities(observations))

Information about installed software

madmom version: '0.16.1' numpy version: '1.19.5' scipy version: '1.7.2'

superbock commented 2 years ago

The observations (including the observations for non-beat states) have to be a probability density function in order to work with DBNDownBeatTrackingProcessor. Thus your observations are not suitable for DBNDownBeatTrackingProcessor. I will update the documentation to be more clear about that.