Ejemplo n.º 1
0
def build_pump(sr,
               hop_length,
               n_fft,
               n_mels,
               n_t_constants=10,
               save_pump=None):
    pcen_t = PCEN_T(name='PCEN',
                    sr=sr,
                    hop_length=hop_length,
                    n_t_constants=n_t_constants)

    p_tag = pumpp.task.StaticLabelTransformer(name='static',
                                              namespace='tag_open',
                                              labels=URBANSED_CLASSES)

    p_dtag = pumpp.task.DynamicLabelTransformer(name='dynamic',
                                                namespace='tag_open',
                                                labels=URBANSED_CLASSES,
                                                sr=sr,
                                                hop_length=hop_length)
    pump = pumpp.Pump(pcen_t, p_tag, p_dtag)

    if save_pump is not None:
        with open(os.path.join(save_pump, 'pump.pkl'), 'wb') as fd:
            pickle.dump(pump, fd)

    return pump
Ejemplo n.º 2
0
def make_pump(sr, hop_length, n_fft, n_mels):

    p_feature = pumpp.feature.Mel(name='mel',
                                  sr=sr,
                                  hop_length=hop_length,
                                  n_fft=n_fft,
                                  n_mels=n_mels,
                                  log=True,
                                  conv='tf')

    p_tag = pumpp.task.StaticLabelTransformer(name='static',
                                              namespace='tag_open',
                                              labels=DCASE_CLASSES)

    p_dtag = pumpp.task.DynamicLabelTransformer(name='dynamic',
                                                namespace='tag_open',
                                                labels=DCASE_CLASSES,
                                                sr=sr,
                                                hop_length=hop_length)

    pump = pumpp.Pump(p_feature, p_tag, p_dtag)

    # Save the pump
    with open(os.path.join(OUTPUT_PATH, 'pump.pkl'), 'wb') as fd:
        pickle.dump(pump, fd)

    return pump
Ejemplo n.º 3
0
def make_pump(sr, hop_length, n_octaves):
    p_feature = pumpp.feature.CQTMag(name='cqt',
                                     sr=sr,
                                     hop_length=hop_length,
                                     log=True,
                                     conv='tf',
                                     n_octaves=n_octaves)

    p_chord_tag = pumpp.task.ChordTagTransformer(name='chord_tag',
                                                 sr=sr,
                                                 hop_length=hop_length,
                                                 sparse=True)

    p_chord_struct = pumpp.task.ChordTransformer(name='chord_struct',
                                                 sr=sr,
                                                 hop_length=hop_length,
                                                 sparse=True)

    pump = pumpp.Pump(p_feature, p_chord_tag, p_chord_struct)

    # Save the pump

    with open(os.path.join(OUTPUT_PATH, 'pump.pkl'), 'wb') as fd:
        pickle.dump(pump, fd)

    return pump
Ejemplo n.º 4
0
def data(ops):

    audio_f = 'tests/data/test.ogg'
    jams_f = 'tests/data/test.jams'

    P = pumpp.Pump(*ops)
    return P.transform(audio_f=audio_f, jam=jams_f)
Ejemplo n.º 5
0
def test_pump_badkey(sr, hop_length):

    op = pumpp.feature.STFT(name='stft',
                            sr=sr,
                            hop_length=hop_length,
                            n_fft=2 * hop_length)

    P = pumpp.Pump(op)

    P['bad key']
Ejemplo n.º 6
0
def test_pump_add_twice(sr, hop_length):

    op = pumpp.feature.STFT(name='stft',
                            sr=sr,
                            hop_length=hop_length,
                            n_fft=2 * hop_length)

    P = pumpp.Pump()

    P.add(op)
    P.add(op)
Ejemplo n.º 7
0
def get_pump(sr=p.SAMPLE_RATE, n_mels=p.NUM_MEL_BINS):

    mel = pumpp.feature.Mel(name='mel',
                            sr=sr,
                            n_mels=n_mels,
                            n_fft=2048,
                            hop_length=512,
                            log=True,
                            conv='tf')

    return pumpp.Pump(mel)
