Example #1
0
def score_model(model, x, b, t):

    # First, transform the data
    if model is not None:
        try:
            xt = model.dot(x)
        except:
            return 0.0
    else:
        xt = x

    # Then, run the segmenter
    kmin, kmax = segmenter.get_num_segs(b[-1])
    boundary_beats = segmenter.get_segments(xt, kmin=kmin, kmax=kmax)

    if len(boundary_beats) < 2 or len(t) < 2:
        return 0.0

    t = np.unique(t)
    boundary_times = mir_eval.util.adjust_events(b[boundary_beats],
                                                 t_min=0.0,
                                                 t_max=t[-1])[0]

    truth_intervals = mir_eval.util.boundaries_to_intervals(t)
    pred_intervals = mir_eval.util.boundaries_to_intervals(boundary_times)
    score = mir_eval.segment.detection(truth_intervals,
                                       pred_intervals,
                                       trim=True)[-1]

    return score
Example #2
0
def score_model(model, x, b, t):

    # First, transform the data
    if model is not None:
        try:
            xt = model.dot(x)
        except:
            return 0.0
    else:
        xt = x

    # Then, run the segmenter
    kmin, kmax = segmenter.get_num_segs(b[-1])
    boundary_beats = segmenter.get_segments(xt, kmin=kmin, kmax=kmax)

    if len(boundary_beats) < 2 or len(t) < 2:
        return 0.0

    t = np.unique(t)
    boundary_times = mir_eval.util.adjust_events(b[boundary_beats], t_min=0.0, t_max=t[-1])[0]

    truth_intervals = mir_eval.util.boundaries_to_intervals(t)[0]
    pred_intervals = mir_eval.util.boundaries_to_intervals(boundary_times)[0]
    score = mir_eval.segment.detection(truth_intervals, pred_intervals, trim=True)[-1]

    return score
Example #3
0
def score_model(model, x, b, t):

    # First, transform the data
    if model is not None:
        xt = model.dot(x)
    else:
        xt = x

    # Then, run the segmenter
    kmin, kmax = segmenter.get_num_segs(b[-1])
    boundary_beats = segmenter.get_segments(xt, kmin=kmin, kmax=kmax)

    if len(boundary_beats) < 2 or len(t) < 2:
        return 0.0

    boundary_times = mir_eval.util.adjust_events(b[boundary_beats],
                                                 t_min=0.0,
                                                 t_max=t[-1])[0]

    # Convert boundaries to intervals
    truth_intervals = mir_eval.util.boundaries_to_intervals(t)[0]
    pred_intervals = mir_eval.util.boundaries_to_intervals(boundary_times)[0]
    score = mir_eval.segment.boundary_detection(truth_intervals,
                                                pred_intervals)[-1]

    return score
Example #4
0

if __name__ == '__main__':

    parameters = process_arguments()

    # Load the features
    print('- ', os.path.basename(parameters['input_song']))

    X, Y, beats = features(parameters['input_song'])
    # Load the transformation
    W = segmenter.load_transform(parameters['transform'])
    print('\tapplying transformation...')
    X = W.dot(X)

    # Find the segment boundaries
    print('\tpredicting segments...')
    if parameters['gnostic']:
        S = segmenter.get_segments(X, kmin=len(Y) - 1, kmax=len(Y))
    elif parameters['dynamic']:
        kmin, kmax = get_num_segs(beats[-1])
        S = segmenter.get_segments(X, kmin=kmin, kmax=kmax)
    else:
        S = segmenter.get_segments(X)

    # Output lab file
    print('\tsaving output to ', parameters['output_file'])
    segmenter.save_segments(parameters['output_file'], S, beats)

    pass
Example #5
0
    return vars(parser.parse_args(sys.argv[1:]))

if __name__ == '__main__':

    parameters = process_arguments()

    # Load the features
    print('- ', os.path.basename(parameters['input_song']))

    X, Y, beats    = features(parameters['input_song'])
    # Load the transformation
    W           = segmenter.load_transform(parameters['transform'])
    print('\tapplying transformation...')
    X           = W.dot(X)

    # Find the segment boundaries
    print('\tpredicting segments...')
    if parameters['gnostic']:
        S           = segmenter.get_segments(X, kmin=len(Y)-1, kmax=len(Y))
    elif parameters['dynamic']:
        kmin, kmax  = get_num_segs(beats[-1])
        S           = segmenter.get_segments(X, kmin=kmin, kmax=kmax)
    else:
        S           = segmenter.get_segments(X)

    # Output lab file
    print('\tsaving output to ', parameters['output_file'])
    segmenter.save_segments(parameters['output_file'], S, beats)

    pass