madmom.processors¶
This module contains all processor related functionality.
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.processors.
Processor
[source]¶ Abstract base class for processing data.
-
classmethod
load
(infile)[source]¶ Instantiate a new Processor from a file.
This method un-pickles a saved Processor object. Subclasses should overwrite this method with a better performing solution if speed is an issue.
Parameters: infile : str or file handle
Pickled processor.
Returns: Processor
instanceProcessor.
-
dump
(outfile)[source]¶ Save the Processor to a file.
This method pickles a Processor object and saves it. Subclasses should overwrite this method with a better performing solution if speed is an issue.
Parameters: outfile : str or file handle
Output file for pickling the processor.
-
process
(data)[source]¶ Process the data.
This method must be implemented by the derived class and should process the given data and return the processed output.
Parameters: data : depends on the implementation of subclass
Data to be processed.
Returns: depends on the implementation of subclass
Processed data.
-
classmethod
-
class
madmom.processors.
OutputProcessor
[source]¶ Class for processing data and/or feeding it into some sort of output.
-
process
(data, output)[source]¶ Processes the data and feed it to the output.
This method must be implemented by the derived class and should process the given data and return the processed output.
Parameters: data : depends on the implementation of subclass
Data to be processed (e.g. written to file).
output : str or file handle
Output file name or file handle.
Returns: depends on the implementation of subclass
Processed data.
-
-
class
madmom.processors.
SequentialProcessor
(processors)[source]¶ Processor class for sequential processing of data.
Parameters: processors : list
Processor instances to be processed sequentially.
Notes
If the processors list contains lists or tuples, these get wrapped as a SequentialProcessor itself.
-
insert
(index, processor)[source]¶ Insert a Processor at the given processing chain position.
Parameters: index : int
Position inside the processing chain.
processor :
Processor
Processor to insert.
-
append
(other)[source]¶ Append another Processor to the processing chain.
Parameters: other :
Processor
Processor to append to the processing chain.
-
-
class
madmom.processors.
ParallelProcessor
(processors, num_threads=None)[source]¶ Processor class for parallel processing of data.
Parameters: processors : list
Processor instances to be processed in parallel.
num_threads : int, optional
Number of parallel working threads.
Notes
If the processors list contains lists or tuples, these get wrapped as a
SequentialProcessor
.-
process
(data)[source]¶ Process the data in parallel.
Parameters: data : depends on the processors
Data to be processed.
Returns: list
Processed data.
-
static
add_arguments
(parser, num_threads)[source]¶ Add parallel processing options to an existing parser object.
Parameters: parser : argparse parser instance
Existing argparse parser object.
num_threads : int, optional
Number of parallel working threads.
Returns: argparse argument group
Parallel processing argument parser group.
Notes
The group is only returned if only if num_threads is not ‘None’. Setting it smaller or equal to 0 sets it the number of CPU cores.
-
-
class
madmom.processors.
IOProcessor
(in_processor, out_processor=None)[source]¶ Input/Output Processor which processes the input data with the input processor and pipes everything into the given output processor.
All Processors defined in the input chain are sequentially called with the ‘data’ argument only. The output Processor is the only one ever called with two arguments (‘data’, ‘output’).
Parameters: in_processor :
Processor
, function, tuple or listInput processor. Can be a
Processor
(or subclass thereof likeSequentialProcessor
orParallelProcessor
), a function accepting a single argument (‘data’). If a tuple or list is given, it is wrapped as aSequentialProcessor
.out_processor :
OutputProcessor
, function, tuple or listOutputProcessor or function accepting two arguments (‘data’, ‘output’). If a tuple or list is given, it is wrapped in an
IOProcessor
itself with the last element regarded as the out_processor and all others as in_processor.-
process
(data, output=None)[source]¶ Processes the data with the input processor and pipe everything into the output processor, which also pipes it to output.
Parameters: data : depends on the input processors
Data to be processed.
output: str or file handle
Output file (handle).
Returns: depends on the output processors
Processed data.
-
-
madmom.processors.
process_single
(processor, infile, outfile, **kwargs)[source]¶ Process a single file with the given Processor.
Parameters: processor :
Processor
instanceProcessor to be processed.
infile : str or file handle
Input file (handle).
outfile : str or file handle
Output file (handle).
-
madmom.processors.
process_batch
(processor, files, output_dir=None, output_suffix=None, strip_ext=True, num_workers=4, shuffle=False, **kwargs)[source]¶ Process a list of files with the given Processor in batch mode.
Parameters: processor :
Processor
instanceProcessor to be processed.
files : list
Input file(s) (handles).
output_dir : str, optional
Output directory.
output_suffix : str, optional
Output suffix (e.g. ‘.txt’ including the dot).
strip_ext : bool, optional
Strip off the extension from the input files.
num_workers : int, optional
Number of parallel working threads.
shuffle : bool, optional
Shuffle the files before distributing them to the working threads
Notes
Either output_dir and/or output_suffix must be set. If strip_ext is True, the extension of the input file names is stripped off before the output_suffix is appended to the input file names.
Use shuffle if you experience out of memory errors (can occur for certain methods with high memory consumptions if consecutive files are rather long).
-
madmom.processors.
pickle_processor
(processor, outfile, **kwargs)[source]¶ Pickle the Processor to a file.
Parameters: processor :
Processor
instanceProcessor to be pickled.
outfile : str or file handle
Output file (handle) where to pickle it.
-
madmom.processors.
io_arguments
(parser, output_suffix='.txt', pickle=True)[source]¶ Add input / output related arguments to an existing parser.
Parameters: parser : argparse parser instance
Existing argparse parser object.
output_suffix : str, optional
Suffix appended to the output files.
pickle : bool, optional
Add a ‘pickle’ sub-parser to the parser?