madmom.evaluation.key

This module contains key evaluation functionality.

madmom.evaluation.key.key_label_to_class(key_label)[source]

Convert key label to key class number.

The key label must follow the MIREX syntax defined at http://music-ir.org/mirex/wiki/2017:Audio_Key_Detection: tonic mode, where tonic is in {C, C#, Db, … Cb} and mode in {‘major’, ‘maj’, ‘minor’, ‘min’}. The label will be converted into a class id based on the root pitch id (c .. 0, c# .. 1, …, cb … 11) plus 12 if in minor mode.

Parameters:
key_label : str

Key label.

Returns:
key_class : int

Key class.

Examples

>>> from madmom.evaluation.key import key_label_to_class
>>> key_label_to_class('D major')
2
>>> key_label_to_class('D minor')
14
madmom.evaluation.key.error_type(det_key, ann_key, strict_fifth=False)[source]

Compute the evaluation score and error category for a predicted key compared to the annotated key.

Categories and evaluation scores follow the evaluation strategy used for MIREX (see http://music-ir.org/mirex/wiki/2017:Audio_Key_Detection). There are two evaluation modes for the ‘fifth’ category: by default, a detection falls into the ‘fifth’ category if it is the fifth of the annotation, or the annotation is the fifth of the detection. If strict_fifth is True, only the former case is considered. This is the mode used for MIREX.

Parameters:
det_key : int

Detected key class.

ann_key : int

Annotated key class.

strict_fifth: bool

Use strict interpretation of the ‘fifth’ category, as in MIREX.

Returns:
score, category : float, str

Evaluation score and error category.

class madmom.evaluation.key.KeyEvaluation(detection, annotation, strict_fifth=False, name=None, **kwargs)[source]

Provide the key evaluation score.

Parameters:
detection : str

File containing detected key

annotation : str

File containing annotated key

strict_fifth : bool, optional

Use strict interpretation of the ‘fifth’ category, as in MIREX.

name : str, optional

Name of the evaluation object (e.g., the name of the song).

tostring(**kwargs)[source]

Format the evaluation as a human readable string.

Returns:
str

Evaluation score and category as a human readable string.

class madmom.evaluation.key.KeyMeanEvaluation(eval_objects, name=None)[source]

Class for averaging key evaluations.

Parameters:
eval_objects : list

Key evaluation objects.

name : str, optional

Name to be displayed.

tostring(**kwargs)[source]

Format the evaluation metrics as a human readable string.

Returns:
str

Evaluation metrics formatted as a human readable string.

Notes

This is a fallback method formatting the metrics dictionary in a human readable way. Classes inheriting from this mixin class should provide a method better suitable.

madmom.evaluation.key.add_parser(parser)[source]

Add a key evaluation sub-parser to an existing parser.

Parameters:
parser : argparse parser instance

Existing argparse parser object.

Returns:
sub_parser : argparse sub-parser instance

Key evaluation sub-parser.