Exemple #1
0
def main():
    print 'Generating the training model...'
    training_model = get_training_model()

    print 'Compiling the training model...'
    optimizer = Adadelta(lr=0.01, epsilon=1e-6)
    training_model.compile(loss=objective,
                           optimizer=optimizer,
                           metrics=['accuracy'])

    print 'Retrieving the repository...'
    pieces = repository_handler.load_repository(args.repository)

    print 'Learning...'
    train(training_model, pieces)

    print 'Retrieving the weights...'
    weights = training_model.get_weights()

    print 'Generating the composition model...'
    composition_model = get_composition_model()

    print 'Compiling the composition model...'
    composition_model.compile(loss=objective, optimizer=optimizer)

    print 'Setting the weights...'
    composition_model.set_weights(weights)

    print 'Composing a piece...'
    random_batch, _ = piece_handler.get_piece_batch(pieces, 5)
    initial_note = random_batch[0][0].reshape((1, 78, 80))
    piece = compose_piece(composition_model, initial_note)
    piece_handler.save_piece(piece, args.piece)
Exemple #2
0
def main():
    print 'Retrieving the repository...'
    pieces = repository_handler.load_repository(args.repository)
    _, data = piece_handler.get_piece_batch(pieces, args.batch_size)

    print 'Generating Probability Matrix..'
    probability_matrix = get_probability_matrix(data)

    print 'Making Sweet Jams...'
    segment = generate_music(data[0, 0], probability_matrix,
                             args.segment_length)

    print 'Saving Sweet Jams...'
    piece_handler.save_piece(segment, args.file_path)
Exemple #3
0
def train(deep_jammer, pieces, epochs, batch_size):
    loss_history = []

    for epoch in xrange(epochs):
        loss = deep_jammer.update(*piece_handler.get_piece_batch(pieces, batch_size))

        loss_history.append(loss)

        if epoch % SUMMARY_THRESHOLD == 0:
            display_summary(epoch, batch_size, loss)

        if epoch % CHECKPOINT_THRESHOLD == 0:
            print 'Epoch %d -> Checkpoint' % epoch
            save_configuration(deep_jammer, epoch)
            save_loss_history(loss_history)

            piece = generate_piece(deep_jammer, pieces)
            save_generated_piece(piece, epoch)
def main():
    print 'Generating the composition model...'
    composition_model = deep_jammer.get_composition_model()

    print 'Compiling the composition model...'
    optimizer = Adam(lr=1)
    composition_model.compile(loss=objective, optimizer=optimizer, metrics=['accuracy'])

    print 'Loading the weights...'
    composition_model.load_weights('checkpoints/model-weights-40.h5')

    print 'Generating the initial note of the piece...'
    repository = repository_handler.load_repository('1-repository')
    X_train, _ = piece_handler.get_piece_batch(repository, 5)
    initial_note = X_train[0][0].reshape((1, 78, 80))

    print 'Generating a piece...'
    piece = compose_piece(composition_model, initial_note)
    piece_handler.save_piece(piece, 'checkpoint-piece')
Exemple #5
0
def train(model, pieces):
    loss_history = []

    for epoch in xrange(EPOCHS):
        print 'Training on epoch %s/%s...' % (epoch, EPOCHS)

        X, y = piece_handler.get_piece_batch(pieces, BATCH_SIZE)

        loss, _ = model.train_on_batch([X, y], y)
        print 'Loss =', loss

        loss_history.append(loss)

        if ARE_CHECKPOINTS_ENABLED and epoch % CHECKPOINT_THRESHOLD == 0:
            filename = '%s/model-weights-%s.h5' % (CHECKPOINT_DIRECTORY, epoch)
            model.save_weights(filename)

        if ARE_ACCURACIES_SAVED and epoch % ACCURACIES_THRESHOLD == 0:
            if IS_GPU_USED:
                filename = '%s/model-accuracies.txt' % ACCURACIES_DIRECTORY

                f = open(filename, 'w')
                for new_loss in loss_history:
                    f.write('%s\n' % new_loss)
            else:
                import matplotlib.pyplot as plt

                filename = '%s/model-accuracies.png' % ACCURACIES_DIRECTORY

                figure = plt.figure()
                plt.plot(loss_history)
                figure.suptitle('Loss Analysis')
                plt.xlabel('Iterations')
                plt.ylabel('Loss')

                figure.savefig(filename)