Ejemplo n.º 8
0
Archivo: pump.py Proyecto: mtuit/VGGish
def get_pump(sr=p.SAMPLE_RATE,
             n_fft_secs=p.STFT_WINDOW_LENGTH_SECONDS,
             hop_length_secs=p.STFT_HOP_LENGTH_SECONDS,
             n_mels=p.NUM_MEL_BINS,
             fmax=p.MEL_MAX_HZ):

    mel = pumpp.feature.Mel(name='mel',
                            sr=sr,
                            n_mels=n_mels,
                            n_fft=int(n_fft_secs * sr),
                            hop_length=int(hop_length_secs * sr),
                            fmax=fmax,
                            log=True,
                            conv='tf')

    return pumpp.Pump(mel)
Ejemplo n.º 9
0
def test_pump_sampler(sr, hop_length, n_samples, duration, rng):
    ops = [
        pumpp.feature.STFT(name='stft',
                           sr=sr,
                           hop_length=hop_length,
                           n_fft=2 * hop_length),
        pumpp.task.BeatTransformer(name='beat', sr=sr, hop_length=hop_length)
    ]

    P = pumpp.Pump(*ops)

    S1 = pumpp.Sampler(n_samples, duration, random_state=rng, *ops)
    S2 = P.sampler(n_samples, duration, random_state=rng)

    assert S1._time == S2._time
    assert S1.n_samples == S2.n_samples
    assert S1.duration == S2.duration
Ejemplo n.º 10
0
def create_pump_object():

    (bins_per_octave, n_octaves, harmonics, sr, f_min, hop_length,
     over_sample) = get_hcqt_params()

    p_phdif = pumpp.feature.HCQTPhaseDiff(name='dphase',
                                          sr=sr,
                                          hop_length=hop_length,
                                          fmin=f_min,
                                          n_octaves=n_octaves,
                                          over_sample=over_sample,
                                          harmonics=harmonics,
                                          log=True)

    pump = pumpp.Pump(p_phdif)

    return pump
Ejemplo n.º 11
0
def test_pump_repr_html(sr, hop_length):

    ops = [
        pumpp.feature.STFT(name='stft',
                           sr=sr,
                           hop_length=hop_length,
                           n_fft=2 * hop_length),
        pumpp.task.BeatTransformer(name='beat', sr=sr, hop_length=hop_length),
        pumpp.task.ChordTransformer(name='chord', sr=sr,
                                    hop_length=hop_length),
        pumpp.task.StaticLabelTransformer(name='tags',
                                          namespace='tag_open',
                                          labels=['rock', 'jazz'])
    ]

    pump = pumpp.Pump(*ops)

    assert isinstance(pump._repr_html_(), str)
Ejemplo n.º 12
0
def test_pump_add(sr, hop_length):

    ops = [
        pumpp.feature.STFT(name='stft',
                           sr=sr,
                           hop_length=hop_length,
                           n_fft=2 * hop_length),
        pumpp.task.BeatTransformer(name='beat', sr=sr, hop_length=hop_length),
        pumpp.task.ChordTransformer(name='chord', sr=sr,
                                    hop_length=hop_length),
        pumpp.task.StaticLabelTransformer(name='tags',
                                          namespace='tag_open',
                                          labels=['rock', 'jazz'])
    ]

    pump = pumpp.Pump()
    assert pump.ops == []

    for op in ops:
        pump.add(op)
        assert op in pump.ops
Ejemplo n.º 13
0
def make_pump(sr, hop_length, n_fft, n_mels):
    p_feature = pumpp.feature.Mel(name='mel',
                                  sr=sr,
                                  hop_length=hop_length,
                                  n_fft=n_fft,
                                  n_mels=n_mels,
                                  log=True,
                                  conv='tf')

    p_beat = pumpp.task.BeatTransformer(name='beat',
                                        sr=sr,
                                        hop_length=hop_length)

    pump = pumpp.Pump(p_feature, p_beat)

    # Save the pump

    with open(os.path.join(OUTPUT_PATH, 'pump.pkl'), 'wb') as fd:
        pickle.dump(pump, fd)

    return pump
Ejemplo n.º 14
0
def test_pump_layers(sr, hop_length):
    ops = [
        pumpp.feature.STFT(name='stft',
                           sr=sr,
                           hop_length=hop_length,
                           n_fft=2 * hop_length),
        pumpp.feature.CQT(name='cqt', sr=sr, hop_length=hop_length),
        pumpp.task.BeatTransformer(name='beat', sr=sr, hop_length=hop_length)
    ]

    P = pumpp.Pump(*ops)

    L1 = P.layers()
    L2 = dict()
    L2.update(ops[0].layers())
    L2.update(ops[1].layers())

    assert L1.keys() == L2.keys()

    for k in L1:
        assert L1[k].dtype == L2[k].dtype
        for d1, d2 in zip(L1[k].shape, L2[k].shape):
            assert str(d1) == str(d2)
