Skip to content
Extraits de code Groupes Projets
Valider 399ab88f rédigé par Sting's avatar Sting
Parcourir les fichiers

Try with modified Kullback-Leibler

parent 7f7df0c6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!2CNN + Spectral segmentation
...@@ -7,7 +7,8 @@ from scipy.ndimage.filters import maximum_filter ...@@ -7,7 +7,8 @@ from scipy.ndimage.filters import maximum_filter
def segment(songfile): def segment(songfile):
delay = 0 delay = -4
backtrack = False
cnn = madmom.features.onsets.CNNOnsetProcessor() cnn = madmom.features.onsets.CNNOnsetProcessor()
spectral = madmom.features.onsets.SpectralOnsetProcessor('complex_domain') spectral = madmom.features.onsets.SpectralOnsetProcessor('complex_domain')
...@@ -21,17 +22,18 @@ def segment(songfile): ...@@ -21,17 +22,18 @@ def segment(songfile):
spectral_function = spectral(songfile, num_channels=1) spectral_function = spectral(songfile, num_channels=1)
spectral_function = spectral_function/(spectral_function.max()) spectral_function = spectral_function/(spectral_function.max())
activation_function = 0.5*cnn_function + 0.5*spectral_function #activation_function = 0.5*cnn_function + 0.5*spectral_function
#activation_function = (2 * cnn_function * spectral_function)/(cnn_function + spectral_function) activation_function = (2 * cnn_function * spectral_function)/(cnn_function + spectral_function)
#activation_function = np.where(spectral_function > 0.14, cnn_function, 0) #activation_function = np.where(spectral_function > 0.14, cnn_function, 0)
#onsets = proc(activation_function) #onsets = proc(activation_function)
activation_smoothed = madmom.audio.signal.smooth(activation_function, 20) activation_smoothed = madmom.audio.signal.smooth(activation_function, 20)
cnn_smoothed = madmom.audio.signal.smooth(cnn_function, 20) cnn_smoothed = madmom.audio.signal.smooth(cnn_function, 20)
onsets = madmom.features.onsets.peak_picking(activation_smoothed, threshold=1, smooth=0) onsets = madmom.features.onsets.peak_picking(activation_smoothed, threshold=0.6, smooth=0)
onsets = np.array([o for o in onsets if cnn_smoothed[o] > 0.2]) onsets = np.array([o for o in onsets if cnn_smoothed[o] > 0.2])
if backtrack:
# Backtrack onsets to closest earlier local minimum # Backtrack onsets to closest earlier local minimum
backtrack_max_frames = 50 backtrack_max_frames = 50
for i in range(len(onsets)): for i in range(len(onsets)):
...@@ -50,8 +52,10 @@ def segment(songfile): ...@@ -50,8 +52,10 @@ def segment(songfile):
if __name__ == "__main__": if __name__ == "__main__":
songfile = sys.argv[1] songfile = sys.argv[1]
backtrack = False
cnn = madmom.features.onsets.CNNOnsetProcessor() cnn = madmom.features.onsets.CNNOnsetProcessor()
spectral = madmom.features.onsets.SpectralOnsetProcessor('complex_domain') spectral = madmom.features.onsets.SpectralOnsetProcessor('modified_kullback_leibler')
spec = spec = madmom.audio.spectrogram.Spectrogram(songfile, num_channels=1) spec = spec = madmom.audio.spectrogram.Spectrogram(songfile, num_channels=1)
...@@ -62,17 +66,18 @@ if __name__ == "__main__": ...@@ -62,17 +66,18 @@ if __name__ == "__main__":
spectral_function = spectral(songfile, num_channels=1) spectral_function = spectral(songfile, num_channels=1)
spectral_function = spectral_function/(spectral_function.max()) spectral_function = spectral_function/(spectral_function.max())
activation_function = 0.5*cnn_function + 0.5*spectral_function #activation_function = 0.5*cnn_function + 0.5*spectral_function
#activation_function = (2 * cnn_function * spectral_function)/(cnn_function + spectral_function) activation_function = (2 * cnn_function * spectral_function)/(cnn_function + spectral_function)
#activation_function = np.where(spectral_function > 0.14, cnn_function, 0) #activation_function = np.where(spectral_function > 0.14, cnn_function, 0)
#onsets = proc(activation_function) #onsets = proc(activation_function)
activation_smoothed = madmom.audio.signal.smooth(activation_function, 20) activation_smoothed = madmom.audio.signal.smooth(activation_function, 20)
cnn_smoothed = madmom.audio.signal.smooth(cnn_function, 20) cnn_smoothed = madmom.audio.signal.smooth(cnn_function, 20)
onsets = madmom.features.onsets.peak_picking(activation_smoothed, threshold=1, smooth=0) onsets = madmom.features.onsets.peak_picking(activation_smoothed, threshold=0.6, smooth=0)
onsets = np.array([o for o in onsets if cnn_smoothed[o] > 0.2]) onsets = np.array([o for o in onsets if cnn_smoothed[o] > 0.2])
# Backtrack onsets to closest earlier local minimum # Backtrack onsets to closest earlier local minimum
if backtrack:
backtrack_max_frames = 50 backtrack_max_frames = 50
for i in range(len(onsets)): for i in range(len(onsets)):
initial_onset = onsets[i] initial_onset = onsets[i]
...@@ -85,7 +90,7 @@ if __name__ == "__main__": ...@@ -85,7 +90,7 @@ if __name__ == "__main__":
axs[0].imshow(log_spec.T, origin='lower', aspect='auto') axs[0].imshow(log_spec.T, origin='lower', aspect='auto')
axs[1].plot(cnn_smoothed) axs[1].plot(cnn_smoothed)
axs[1].plot(spectral_function, color='green') axs[1].plot(spectral_function, color='green')
axs[1].plot(activation_smoothed, color='pink') axs[1].plot(activation_smoothed, color='orange')
axs[1].vlines(onsets, 0, 1, colors='red') axs[1].vlines(onsets, 0, 1, colors='red')
plt.show() plt.show()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter