コード例 #1
0
def predict_one(items, outs, model_names, config):
    data, bpm_label, beat_label, downbeat_label, song_name = items
    import matplotlib.pyplot as plt
    # plt.imshow(data[0].T, aspect=20, origin="lower")
    # plt.show()
    # plt.savefig("/home/ooyama/melspectrogram.pdf")
    # exit()
    bpmgram, beat, downbeat = outs
    # plt.plot(softmax(bpmgram))
    # plt.show()
    # plot_tempogram(bpmgram)
    bpm = np.argmax(softmax(bpmgram), axis=-1)
    print(bpm.shape, beat.shape)
    plot_beat_and_bpm2(
        {
            "beat": (1, beat),
            "beat_label": (2, beat_label),
            "downbeat": (3, downbeat),
            # "downbeatlabel": (4, downbeat_label),
        },
        song_name,
        model_names,
        time_range=(2500, 3500),
        bpm_range=(50, 200),
    )
コード例 #2
0
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()
コード例 #3
0
def predict_one(items, outs, model_names, config):
    data, beattheta, downbeat_label, song_name = items
    # theta, idxs = numpy_fft(outs[None, :] * 2 * np.pi, 100)

    plot_beat_and_bpm2(
        # beat=outs,
        # beat_label=downbeat_label,
        # theta[0],
        {"downbeat": outs, "downbeat_label": downbeat_label, "beat_label":beattheta},
        # {"before": outs, "after": theta[0]},
        song_name=song_name,
        model_names=model_names,
        time_range=(0, 6000),
    )
コード例 #4
0
def predict_one(items, outs, model_names, config):
    data, bpm_label, beat_label, song_name = items
    bpmgram, beat = outs
    bpmgram = bpmgram.T
    # plot_tempogram(bpmgram)
    bpm = np.argmax(bpmgram, axis=-1)
    print(bpm.shape, beat.shape)
    plot_beat_and_bpm2(
        {"beat": (1, beat)},
        song_name,
        model_names,
        time_range=(0000, 1000),
        bpm_range=(50, 200),
    )
コード例 #5
0
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),
    )
コード例 #6
0
def predict_one(items, outs, model_names, config):
    data, beattheta, bpm_label, song_name = items
    theta, f_logsoftmax = outs
    f_logsoftmax = torch.from_numpy(f_logsoftmax)
    bpm_label = torch.from_numpy(bpm_label)
    # theta, idxs = numpy_fft(outs[None, :] * 2 * np.pi, 100)
    f_label = get_bpm_label(bpm_label[None, :], f_logsoftmax[None, :])[0]
    # exit()
    plot_beat_and_bpm2(
        # theta[0],
        {"beat": theta, "beat_label": beattheta},
        # {"beat": np.sin(theta*2*np.pi)},
        # {"a": f_label[2000], "before": torch.exp(f_logsoftmax[2000]),},
        song_name=song_name,
        model_names=model_names,
        # time_range=(0, 6000),
    )
コード例 #7
0
def predict_one(items, outs, model_names, config):
    data, bpm_label, beattheta_label, downbeattheta_label, song_name = items
    beattheta_out, downbeattheta_out, deltabeat_out, deltadownbeat_out = outs
    diffbeattheta = medfilt(deltabeat_out, kernel_size=21)
    beattheta_out = np.argmax(beattheta_out.T, axis=-1) / 6000
    downbeattheta_out = np.argmax(downbeattheta_out.T, axis=-1) / 6000
    activation = beattheta_out[:-1] - beattheta_out[1:]
    activation[activation <= 0] = 1e-6
    bpm_out = diffbeattheta * 3000 / np.pi
    plot_beat_and_bpm2(
        {
            "beat": (1, beattheta_out),
            "beat_label": (2, beattheta_label),
            "downbeat": (3, downbeattheta_out),
            # "bpm": (4, bpm_out),
        },
        song_name,
        model_names,
        time_range=(2500, 3500),
        bpm_range=(50, 200),
    )