Пример #1
0
import numpy as np
import librosa
import feature_extraction
import pretty_midi
import deepdish
import jams
import os
import glob
import joblib
import subprocess
import whoosh_search
import collections
import shutil

# Pre-load the MSD index as a list
MSD_IDX = whoosh_search.get_whoosh_index(
    os.path.join('..', 'data', 'msd', 'index'))
with MSD_IDX.searcher() as searcher:
    MSD_LIST = dict((e['id'], e) for e in searcher.documents())
# Threshold above which alignments are considered correct
SCORE_THRESHOLD = .5


def interpolate_times(times,
                      old_timebase,
                      new_timebase,
                      labels=None,
                      shift_start=False):
    '''
    Linearly interpolate a set of times (and optionally labels) to a new
    timebase.  All returned times will fall within the range of
    ``new_timebase``, and only times which fall within ``old_timebase`` will be
Пример #2
0
    sequence = sequence.reshape(
            sequence.shape[0]/window, window, sequence.shape[-1])
    # Compute mean over the window dimension
    return sequence.mean(axis=1)

if __name__ == '__main__':
    # Load in training data for computing mean for thresholding
    training_data = collections.defaultdict(list)
    for f in glob.glob(os.path.join(
            RESULTS_PATH, 'training_dataset', 'train', 'h5', '*.h5')):
        for k, v in deepdish.io.load(f).items():
            training_data[k].append(v)
    # Build networks and output-computing functions
    for dataset, network in zip(['clean_midi', 'msd'], ['X', 'Y']):
        # Get file list from whoosh index
        index = whoosh_search.get_whoosh_index(
            os.path.join(DATA_PATH, dataset, 'index'))
        with index.searcher() as searcher:
            file_list = list(searcher.documents())
        # We only need to hash MIDI files from the dev or test sets
        if dataset == 'clean_midi':
            md5s = [line.split(',')[0]
                    for pair_file in [
                        os.path.join(RESULTS_PATH, 'dev_pairs.csv'),
                        os.path.join(RESULTS_PATH, 'test_pairs.csv')]
                    for line in open(pair_file)
                    if line.split(',')[1] == 'msd']
            file_list = [e for e in file_list if e['id'] in md5s]
        # Compute the mean of the feature dimensions over the training set for
        # thresholding
        input_mean = np.mean(
            np.concatenate(training_data[network], axis=1), axis=1)
Пример #3
0
import deepdish
import numpy as np

RESULTS_PATH = '../../results'
DATA_PATH = '../../data'
# Should we use the test set or development set?
SPLIT = 'dev'
# A DP score above this means the alignment is correct
SCORE_THRESHOLD = .5
# Skip any hash sequences shorter than this
MIN_SEQUENCE_LENGTH = 30


if __name__ == '__main__':
    # Load in list of MSD entries
    msd_index = whoosh_search.get_whoosh_index(
        os.path.join(DATA_PATH, 'msd', 'index'))
    with msd_index.searcher() as searcher:
        msd_list = list(searcher.documents())

    # Load in list of MSD entries
    midi_index = whoosh_search.get_whoosh_index(
        os.path.join(DATA_PATH, 'clean_midi', 'index'))
    with midi_index.searcher() as searcher:
        midi_list = list(searcher.documents())

    # Load MSD embeddings
    msd_embedding_datas = experiment_utils.load_precomputed_data(
        msd_list, os.path.join(RESULTS_PATH, 'pse_msd_embeddings'))
    # Load in hash sequences (and metadata) for all MSD entries
    msd_sequence_datas = experiment_utils.load_precomputed_data(
        msd_list, os.path.join(RESULTS_PATH, 'dhs_msd_hash_sequences'))
        {
            'id': unicode(n),
            'artist': row[1],
            'title': row[3],
            # Must remove .mp3 from the path to get generic path
            'path': row[4].replace('.mp3', '')
        } for n, row in enumerate(uspop2002_list)
    ]
    whoosh_search.create_index(
        os.path.join(BASE_DATA_PATH, 'uspop2002', 'index'), uspop2002_list)

# Quick test
artist = 'bon jovi'
title = 'livin on a prayer'

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'cal500', 'index'))
with index.searcher() as searcher:
    print 'cal500:\t{}'.format(
        whoosh_search.search(searcher, index.schema, artist, title))

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'cal10k', 'index'))
with index.searcher() as searcher:
    print 'cal10k:\t{}'.format(
        whoosh_search.search(searcher, index.schema, artist, title))

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'msd', 'index'))
with index.searcher() as searcher:
    print 'msd:\t{}'.format(
        whoosh_search.search(searcher, index.schema, artist, title))
Пример #5
0
    output_filename = mp3_filename.replace('mp3', 'h5')
    # Skip files already created
    if skip and os.path.exists(output_filename):
        return
    try:
        # Load audio and compute CQT
        audio_data, _ = librosa.load(
            mp3_filename, sr=feature_extraction.AUDIO_FS)
        cqt = feature_extraction.audio_cqt(audio_data)
        # Create subdirectories if they don't exist
        if not os.path.exists(os.path.split(output_filename)[0]):
            os.makedirs(os.path.split(output_filename)[0])
        # Save CQT
        deepdish.io.save(output_filename, {'gram': cqt})
    except Exception as e:
        print "Error processing {}: {}".format(
            mp3_filename, traceback.format_exc(e))

if __name__ == '__main__':
    # Load in all msd entries from whoosh index
    index = whoosh_search.get_whoosh_index(
        os.path.join(BASE_DATA_PATH, 'msd', 'index'))
    with index.searcher() as searcher:
        msd_list = list(searcher.documents())
    # Create list of mp3 file paths
    mp3_files = [os.path.join(BASE_DATA_PATH, 'msd', 'mp3', e['path'] + '.mp3')
                 for e in msd_list]
    joblib.Parallel(n_jobs=10, verbose=51)(
        joblib.delayed(process_one_file)(mp3_filename)
        for mp3_filename in mp3_files)
Пример #6
0
if __name__ == '__main__':
    # Load in all parameter optimization trials
    trial_files = glob.glob(
        os.path.join(RESULTS_PATH, 'pse_parameter_trials', '*.h5'))
    trials = [deepdish.io.load(f) for f in trial_files]
    # Get the hyperparameters for the trial with the lowest objective value
    best_trial = sorted(trials, key=lambda t: t['best_objective'])[0]
    hyperparameters = best_trial['hyperparameters']
    # Load in the pre-trained parameters for the best performing models
    network_params = deepdish.io.load(
        os.path.join(RESULTS_PATH, 'pse_model', 'best_model.h5'))
    # Build networks and output-computing functions
    for dataset, network in zip(['clean_midi', 'msd'], ['X', 'Y']):
        # Get file list from whoosh index
        index = whoosh_search.get_whoosh_index(
            os.path.join(DATA_PATH, dataset, 'index'))
        with index.searcher() as searcher:
            file_list = list(searcher.documents())
        # We only need to hash MIDI files from the dev or test sets
        if dataset == 'clean_midi':
            md5s = [
                line.split(',')[0] for pair_file in [
                    os.path.join(RESULTS_PATH, 'dev_pairs.csv'),
                    os.path.join(RESULTS_PATH, 'test_pairs.csv')
                ] for line in open(pair_file) if line.split(',')[1] == 'msd'
            ]
            file_list = [e for e in file_list if e['id'] in md5s]
        # Construct the network according to best-trial hyperparameters
        if hyperparameters['network'] == 'pse_big_filter':
            build_network = experiment_utils.build_pse_net_big_filter
        elif hyperparameters['network'] == 'pse_small_filters':
Пример #7
0
import numpy as np
import librosa
import feature_extraction
import pretty_midi
import deepdish
import jams
import os
import glob
import joblib
import subprocess
import whoosh_search
import collections
import shutil

# Pre-load the MSD index as a list
MSD_IDX = whoosh_search.get_whoosh_index(
    os.path.join('..', 'data', 'msd', 'index'))
with MSD_IDX.searcher() as searcher:
    MSD_LIST = dict((e['id'], e) for e in searcher.documents())
# Threshold above which alignments are considered correct
SCORE_THRESHOLD = .5


def interpolate_times(times, old_timebase, new_timebase, labels=None,
                      shift_start=False):
    '''
    Linearly interpolate a set of times (and optionally labels) to a new
    timebase.  All returned times will fall within the range of
    ``new_timebase``, and only times which fall within ``old_timebase`` will be
    interpolated.

    Parameters
