def predict_one(items, outs, model_names, config):
    data, beattheta, bpm_label, song_name = items
    theta, idxs = numpy_fft(outs[None, :] * 2 * np.pi, 100)

    plot_beat_and_bpm2(
        # theta[0],
        # {"beat": outs, "beat_label": beattheta},
        {
            "before": outs,
            "after": theta[0]
        },
        song_name=song_name,
        model_names=model_names,
        time_range=(0, 6000),
    )
    k = 200
    sin = np.sin(outs * 2 * np.pi)
    spectrogram = [
        np.abs(np.fft.fft(sin[i:i + k]))[:k // 2]
        for i in range(outs.shape[0] - k)
    ]
    spectrogram = np.stack(spectrogram)
    # plt.plot(np.abs(np.fft.fft(sin))[:3000])
    print(np.argmax(spectrogram[4]))
    plt.imshow(spectrogram.T, aspect=40, origin="lower")
    # plt.plot(spectrogram[5])
    plt.show()
Exemple #2
0
def evaluate(items, outs, config, trial=None):
    # eval_beat = EvaluateBeat(estimated_type="index", target_type="activation")
    eval_downbeat = EvaluateDownbeat(
        estimated_type="activation", target_type="activation")

    data, beat_label, downbeattheta_label = items
    theta, idxs = numpy_fft(outs * 2 * np.pi, 100)
    # act = (outs[:, :-1] - outs[:, 1:]) / (2 * np.pi)
    # act[act <= 0] = 1e-5
    beat_metrics = eval_downbeat.batch(outs, downbeattheta_label)

    ret = {"beat": beat_metrics}
    return ret
def predict_one(items, outs, model_names, config):
    data, beattheta, downbeat_label, song_name = items
    beat, downbeat = outs
    plt.plot(beat)
    plt.plot(downbeat)
    plt.show()
    theta, idxs = numpy_fft(beat[None, :] * 2 * np.pi, 400)
    plot_beat_and_bpm2(
        # theta[0],
        {"beat": beat, "downbeat_label": downbeat_label, "downbeat": downbeat},
        # {"downbeat": theta[0]/2/np.pi, "label": beattheta},
        song_name=song_name,
        model_names=model_names,
        time_range=(0, 6000),
    )
def predict_one(items, outs, model_names, config):
    data, bpm_label, beattheta, song_name = items
    beattheta_out, diffbeattheta = outs
    diffbeattheta = medfilt(diffbeattheta, kernel_size=21)
    beattheta_out = np.argmax(beattheta_out.T, axis=-1) / 6000
    theta = numpy_fft(beattheta_out[None, :] * 2 * np.pi, 100)
    theta /= 2 * np.pi
    activation = beattheta_out[:-1] - beattheta_out[1:]
    activation[activation <= 0] = 1e-6
    bpm_out = diffbeattheta * 3000 / np.pi
    # plot_beat_and_bpm(
    #     theta[0], beattheta, bpm_label, bpm_out, song_name, model_names,
    # )
    plt.plot(np.sin(beattheta_out * 2 * np.pi))
    # plt.plot(theta[0], alpha=0.7)
    plt.plot(np.sin(beattheta * 2 * np.pi), alpha=0.7)
    plt.show()