Exemplo n.º 1
0
def cpu(*F, N=(500, 5000, 500)):
    '''Mostra gráfico com o consumo de tempo das funções *F, para
       entradas com tamanho variando no intervalo N=(500,5000,500).
       Um parâmetro E = g define a função que gera as entradas'''
    C = ['r', 'b', 'g', 'c', 'm', 'y', 'k', 'w']
    M = ['o', 's', 'p', 'h', '+', 'x', 'v', '^']
    X = []
    Y = [[] for _ in range(len(F))]
    print('n = ', end='')
    inicio = time()
    rodada = 1
    for n in range(N[0], N[1] + 1, N[2]):
        print('%s ' % rodada, end='')
        X.append(n)
        v = sample(range(0, n), n)
        for i, f in enumerate(F):
            w = deepcopy(v)
            Y[i].append(tempo(f, w))
        rodada += 1
    print('\nTempo total: %.1fs' % (time() - inicio))
    xlabel('tamanho da entrada')
    ylabel('tempo de execução (s)')
    ticklabel_format(style='sci', axis='both', scilimits=(-3, +4))
    grid(True)
    for i, f in enumerate(F):
        plot(X,
             Y[i],
             color=C[i % len(C)],
             marker=M[i % len(M)],
             label=f.__name__)
    legend(loc='upper left')
    show()
Exemplo n.º 2
0
        # Read the labeled tempo
        bpm = float(utils.read_tempofile(DB, f))
        print('ground-truth tempo: ', bpm)
        label.append(bpm)

        # Estimate a static tempo
        sr, y = utils.read_wav(f)

        hop_length = 512
        oenv = librosa.onset.onset_strength(y=y, sr=sr, hop_length=hop_length)

        # tempogram = librosa.feature.tempogram(onset_envelope=oenv, sr=sr, hop_length=hop_length)

        # predict the tempo1(slower one), tempo2(faster one)
        # tempo1, tempo2 = librosa.beat.tempo(onset_envelope=oenv, sr=sr, hop_length=hop_length)
        tempo1, tempo2 = utils.tempo(onset_envelope=oenv, sr=sr, hop_length=hop_length)
        pred_t1.append(tempo1)
        pred_t2.append(tempo2)
        print(tempo1, tempo2)

        # p score
        s1 = tempo1/(tempo1+tempo2)
        s2 = 1.0 - s1
        print(s1, s2)
        p = s1 * utils.P_score(tempo1, bpm) + s2 * utils.P_score(tempo2, bpm)
        p_score.append(p)

        # ALOTC score
        ALOTC = utils.ALOTC(tempo1, tempo2, bpm)
        ALOTC_score.append(ALOTC)
Exemplo n.º 3
0
def executar_teste(t):  #t=(função, lista)
    print('processando %s com uma lista de %d' % (t[0].__name__, len(t[1])))
    return tempo(t[0], t[1])
def beat_estimate(DB,GENRE,fout,name="***** Q1 *****\n",multi=1,method="own"):
    genres_p, genres_ALOTC = list(), list()
    for genre in GENRE:
        print('GENRE:', genre)
        FILES = glob(DB + '/wav/' + genre + '/*.wav')
        label, p_score, ALOTC_score = list(), list(), list()

        for f in FILES:
            f = f.replace('\\', '/')
            #print('FILE:', f)

            # Read the labeled tempo
            bpm = float(utils.read_tempofile(DB, genre, f))
            #print('ground-truth tempo: ', bpm)
            label.append(bpm)
            
            if method=="own":
                # Estimate a static tempo
                sr, y = utils.read_wav(f)
                hop_length = 512
                oenv = librosa.onset.onset_strength(y=y, sr=sr, hop_length=hop_length)
                # predict the tempo1(slower one), tempo2(faster one)
                tempo1, tempo2 = utils.tempo(onset_envelope=oenv, sr=sr, hop_length=hop_length)
            elif method=="madmom":
                # madmom estimate tempo
                proc = madmom.features.tempo.TempoEstimationProcessor(fps=100)
                act = madmom.features.beats.RNNBeatProcessor()(f)
                tempo1 = (proc(act)).astype(float)[0][0].item()
                tempo2 = (proc(act)).astype(float)[1][0].item()
            # Q2
            tempo1 = tempo1*multi
            tempo2 = tempo2*multi

            # p score
            s1 = tempo1/(tempo1+tempo2)
            s2 = 1.0 - s1
            #print(s1, s2)
            p = s1 * utils.P_score(tempo1, bpm) + s2 * utils.P_score(tempo2, bpm)
            p_score.append(p)

            # ALOTC score
            ALOTC = utils.ALOTC(tempo1, tempo2, bpm)
            ALOTC_score.append(ALOTC)

            #print(p, ALOTC)

        p_avg = sum(p_score)/len(p_score)
        ALOTC_avg = sum(ALOTC_score)/len(ALOTC_score)
        genres_p.append(p_avg)
        genres_ALOTC.append(ALOTC_avg)
        print('finished : ',genre)

    print(genres_p)
    print(genres_ALOTC)
    fout.write(name)
    fout.write("Genre          \tP-score    \tALOTC score\n")
    for genre in range(len(GENRE)):
        fout.write("{:13s}\t{:8.2f}\t{:8.2f}\n".format(GENRE[genre], genres_p[genre], genres_ALOTC[genre]))
    fout.write('----------\n')
    fout.write("Overall P-score:\t{:.2f}\n".format(sum(genres_p)/len(genres_p)))
    fout.write("Overall ALOTC score:\t{:.2f}\n".format(sum(genres_ALOTC)/len(genres_ALOTC)))