madmom.features

This package includes high-level features. Your definition of “high” may vary, but we define high-level features as the ones you want to evaluate (e.g. onsets, beats, etc.). All lower-level features can be found the madmom.audio package.

Notes

All features should be implemented as classes which inherit from Processor (or provide a XYZProcessor(Processor) variant). This way, multiple Processor objects can be chained/combined to achieve the wanted functionality.

class madmom.features.Activations(data, fps=None, sep=None, dtype=<type 'numpy.float32'>)[source]

The Activations class extends a numpy ndarray with a frame rate (fps) attribute.

Parameters:

data : str, file handle or numpy array

Either file name/handle to read the data from or array.

fps : float, optional

Frames per second (must be set if data is given as an array).

sep : str, optional

Separator between activation values (if read from file).

dtype : numpy dtype

Data-type the activations are stored/saved/kept.

Notes

If a filename or file handle is given, an undefined or empty separator means that the file should be treated as a numpy binary file. Only binary files can store the frame rate of the activations. Text files should not be used for anything else but manual inspection or I/O with other programs.

Attributes

fps (float) Frames per second.
classmethod load(infile, fps=None, sep=None)[source]

Load the activations from a file.

Parameters:

infile : str or file handle

Input file name or file handle.

fps : float, optional

Frames per second; if set, it overwrites the saved frame rate.

sep : str, optional

Separator between activation values.

Returns:

Activations instance

Activations instance.

Notes

An undefined or empty separator means that the file should be treated as a numpy binary file. Only binary files can store the frame rate of the activations. Text files should not be used for anything else but manual inspection or I/O with other programs.

save(outfile, sep=None, fmt='%.5f')[source]

Save the activations to a file.

Parameters:

outfile : str or file handle

Output file name or file handle.

sep : str, optional

Separator between activation values if saved as text file.

fmt : str, optional

Format of the values if saved as text file.

Notes

An undefined or empty separator means that the file should be treated as a numpy binary file. Only binary files can store the frame rate of the activations. Text files should not be used for anything else but manual inspection or I/O with other programs.

If the activations are a 1D array, its values are interpreted as features of a single time step, i.e. all values are printed in a single line. If you want each value to appear in an individual line, use ‘n’ as a separator.

If the activations are a 2D array, the first axis corresponds to the time dimension, i.e. the features are separated by sep and the time steps are printed in separate lines. If you like to swap the dimensions, please use the T attribute.

class madmom.features.ActivationsProcessor(mode, fps=None, sep=None, **kwargs)[source]

ActivationsProcessor processes a file and returns an Activations instance.

Parameters:

mode : {‘r’, ‘w’, ‘in’, ‘out’, ‘load’, ‘save’}

Mode of the Processor: read/write.

fps : float, optional

Frame rate of the activations (if set, it overwrites the saved frame rate).

sep : str, optional

Separator between activation values if saved as text file.

Notes

An undefined or empty (“”) separator means that the file should be treated as a numpy binary file. Only binary files can store the frame rate of the activations.

process(data, output=None, **kwargs)[source]

Depending on the mode, either loads the data stored in the given file and returns it as an Activations instance or save the data to the given output.

Parameters:

data : str, file handle or numpy array

Data or file to be loaded (if mode is ‘r’) or data to be saved to file (if mode is ‘w’).

output : str or file handle, optional

output file (only in write-mode)

Returns:

Activations instance

Activations instance (only in read-mode)

static add_arguments(parser)[source]

Add options to save/load activations to an existing parser.

Parameters:

parser : argparse parser instance

Existing argparse parser.

Returns:

parser_group : argparse argument group

Input/output argument parser group.