Пример #8
0
Collect groups of same-song MIDI files and match them to groups of same-song
audio files
'''
import sys
sys.path.append('..')
import whoosh_search
import json
import os

# The datasets to match MIDIs against
DATASETS = ['cal10k', 'cal500', 'uspop2002', 'msd']
BASE_DATA_PATH = '../data'
RESULTS_PATH = '../results'

# Load in list of MIDI files
midi_index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'clean_midi', 'index'))
with midi_index.searcher() as searcher:
    midi_list = list(searcher.documents())

# Create dict of whoosh indices
indices = {}
for dataset in DATASETS:
    # Load in whoosh index for this dataset
    indices[dataset] = whoosh_search.get_whoosh_index(
        os.path.join(BASE_DATA_PATH, dataset, 'index'))

pairs = []


def merge_entries(indices):
    '''
Пример #9
0
import joblib
import deepdish
import numpy as np

RESULTS_PATH = '../../results'
DATA_PATH = '../../data'
# Should we use the test set or development set?
SPLIT = 'dev'
# A DP score above this means the alignment is correct
SCORE_THRESHOLD = .5
# Skip any hash sequences shorter than this
MIN_SEQUENCE_LENGTH = 30

if __name__ == '__main__':
    # Load in list of MSD entries
    msd_index = whoosh_search.get_whoosh_index(
        os.path.join(DATA_PATH, 'msd', 'index'))
    with msd_index.searcher() as searcher:
        msd_list = list(searcher.documents())

    # Load in list of MSD entries
    midi_index = whoosh_search.get_whoosh_index(
        os.path.join(DATA_PATH, 'clean_midi', 'index'))
    with midi_index.searcher() as searcher:
        midi_list = list(searcher.documents())

    # Load MSD embeddings
    msd_embedding_datas = experiment_utils.load_precomputed_data(
        msd_list, os.path.join(RESULTS_PATH, 'pse_msd_embeddings'))
    # Load in hash sequences (and metadata) for all MSD entries
    msd_sequence_datas = experiment_utils.load_precomputed_data(
        msd_list, os.path.join(RESULTS_PATH, 'dhs_msd_hash_sequences'))
