Ejemplo 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)
Ejemplo n.º 2
0
@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--local-path',
        required=True,
        type=str,
        help='local path where the nsynth tar files should be stored')
    parser.add_argument(
        '--port',
        default=8888,
        type=int,
        help='port to run the in-browser REPL in')
    args = parser.parse_args()

    ns = zounds.NSynth(path=args.local_path)
    zounds.ingest(ns, Sound, multi_threaded=True)

    app = zounds.ZoundsApp(
        model=Sound,
        audio_feature=Sound.ogg,
        visualization_feature=Sound.fft,
        globals=globals(),
        locals=locals())
    app.start(args.port)
Ejemplo n.º 3
0
        needs=WithOnsets.bark,
        store=True)

    pooled = zounds.VariableRateTimeSeriesFeature(
        zounds.Pooled,
        needs=(bark_kmeans, WithOnsets.slices),
        op=np.max,
        axis=0,
        store=True)


if __name__ == '__main__':
    index = zounds.HammingIndex(WithCodes, WithCodes.pooled, listen=True)

    zounds.ingest(
        zounds.PhatDrumLoops(),
        WithOnsets,
        multi_threaded=True)

    # learn K-Means centroids from the drum hits
    if not BarkKmeans.exists():
        print('learning K-Means clusters')
        BarkKmeans.process(docs=(wo.bark for wo in WithOnsets))

    # bark_kmeans = BarkKmeans()

    # force the new pooled feature to be computed
    for doc in WithCodes:
        print(doc.pooled.slicedata.shape)

    results = index.random_search(n_results=5)
Ejemplo n.º 4
0
    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 = [snd for snd in snds if 'Nixon' in snd.meta['artist']]

        # 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,
Ejemplo n.º 5
0
    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,
                       labels=np.ones((len(snd.rasterized), 1)))
Ejemplo n.º 6
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)
                        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
        data_preprocessor = label_preprocessor = lambda x: x
Ejemplo n.º 8
0
                                           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)

    # create a synthesizer that can invert the frequency adaptive representation
Ejemplo n.º 9
0

@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)
Ejemplo n.º 10
0
    args = parser.parse_args()

    new_id = most_recent_id()

    # try:
    #     cls = with_hash(new_id)
    # except NoTrainedModelException:
    #     cls = Sound

    cls = Sound

    # zounds.ingest(zounds.PhatDrumLoops(), cls, multi_threaded=True)
    #
    # for query in queries:
    #     fss = zounds.FreeSoundSearch(
    #         args.freesound_key, query, n_results=20, delay=1.0)
    #     zounds.ingest(fss, cls, multi_threaded=True)

    # for archive_id in internet_archive_ids:
    #     zounds.ingest(
    #         zounds.InternetArchive(archive_id=archive_id),
    #         cls,
    #         multi_threaded=True)
    #

    # mn = zounds.MusicNet(path='/home/user/Downloads')
    # zounds.ingest(mn, cls, multi_threaded=True)

    ns = zounds.NSynth(path='/home/user/Downloads')
    zounds.ingest(ns, cls, multi_threaded=True)
Ejemplo n.º 11
0

@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)

    if not len(index):
Ejemplo n.º 12
0
BaseModel = zounds.stft(resample_to=samplerate, store_fft=True)


@zounds.simple_in_memory_settings
class Sound(BaseModel):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--local-path',
        required=True,
        type=str,
        help='local path where the nsynth tar files should be stored')
    parser.add_argument('--port',
                        default=8888,
                        type=int,
                        help='port to run the in-browser REPL in')
    args = parser.parse_args()

    ns = zounds.NSynth(path=args.local_path)
    zounds.ingest(ns, Sound, multi_threaded=True)

    app = zounds.ZoundsApp(model=Sound,
                           audio_feature=Sound.ogg,
                           visualization_feature=Sound.fft,
                           globals=globals(),
                           locals=locals())
    app.start(args.port)
            epochs=20,
            batch_size=64,
            holdout_percent=0.5),
        needs=dict(data=scaled_source, labels=scaled_target),
        store=False)

    pipeline = ff.PickleFeature(
        zounds.PreprocessingPipeline,
        needs=(mu_law_source, scaled_source, network),
        store=True)


if __name__ == '__main__':

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

    if not FeatureTransfer.exists():
        FeatureTransfer.process(
            docs=(dict(data=doc.rasterized, labels=doc.freq_adaptive)
                  for doc in Sound))

    snds = list(Sound)
    snd = choice(snds)

    feature_transfer = FeatureTransfer()

    synth = zounds.FrequencyAdaptiveFFTSynthesizer(scale, samplerate)

    original = synth.synthesize(snd.freq_adaptive)
        '--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
        data_preprocessor = label_preprocessor = lambda x: x
Ejemplo n.º 15
0
        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)

    # create a synthesizer that can invert the frequency adaptive representation