Beispiel #1
0
def evaluate_model_all(test_guesses, test_labels):
    '''
        Run standard Mirex evaluations on all test data
        Inputs:
            1d np.array containing all predictions made by the model
            1d np.array containing all ground truth labels
        Outputs:
            Dict holding results of all evaluations
    '''
    print('Running conversions...')
    ref_freq = hr.note_to_hz_zeros(test_labels)  # And back to Hz!
    est_freq = hr.note_to_hz_zeros(test_guesses)

    ref_cent = mel_eval.hz2cents(ref_freq)  # Then to cents...
    est_cent = mel_eval.hz2cents(est_freq)

    ref_voicing = mel_eval.freq_to_voicing(ref_freq)[1]  # And voicings!
    est_voicing = mel_eval.freq_to_voicing(est_freq)[1]

    print('Evaluating voicing...')
    vx_recall, vx_false_alarm = mel_eval.voicing_measures(
        ref_voicing, est_voicing)

    print('Evaluating pitch...')
    raw_pitch = mel_eval.raw_pitch_accuracy(ref_voicing,
                                            ref_cent,
                                            est_voicing,
                                            est_cent,
                                            cent_tolerance=50)

    print('Evaluating chroma...')
    raw_chroma = mel_eval.raw_chroma_accuracy(ref_voicing,
                                              ref_cent,
                                              est_voicing,
                                              est_cent,
                                              cent_tolerance=50)

    print('Evaluating overall accuracy...')
    overall_accuracy = mel_eval.overall_accuracy(ref_voicing,
                                                 ref_cent,
                                                 est_voicing,
                                                 est_cent,
                                                 cent_tolerance=50)

    metrics = {
        'vx_recall': vx_recall,
        'vx_false_alarm ': vx_false_alarm,
        'raw_pitch': raw_pitch,
        'raw_chroma': raw_chroma,
        'overall_accuracy': overall_accuracy
    }

    for m, v in metrics.items():  # Python2 is iteritems I think
        print(m, ':', v)

    return metrics
Beispiel #2
0
def format_annotation(new_times, annot_times, annot_freqs):
    """ Format an annotation file and resample to a uniform timebase.

    Parameters
    ----------
    new_times : np.array
        Times to resample to
    annot_times : np.array
        Annotation time stamps
    annot_freqs : np.array
        Annotation frequency values

    Returns
    -------

    ref_cent : np.array
        Annotation frequencies in cents at the new timescale
    ref_voicing : np.array
        Annotation voicings at the new timescale

    """
    ref_freq, ref_voicing = melody.freq_to_voicing(annot_freqs)
    ref_cent = melody.hz2cents(ref_freq)

    ref_cent, ref_voicing = melody.resample_melody_series(
        annot_times, ref_cent, ref_voicing, new_times,
        kind='linear'
    )
    return ref_cent, ref_voicing
Beispiel #3
0
def eval_from_hz(ref_hz, est_hz):
    ref_cent = melody.hz2cents(ref_hz)
    est_cent = melody.hz2cents(est_hz)
    ref_voicing = np.array(ref_cent > 0, dtype=float)
    est_voicing = np.array(est_cent > 0, dtype=float)
    recall, false_alarm = melody.voicing_measures(ref_voicing, est_voicing)
    return {
        "recall":
        recall,
        "false_alarm":
        false_alarm,
        "rca50":
        melody.raw_chroma_accuracy(ref_voicing,
                                   ref_cent,
                                   est_voicing,
                                   est_cent,
                                   cent_tolerance=50),
        "rpa50":
        melody.raw_pitch_accuracy(ref_voicing,
                                  ref_cent,
                                  est_voicing,
                                  est_cent,
                                  cent_tolerance=50),
        "rpa25":
        melody.raw_pitch_accuracy(ref_voicing,
                                  ref_cent,
                                  est_voicing,
                                  est_cent,
                                  cent_tolerance=25),
        "rpa10":
        melody.raw_pitch_accuracy(ref_voicing,
                                  ref_cent,
                                  est_voicing,
                                  est_cent,
                                  cent_tolerance=10),
        "std50":
        eval_pitch_std(ref_voicing,
                       ref_cent,
                       est_voicing,
                       est_cent,
                       cent_tolerance=50)
    }
Beispiel #4
0
def matrix_parser(m):
    x = np.zeros(shape=(m.shape[0], 2))

    for i in range(len(m)):
        if (np.sum(m[i]) != 0):
            x[i][0] = 1
            x[i][1] = midi2freq(np.argmax(m[i]) / 4 + 21)

    x[:, 1] = melody.hz2cents(x[:, 1])

    return x
Beispiel #5
0
def evaluate_model_melody(test_guesses, test_labels):
    '''
        Run standard pitch and chroma evaluations on all test data
        Inputs:
            1d np.array containing all predictions made by the model
            1d np.array containing all ground truth labels
        Outputs:
            Dict holding results of all evaluations
    '''
    ref_freq = hr.note_to_hz_zeros(test_labels)
    est_freq = hr.note_to_hz_zeros(test_guesses)

    ref_cent = mel_eval.hz2cents(ref_freq)
    est_cent = mel_eval.hz2cents(est_freq)

    all_voiced = np.ones(len(ref_cent), dtype=bool)

    print('Evaluating pitch...')
    raw_pitch = mel_eval.raw_pitch_accuracy(all_voiced,
                                            ref_cent,
                                            all_voiced,
                                            est_cent,
                                            cent_tolerance=50)

    print('Evaluating chroma...')
    raw_chroma = mel_eval.raw_chroma_accuracy(all_voiced,
                                              ref_cent,
                                              all_voiced,
                                              est_cent,
                                              cent_tolerance=50)
    metrics = {
        'raw_pitch': raw_pitch,
        'raw_chroma': raw_chroma,
    }

    for m, v in metrics.items():
        print(m, ':', v)

    return metrics
Beispiel #6
0
def format_contour_data(frequencies):
    """ Convert contour frequencies to cents + voicing.

    Parameters
    ----------
    frequencies : np.array
        Contour frequency values

    Returns
    -------
    est_cent : np.array
        Contour frequencies in cents
    est_voicing : np.array
        Contour voicings

    """
    est_freqs, est_voicing = melody.freq_to_voicing(frequencies)
    est_cents = melody.hz2cents(est_freqs)
    return est_cents, est_voicing
def getf0CentsVoicingArrays(f0Values):
    f0ValuesArray, voicingArray = melody.freq_to_voicing(f0Values)
    f0CentsArray = melody.hz2cents(f0ValuesArray, base_frequency=10.0)
    return f0CentsArray, voicingArray