Пример #10
0
if not os.path.exists(os.path.join(BASE_DATA_PATH, 'uspop2002', 'index')):
    uspop2002_list = get_sv_list(
        os.path.join(FILE_LIST_PATH, 'uspop2002.txt'))
    uspop2002_list = [{'id': unicode(n), 'artist': row[1], 'title': row[3],
                       # Must remove .mp3 from the path to get generic path
                       'path': row[4].replace('.mp3', '')}
                      for n, row in enumerate(uspop2002_list)]
    whoosh_search.create_index(
        os.path.join(BASE_DATA_PATH, 'uspop2002', 'index'), uspop2002_list)

# Quick test
artist = 'bon jovi'
title = 'livin on a prayer'

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'cal500', 'index'))
with index.searcher() as searcher:
    print 'cal500:\t{}'.format(whoosh_search.search(searcher, index.schema,
                                        artist, title))

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'cal10k', 'index'))
with index.searcher() as searcher:
    print 'cal10k:\t{}'.format(whoosh_search.search(searcher, index.schema,
                                        artist, title))

index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'msd', 'index'))
with index.searcher() as searcher:
    print 'msd:\t{}'.format(whoosh_search.search(searcher, index.schema,
                                                 artist, title))
Пример #11
0
Collect groups of same-song MIDI files and match them to groups of same-song
audio files
'''
import sys
sys.path.append('..')
import whoosh_search
import json
import os

# The datasets to match MIDIs against
DATASETS = ['cal10k', 'cal500', 'uspop2002', 'msd']
BASE_DATA_PATH = '../data'
RESULTS_PATH = '../results'

# Load in list of MIDI files
midi_index = whoosh_search.get_whoosh_index(
    os.path.join(BASE_DATA_PATH, 'clean_midi', 'index'))
with midi_index.searcher() as searcher:
    midi_list = list(searcher.documents())

# Create dict of whoosh indices
indices = {}
for dataset in DATASETS:
    # Load in whoosh index for this dataset
    indices[dataset] = whoosh_search.get_whoosh_index(
        os.path.join(BASE_DATA_PATH, dataset, 'index'))

pairs = []


def merge_entries(indices):
    '''