Exemplo n.º 1
0
def ingest_all():
    data = [
        zounds.InternetArchive('AOC11B'),
        zounds.InternetArchive('Greatest_Speeches_of_the_20th_Century'),
        zounds.InternetArchive('Kevin_Gates_-_By_Any_Means-2014'),
        zounds.PhatDrumLoops()
    ]
    for d in data:
        zounds.ingest(d, Sound, multi_threaded=True)
Exemplo n.º 2
0
from client import Client
import requests
import urllib
from io import BytesIO
from log import module_logger
from pathlib import Path
import zounds
from bot_helper import BotDriver
from urllib.parse import urlparse

logger = module_logger(__file__)

datasets = [

    # Classical
    zounds.InternetArchive('AOC11B'),
    zounds.InternetArchive('CHOPINBallades-NEWTRANSFER'),
    zounds.InternetArchive('beethoven_ingigong_850'),
    zounds.InternetArchive('jamendo-086440'),
    zounds.InternetArchive('The_Four_Seasons_Vivaldi-10361'),

    # Pop
    zounds.InternetArchive('02.LostInTheShadowsLouGramm'),
    zounds.InternetArchive('08Scandalous'),
    zounds.InternetArchive('09.JoyceKennedyDidntITellYou'),
    zounds.InternetArchive('02.InThisCountryRobinZander'),
    zounds.InternetArchive('PeterGabrielOutOut'),
    zounds.InternetArchive('07.SpeedOfLightJoeSatriani'),

    # Jazz
    zounds.InternetArchive('Free_20s_Jazz_Collection'),
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--epochs',
        help='how many epochs (full passes over data) should the network train',
        default=100,
        type=int)
    parser.add_argument(
        '--force',
        help='retrain the network, even if its already been trained',
        action='store_true',
        default=False)

    args = parser.parse_args()

    zounds.ingest(
        zounds.InternetArchive('Greatest_Speeches_of_the_20th_Century'),
        Sound,
        multi_threaded=True)

    def generate_training_and_test_set():
        snds = list(Sound)

        # get all sounds where Nixon is the speaker
        nixon = filter(lambda snd: 'Nixon' in snd.meta['artist'], snds)

        # get an equal number of speeches by anyone besides Nixon
        not_nixon = filter(lambda snd: 'Nixon' not in snd.meta['artist'],
                           snds)[:len(nixon)]

        for snd in nixon:
            yield dict(data=snd.rasterized,
Exemplo n.º 4
0
                model.parameters(), lr=0.0002, betas=(0.5, 0.999)),
            discriminator_optim_func=lambda model: optim.Adam(
                model.parameters(), lr=0.00005, betas=(0.5, 0.999)),
            latent_dimension=(LATENT_DIM, ),
            epochs=500,
            batch_size=64),
        needs=scaled,
        store=False)

    pipeline = ff.PickleFeature(zounds.PreprocessingPipeline,
                                needs=(mu_law, scaled, network),
                                store=True)


if __name__ == '__main__':
    zounds.ingest(zounds.InternetArchive('AOC11B'), Sound, multi_threaded=True)

    if not GanPipeline.exists():
        GanPipeline.process(docs=(snd.rasterized for snd in Sound))

    gan = GanPipeline()
    noise = np.random.normal(0, 1, (32, LATENT_DIM))
    generated_samples = gan.pipeline.transform(noise)

    # start up an in-browser REPL to interact with the results
    app = zounds.ZoundsApp(model=Sound,
                           audio_feature=Sound.ogg,
                           visualization_feature=Sound.bark,
                           globals=globals(),
                           locals=locals())
    app.start(8888)
                        type=str,
                        help='the internet archive id to use for training')
    parser.add_argument('--epochs',
                        type=int,
                        help='the number of epochs to train the network')
    parser.add_argument(
        '--force-train',
        action='store_true',
        help='re-train the network, even if it has already been trained')
    parser.add_argument('--categorical',
                        action='store_true',
                        help='use a categorical distribution of samples')
    args = parser.parse_args()

    if args.internet_archive_id:
        zounds.ingest(zounds.InternetArchive(args.internet_archive_id),
                      Sound,
                      multi_threaded=True)

    if args.categorical:
        network = CategoricalAutoEncoder()
        loss = CategoricalLoss()
        synthesize = categorical_synthesize
        pipeline_cls = CategoricalAutoEncoderPipeline
        data_preprocessor = label_preprocessor = preprocess_categorical
        batch_size = 16
    else:
        network = RawSamplesAutoEncoder()
        loss = FrequencyBandLoss()
        synthesize = raw_samples_synthesize
        pipeline_cls = AutoEncoderPipeline
Exemplo n.º 6
0
    encoded = zounds.ArrayWithUnitsFeature(zounds.Learned,
                                           learned=FreqAdaptiveAutoEncoder(),
                                           needs=freq_adaptive,
                                           store=False)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--internet-archive-id',
                        help='the internet archive id to process',
                        type=str,
                        required=False,
                        default='AOC11B')
    args = parser.parse_args()

    zounds.ingest(dataset=zounds.InternetArchive(args.internet_archive_id),
                  cls=Sound,
                  multi_threaded=True)

    # train the pipeline, including the autoencoder
    if not FreqAdaptiveAutoEncoder.exists():
        FreqAdaptiveAutoEncoder.process(docs=(snd.freq_adaptive
                                              for snd in Sound))

    # get a reference to the trained pipeline
    autoencoder = FreqAdaptiveAutoEncoder()

    # get references to all the sounds.  features are lazily
    # loaded/evaluated, so this is a cheap operation
    snds = list(Sound)
Exemplo n.º 7
0
        packed, [x.dimensions[0], zounds.IdentityDimension()])


@zounds.simple_lmdb_settings('hamming_index',
                             map_size=1e11,
                             user_supplied_id=True)
class Sound(BaseModel):

    fake_hash = zounds.ArrayWithUnitsFeature(produce_fake_hash,
                                             needs=BaseModel.fft,
                                             store=True)


if __name__ == '__main__':

    zounds.ingest(zounds.InternetArchive('Kevin_Gates_-_By_Any_Means-2014'),
                  Sound,
                  multi_threaded=True)

    def web_url(doc, ts):
        return doc.meta['web_url']

    def total_duration(doc, ts):
        return doc.fake_hash.dimensions[0].end / zounds.Seconds(1)

    index = zounds.HammingIndex(Sound,
                                Sound.fake_hash,
                                path='fake_hash_index',
                                web_url=web_url,
                                total_duration=total_duration)