Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bin/GMMPatternTracker
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ GMMPatternTracker for tracking (down-)beats based on rhythmic patterns.

from __future__ import absolute_import, division, print_function

import glob
import argparse

from madmom import MODELS_PATH
from madmom.processors import IOProcessor, io_arguments
from madmom.audio.signal import SignalProcessor, FramedSignalProcessor
from madmom.audio.spectrogram import (FilteredSpectrogramProcessor,
Expand All @@ -19,6 +17,7 @@ from madmom.audio.spectrogram import (FilteredSpectrogramProcessor,
MultiBandSpectrogramProcessor)
from madmom.features import ActivationsProcessor
from madmom.features.beats import PatternTrackingProcessor
from madmom.models import PATTERNS_BALLROOM


def main():
Expand Down Expand Up @@ -87,7 +86,7 @@ def main():
args.diff_ratio = 0.5
args.positive_diffs = True
args.crossover_frequencies = [270]
args.pattern_files = glob.glob("%s/patterns/2013/*.pkl" % MODELS_PATH)
args.pattern_files = PATTERNS_BALLROOM

# print arguments
if args.verbose:
Expand Down
9 changes: 3 additions & 6 deletions bin/SuperFluxNN
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ SuperFlux with neural network based peak picking onset detection algorithm.

from __future__ import absolute_import, division, print_function

import glob
import argparse

from madmom import MODELS_PATH
from madmom.processors import IOProcessor, io_arguments
from madmom.audio.signal import SignalProcessor, FramedSignalProcessor
from madmom.audio.filters import FilterbankProcessor
from madmom.audio.spectrogram import (LogarithmicSpectrogramProcessor,
SpectrogramDifferenceProcessor,
SuperFluxProcessor)
from madmom.ml.nn import NeuralNetworkEnsemble
from madmom.features import ActivationsProcessor
from madmom.features.onsets import SpectralOnsetProcessor, PeakPickingProcessor
from madmom.ml.nn import NeuralNetworkEnsemble
from madmom.models import ONSETS_BRNN_PP


def main():
Expand Down Expand Up @@ -82,8 +81,6 @@ def main():
args.fps = 100
args.online = False
args.onset_method = 'superflux'
args.nn_files = glob.glob("%s/onsets/2014/onsets_brnn_pp_[1-8].pkl" %
MODELS_PATH)

# print arguments
if args.verbose:
Expand All @@ -107,7 +104,7 @@ def main():
out_processor = ActivationsProcessor(mode='w', **vars(args))
else:
# process everything with multiple RNNs and average the predictions
rnn = NeuralNetworkEnsemble.load(args.nn_files)
rnn = NeuralNetworkEnsemble.load(ONSETS_BRNN_PP)
# perform peak picking, i.e. select the local maxima
pp = PeakPickingProcessor(**vars(args))
from madmom.utils import write_events as writer
Expand Down
11 changes: 4 additions & 7 deletions madmom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=no-member
# pylint: disable=wrong-import-position
"""
Madmom is an audio signal processing library.
Madmom is an audio and music signal processing library.

This library is used internally by the Department of Computational Perception,
Johannes Kepler University, Linz, Austria (http://www.cp.jku.at) and the
Expand All @@ -15,16 +15,13 @@

from __future__ import absolute_import, division, print_function

import os
import pkg_resources

MODELS_PATH = '%s/models' % (os.path.dirname(__file__))
# import all packages
from . import audio, evaluation, features, ml, models, processors, utils

# define a version variable
__version__ = pkg_resources.get_distribution("madmom").version

# keep namespace clean
del os
del pkg_resources

# finally import all submodules
from . import audio, features, evaluation, ml, utils, processors
22 changes: 9 additions & 13 deletions madmom/features/beats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ class RNNBeatProcessor(SequentialProcessor):

def __init__(self, post_processor=None, **kwargs):
# pylint: disable=unused-argument
import glob
from .. import MODELS_PATH
from ..audio.signal import SignalProcessor, FramedSignalProcessor
from ..audio.spectrogram import (
FilteredSpectrogramProcessor, LogarithmicSpectrogramProcessor,
SpectrogramDifferenceProcessor)
from ..models import BEATS_BLSTM
from ..ml.nn import NeuralNetworkEnsemble, average_predictions

# define pre-processing chain
Expand All @@ -53,13 +52,12 @@ def __init__(self, post_processor=None, **kwargs):
# stack the features and processes everything sequentially
pre_processor = SequentialProcessor((sig, multi, np.hstack))

# process the pre-processed signal with a NN ensemble
nn_files = glob.glob("%s/beats/2013/beats_blstm_[1-8].pkl" %
MODELS_PATH)
# average predictions
if post_processor is None:
post_processor = average_predictions
nn = NeuralNetworkEnsemble.load(nn_files, ensemble_fn=post_processor)
# process the pre-processed signal with a NN ensemble
nn = NeuralNetworkEnsemble.load(BEATS_BLSTM,
ensemble_fn=post_processor)

# instantiate a SequentialProcessor
super(RNNBeatProcessor, self).__init__((pre_processor, nn))
Expand Down Expand Up @@ -302,7 +300,7 @@ class BeatTrackingProcessor(Processor):
def __init__(self, look_aside=LOOK_ASIDE, look_ahead=LOOK_AHEAD, fps=None,
**kwargs):
# import the TempoEstimation here otherwise we have a loop
from madmom.features.tempo import TempoEstimationProcessor
from .tempo import TempoEstimationProcessor
# save variables
self.look_aside = look_aside
self.look_ahead = look_ahead
Expand Down Expand Up @@ -639,8 +637,7 @@ def add_arguments(parser, interval_sigma=INTERVAL_SIGMA,

"""
# pylint: disable=arguments-differ

from madmom.utils import OverrideDefaultListAction
from ..utils import OverrideDefaultListAction
# add CRF related arguments
g = parser.add_argument_group('conditional random field arguments')
g.add_argument('--interval_sigma', action='store', type=float,
Expand Down Expand Up @@ -721,11 +718,10 @@ def __init__(self, min_bpm=MIN_BPM, max_bpm=MAX_BPM, num_tempi=NUM_TEMPI,
fps=None, **kwargs):
# pylint: disable=unused-argument
# pylint: disable=no-name-in-module

from madmom.ml.hmm import HiddenMarkovModel as Hmm
from .beats_hmm import (BeatStateSpace as St,
BeatTransitionModel as Tm,
RNNBeatTrackingObservationModel as Om)
from ..ml.hmm import HiddenMarkovModel as Hmm

# convert timing information to construct a beat state space
min_interval = 60. * fps / max_bpm
Expand Down Expand Up @@ -935,11 +931,11 @@ def __init__(self, pattern_files, min_bpm=MIN_BPM, max_bpm=MAX_BPM,
# pylint: disable=no-name-in-module

import pickle
from madmom.ml.hmm import HiddenMarkovModel as Hmm
from .beats_hmm import (BarStateSpace, BarTransitionModel,
MultiPatternStateSpace,
MultiPatternTransitionModel,
GMMPatternTrackingObservationModel)
from ..ml.hmm import HiddenMarkovModel as Hmm

# expand num_tempi and transition_lambda to lists if needed
if not isinstance(num_tempi, list):
Expand Down Expand Up @@ -1066,7 +1062,7 @@ def add_arguments(parser, pattern_files=None, min_bpm=MIN_BPM,
`transition_lambda` must the same number of items.

"""
from madmom.utils import OverrideDefaultListAction
from ..utils import OverrideDefaultListAction
# add GMM options
if pattern_files is not None:
g = parser.add_argument_group('GMM arguments')
Expand Down
11 changes: 6 additions & 5 deletions madmom/features/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ def write_notes(notes, filename, sep='\t', fmt=None, header=''):
'note_time' 'MIDI_note' ['duration' ['MIDI_velocity']]

"""
from ..utils import write_events
# set default format
if fmt is None:
fmt = list(('%.3f', '%d', '%.3f', '%d'))
from madmom.utils import write_events
if not notes.ndim == 2:
raise ValueError('unknown format for `notes`')
# truncate to the number of colums given
Expand Down Expand Up @@ -153,7 +154,7 @@ def write_midi(notes, filename, duration=0.6, velocity=100):
'note_time' 'MIDI_note' ['duration' ['MIDI_velocity']]

"""
from madmom.utils.midi import process_notes
from ..utils.midi import process_notes
# expand the array to have a default duration and velocity
notes = expand_notes(notes, duration, velocity)
# write the notes to the file and return them
Expand Down Expand Up @@ -189,7 +190,7 @@ def write_mirex_format(notes, filename, duration=0.6):
'onset_time' 'offset_time' 'note_frequency'

"""
from madmom.audio.filters import midi2hz
from ..audio.filters import midi2hz
# expand the notes if needed
notes = expand_notes(notes, duration)
# report offset time instead of duration
Expand All @@ -209,11 +210,11 @@ class RNNPianoNoteProcessor(SequentialProcessor):

def __init__(self, **kwargs):
# pylint: disable=unused-argument
from .. import MODELS_PATH
from ..audio.signal import SignalProcessor, FramedSignalProcessor
from ..audio.spectrogram import (
FilteredSpectrogramProcessor, LogarithmicSpectrogramProcessor,
SpectrogramDifferenceProcessor)
from ..models import NOTES_BRNN
from ..ml.nn import NeuralNetwork

# define pre-processing chain
Expand All @@ -233,7 +234,7 @@ def __init__(self, **kwargs):
pre_processor = SequentialProcessor((sig, multi, np.hstack))

# process the pre-processed signal with a NN
nn = NeuralNetwork.load("%s/notes/2013/notes_brnn.pkl" % MODELS_PATH)
nn = NeuralNetwork.load(NOTES_BRNN[0])

# instantiate a SequentialProcessor
super(RNNPianoNoteProcessor, self).__init__((pre_processor, nn))
9 changes: 3 additions & 6 deletions madmom/features/onsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,19 @@ class RNNOnsetProcessor(SequentialProcessor):

def __init__(self, online=False, **kwargs):
# pylint: disable=unused-argument
import glob
from .. import MODELS_PATH
from ..audio.signal import SignalProcessor, FramedSignalProcessor
from ..audio.spectrogram import (
FilteredSpectrogramProcessor, LogarithmicSpectrogramProcessor,
SpectrogramDifferenceProcessor)
from ..models import ONSETS_RNN, ONSETS_BRNN
from ..ml.nn import NeuralNetworkEnsemble

# choose the appropriate models and set frame sizes accordingly
if online:
nn_files = glob.glob("%s/onsets/2013/onsets_rnn_[1-8].pkl" %
MODELS_PATH)
nn_files = ONSETS_RNN
frame_sizes = [512, 1024, 2048]
else:
nn_files = glob.glob("%s/onsets/2013/onsets_brnn_[1-8].pkl" %
MODELS_PATH)
nn_files = ONSETS_BRNN
frame_sizes = [1024, 2048, 4096]

# define pre-processing chain
Expand Down
2 changes: 1 addition & 1 deletion madmom/models
Submodule models updated 1 files
+30 −0 __init__.py
2 changes: 0 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import os

from madmom import MODELS_PATH

DATA_PATH = os.path.dirname(os.path.realpath(__file__)) + '/data/'
AUDIO_PATH = DATA_PATH + 'audio/'
ACTIVATIONS_PATH = DATA_PATH + 'activations/'
Expand Down
1 change: 0 additions & 1 deletion tests/test_evaluation_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ def setUp(self):
def test_args(self):
args = self.parser.parse_args(['notes', ANNOTATIONS_PATH,
DETECTIONS_PATH])
print(args)
self.assertTrue(args.ann_dir is None)
self.assertTrue(args.ann_suffix == '.notes')
self.assertTrue(args.det_dir is None)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_features_beats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
from __future__ import absolute_import, division, print_function

import unittest
from . import AUDIO_PATH, ACTIVATIONS_PATH, MODELS_PATH
from madmom.ml.hmm import HiddenMarkovModel
from . import AUDIO_PATH, ACTIVATIONS_PATH
from madmom.features import Activations
from madmom.features.beats import *
from madmom.features.beats_hmm import *
from madmom.ml.hmm import HiddenMarkovModel
from madmom.models import PATTERNS_BALLROOM


sample_file = "%s/sample.wav" % AUDIO_PATH
sample_act = Activations("%s/sample.beats_blstm_2013.npz" % ACTIVATIONS_PATH)
Expand Down Expand Up @@ -96,9 +98,7 @@ def test_process(self):
class TestPatternTrackingProcessorClass(unittest.TestCase):

def setUp(self):
import glob
pattern_files = sorted(glob.glob("%s/patterns/2013/*" % MODELS_PATH))
self.processor = PatternTrackingProcessor(pattern_files,
self.processor = PatternTrackingProcessor(PATTERNS_BALLROOM,
fps=sample_mb_features.fps)

def test_types(self):
Expand Down
1 change: 0 additions & 1 deletion tests/test_features_beats_hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ def test_values_bar(self):
self.assertTrue(tm.num_states == 20 + 20)
self.assertTrue(tm.num_transitions == 26 + 28)
# the first pattern has 26 transitions
print(tm.log_probabilities)
self.assertTrue(np.allclose(tm.states[:26],
[10, 12, 15, 1, 15, 19, 3, 4, 15, 19, 6, 7,
8, 0, 2, 5, 11, 5, 9, 13, 14, 5, 9, 16,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_features_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class TestLoadNotesFunction(unittest.TestCase):

def test_values(self):
result = load_notes(ANNOTATIONS_PATH + 'stereo_sample.notes')
print(result)
self.assertTrue(np.allclose(result, NOTES))


Expand Down Expand Up @@ -61,7 +60,6 @@ class TestWriteMirexFormatFunction(unittest.TestCase):
def test_values(self):
result = write_mirex_format(NOTES, ANNOTATIONS_PATH +
'stereo_sample.notes.mirex')
print(result)
self.assertTrue(np.allclose(result[:, 0], NOTES[:, 0]))
self.assertTrue(np.allclose(result[:, 1], NOTES[:, 0] + NOTES[:, 2]))
self.assertTrue(np.allclose(result[:, 2], [523.3, 87.3, 698.5, 261.6,
Expand Down
6 changes: 2 additions & 4 deletions tests/test_features_tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from __future__ import absolute_import, division, print_function

import unittest
from . import ACTIVATIONS_PATH, DETECTIONS_PATH
from . import ACTIVATIONS_PATH
from madmom.features.tempo import *

act_file = np.load("%s/sample.beats_blstm_2013.npz" % ACTIVATIONS_PATH)
Expand Down Expand Up @@ -132,14 +132,12 @@ def test_values(self):
result = write_tempo(COMB_TEMPI[5], self.out_file)
self.assertTrue(np.allclose(result, [52.17, 104.34, 1], atol=0.001))
# multiple tempi given
result = write_tempo(COMB_TEMPI, DETECTIONS_PATH +
'sample.tempo_detector.txt')
result = write_tempo(COMB_TEMPI, self.out_file)
self.assertTrue(np.allclose(result, [176.47, 117.65, 0.684],
atol=0.001))

def test_values_mirex(self):
# multiple tempi given
result = write_tempo(COMB_TEMPI, self.out_file, mirex=True)
print(result)
self.assertTrue(np.allclose(result, [117.65, 176.47, 0.316],
atol=0.001))
Loading