Ejemplo n.º 15
0
def test_pump(audio_f, jam, y, sr, sr2, hop_length, crop):

    ops = [
        pumpp.feature.STFT(name='stft',
                           sr=sr,
                           hop_length=hop_length,
                           n_fft=2 * hop_length),
        pumpp.task.BeatTransformer(name='beat', sr=sr, hop_length=hop_length),
        pumpp.task.ChordTransformer(name='chord', sr=sr,
                                    hop_length=hop_length),
        pumpp.task.StaticLabelTransformer(name='tags',
                                          namespace='tag_open',
                                          labels=['rock', 'jazz'])
    ]

    P = pumpp.Pump(*ops)

    if audio_f is None and y is None:
        # no input
        with pytest.raises(pumpp.ParameterError):
            data = P.transform(audio_f=audio_f, jam=jam, y=y, sr=sr2)
    elif y is not None and sr2 is None:
        # input buffer, but no sampling rate
        y = librosa.load(y, sr=sr2)[0]
        with pytest.raises(pumpp.ParameterError):
            data = P.transform(audio_f=audio_f, jam=jam, y=y, sr=sr2)
    elif y is not None:
        y = librosa.load(y, sr=sr2)[0]
        data = P.transform(audio_f=audio_f, jam=jam, y=y, sr=sr2)
    else:

        fields = set([
            'stft/mag', 'stft/phase', 'beat/beat', 'beat/downbeat',
            'beat/mask_downbeat', 'chord/pitch', 'chord/root', 'chord/bass',
            'tags/tags'
        ])

        valids = set(['beat/_valid', 'chord/_valid', 'tags/_valid'])

        assert set(P.fields.keys()) == fields

        data = P.transform(audio_f=audio_f, jam=jam, y=y, sr=sr2, crop=crop)
        data2 = P(audio_f=audio_f, jam=jam, y=y, sr=sr2, crop=crop)

        # Fields we should have:
        assert set(data.keys()) == fields | valids

        # time shapes should be the same for annotations
        assert data['beat/beat'].shape[1] == data['beat/downbeat'].shape[1]
        assert data['beat/beat'].shape[1] == data['chord/pitch'].shape[1]
        assert data['beat/beat'].shape[1] == data['chord/root'].shape[1]
        assert data['beat/beat'].shape[1] == data['chord/bass'].shape[1]

        # Audio features can be off by at most a frame
        if crop:
            assert data['stft/mag'].shape[1] == data['beat/beat'].shape[1]
            assert data['stft/mag'].shape[1] == data['chord/pitch'].shape[1]
        else:
            assert (np.abs(data['stft/mag'].shape[1] -
                           data['beat/beat'].shape[1]) * hop_length /
                    float(sr)) <= 0.05

        assert data.keys() == data2.keys()
        for k in data:
            assert np.allclose(data[k], data2[k])
Ejemplo n.º 16
0
def test_pump_empty(audio_f, jam, sr, hop_length):

    pump = pumpp.Pump()
    data = pump.transform(audio_f, jam)
    assert data == dict()
Ejemplo n.º 17
0
def test_pump_add_bad():

    pumpp.Pump('foo')
Ejemplo n.º 18
0
p_feature = pumpp.feature.CQTMag(name='cqt',
                                 sr=sr,
                                 hop_length=hop_length,
                                 log=True,
                                 conv='tf',
                                 n_octaves=6)
p_chord_tag = pumpp.task.ChordTagTransformer(name='chord_tag',
                                             sr=sr,
                                             hop_length=hop_length,
                                             sparse=True)
p_chord_struct = pumpp.task.ChordTransformer(name='chord_struct',
                                             sr=sr,
                                             hop_length=hop_length,
                                             sparse=True)

pump = pumpp.Pump(p_feature, p_chord_tag, p_chord_struct)

# Save the pump
with open('pump.pkl', 'wb') as fd:
    pickle.dump(pump, fd)


# Transformation with CQT
def convert(aud, pump, outdir):
    data = pump.transform(aud)
    fname = os.path.extsep.join([root(aud), 'npz'])
    np.savez(os.path.join(outdir, fname), **data)


OUTDIR = 'pump/'
#%%