Ejemplo n.º 1
0
 def __init__(self):
     algorithm_number = 18
     alg = (1.0 / 32.0) * float(algorithm_number - 1) + 0.001
     a = 4
     overriden_parameters = [(0, 1.0), (1, 0.0), (2, 1.0), (3, 0.0),
                             (a, alg)]
     other_params = [((i + 5), 0.5) for i in range(17)]
     operator_one = [((i + 23), 0.0) for i in range(22)]
     operator_two = [((i + 45), 0.0) for i in range(22)]
     operator_thr = [((i + 67), 0.0) for i in range(22)]
     operator_fou = [((i + 89), 0.0) for i in range(22)]
     operator_fiv = [((i + 111), 0.0) for i in range(22)]
     operator_six = [((i + 133), 0.0) for i in range(22)]
     # overriden_parameters.extend(operator_one)
     overriden_parameters.extend(operator_two)
     overriden_parameters.extend(operator_thr)
     overriden_parameters.extend(operator_fou)
     overriden_parameters.extend(operator_fiv)
     overriden_parameters.extend(operator_six)
     overriden_parameters.extend(other_params)
     self.extractor = PluginFeatureExtractor(
         midi_note=24,
         note_length_secs=0.4,
         render_length_secs=0.7,
         overriden_parameters=overriden_parameters,
         pickle_path=
         "/home/tollie/Development/TensorFlowSynthProgrammers/utils/normalisers/",
         warning_mode="ignore",
         normalise_audio=False)
     path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
     self.extractor.load_plugin(path)
     (features, parameters) = self.extractor.get_random_normalised_example()
     self.action_space = spaces.Discrete(len(parameters) * 2 + 1)
     self.inaction = len(parameters) * 2
     shape = (features.flatten().shape[0], )
     self.observation_space = spaces.Box(np.zeros(shape), np.ones(shape))
     self.reward = 0.0
     self.reward_range = (0, 1)
     self.reward_threshold = 0.90
     self.parameter_alpha = 0.05
     self.features = None
     self.parameters = None
     self.done = False
     self.step_number = 0
     self.step_threshold = 450
     self.patch_average_out_amount = 4
# overriden_parameters.extend(operator_two)
# overriden_parameters.extend(operator_thr)
# overriden_parameters.extend(operator_fou)
# overriden_parameters.extend(operator_fiv)
# overriden_parameters.extend(operator_six)
overriden_parameters.extend(other_params)

# overriden_parameters = np.load("data/fm/overriden_parameters.npy").tolist()
# desired_features = np.load("data/fm/desired_features.npy").tolist()

desired_features = [0, 1, 6]
desired_features.extend([i for i in range(8, 21)])
extractor = PluginFeatureExtractor(midi_note=24,
                                   note_length_secs=0.4,
                                   desired_features=desired_features,
                                   overriden_parameters=overriden_parameters,
                                   render_length_secs=0.7,
                                   pickle_path="utils/normalisers",
                                   warning_mode="ignore",
                                   normalise_audio=False)

# print np.array(extractor.overriden_parameters)

path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
# path = "/home/tollie/Development/vsts/synths/granulator/Builds/build-granulator-Desktop-Debug/build/debug/granulator.so"
# path = "/home/tollie/Downloads/synths/FMSynth/Builds/LinuxMakefile/build/FMSynthesiser.so"

extractor.load_plugin(path)

if extractor.need_to_fit_normalisers():

    print "No normalisers found, fitting new ones."
Ejemplo n.º 3
0
training_iters = 20
batch_size = 32
number_hidden = 256
np.random.seed(8)
checkpoint = 'model3.tfl.ckpt-361000'
data_folder = "data/fm/"

overriden_parameters = np.load(data_folder +
                               "overriden_parameters.npy").tolist()
desired_features = np.load(data_folder + "desired_features.npy").tolist()
print "Features amount: " + str(len(desired_features))

extractor = PluginFeatureExtractor(midi_note=24,
                                   note_length_secs=0.4,
                                   desired_features=desired_features,
                                   overriden_parameters=overriden_parameters,
                                   render_length_secs=0.7,
                                   pickle_path="utils/normalisers",
                                   warning_mode="ignore",
                                   normalise_audio=False)
path = "/home/tollie/Downloads/synths/FMSynth/Builds/LinuxMakefile/build/FMSynthesiser.so"
# path = "/home/tollie/Development/vsts/synths/granulator/Builds/build-granulator-Desktop-Debug/build/debug/granulator.so"
extractor.load_plugin(path)

if extractor.need_to_fit_normalisers():
    extractor.fit_normalisers(10000)

(features, parameters) = extractor.get_random_normalised_example()

if training:

    def unison_shuffled_copies(a, b):
Ejemplo n.º 4
0
h_3_flat = tf.reshape(h_3, [-1, 64 * 4 * 4])
prediction = linear(h_3_flat, 10)


def error(labels, prediction):
    return tf.sqrt(tf.reduce_mean(tf.square(tf.sub(labels, prediction))))


rmse = error(y, prediction)
optimise = tf.train.AdamOptimizer(1e-4).minimize(rmse)

# Load VST.
extractor = PluginFeatureExtractor(midi_note=24,
                                   note_length_secs=0.4,
                                   desired_features=[i for i in range(8, 21)],
                                   render_length_secs=0.7,
                                   pickle_path="utils/normalisers",
                                   warning_mode="ignore",
                                   normalise_audio=False)
path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
extractor.load_plugin(path)

# Get training and testing batch.
train_batch_x = np.load("train_x.npy")
train_batch_y = np.load("train_y.npy")
test_batch_x = np.load("test_x.npy")
test_batch_y = np.load("test_y.npy")

sess = tf.Session()
sess.run(tf.global_variables_initializer())
import tensorflow as tf
import numpy as np
from tqdm import trange
import sys
sys.path.append('/home/tollie/Development/TensorFlowSynthProgrammers/utils/')

from plugin_feature_extractor import PluginFeatureExtractor
from tensorflow.contrib import rnn

extractor = PluginFeatureExtractor(midi_note=24, note_length_secs=0.8,
                                   render_length_secs=1.8,
                                   pickle_path="/home/tollie/Development/TensorFlowSynthProgrammers/utils/normalisers/",
                                   warning_mode="ignore")

path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
extractor.load_plugin(path)

if extractor.need_to_fit_normalisers():
    extractor.fit_normalisers(1)

(features, parameters) = extractor.get_random_normalised_example()

learning_rate = 0.001
training_iters = 400000
batch_size = 128
train_size = 20000
display_step = 100
save_step = 100
number_hidden = 100
number_layers = 3
Ejemplo n.º 6
0
class DexedVstEnv(gym.Env):

    metadata = {'render.modes': ['features_array', 'spectrograms']}

    def __init__(self):
        algorithm_number = 18
        alg = (1.0 / 32.0) * float(algorithm_number - 1) + 0.001
        a = 4
        overriden_parameters = [(0, 1.0), (1, 0.0), (2, 1.0), (3, 0.0),
                                (a, alg)]
        other_params = [((i + 5), 0.5) for i in range(17)]
        operator_one = [((i + 23), 0.0) for i in range(22)]
        operator_two = [((i + 45), 0.0) for i in range(22)]
        operator_thr = [((i + 67), 0.0) for i in range(22)]
        operator_fou = [((i + 89), 0.0) for i in range(22)]
        operator_fiv = [((i + 111), 0.0) for i in range(22)]
        operator_six = [((i + 133), 0.0) for i in range(22)]
        # overriden_parameters.extend(operator_one)
        overriden_parameters.extend(operator_two)
        overriden_parameters.extend(operator_thr)
        overriden_parameters.extend(operator_fou)
        overriden_parameters.extend(operator_fiv)
        overriden_parameters.extend(operator_six)
        overriden_parameters.extend(other_params)
        self.extractor = PluginFeatureExtractor(
            midi_note=24,
            note_length_secs=0.4,
            render_length_secs=0.7,
            overriden_parameters=overriden_parameters,
            pickle_path=
            "/home/tollie/Development/TensorFlowSynthProgrammers/utils/normalisers/",
            warning_mode="ignore",
            normalise_audio=False)
        path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
        self.extractor.load_plugin(path)
        (features, parameters) = self.extractor.get_random_normalised_example()
        self.action_space = spaces.Discrete(len(parameters) * 2 + 1)
        self.inaction = len(parameters) * 2
        shape = (features.flatten().shape[0], )
        self.observation_space = spaces.Box(np.zeros(shape), np.ones(shape))
        self.reward = 0.0
        self.reward_range = (0, 1)
        self.reward_threshold = 0.90
        self.parameter_alpha = 0.05
        self.features = None
        self.parameters = None
        self.done = False
        self.step_number = 0
        self.step_threshold = 450
        self.patch_average_out_amount = 4

    def _reset(self):
        (features, parameters) = self.extractor.get_random_normalised_example()
        self.target_parameters = parameters
        self.target_features = features
        self.target_audio = self.extractor.get_audio_frames()
        self.done = False
        self.reward = 0.0
        self.step_number = 0
        self.parameters = np.zeros_like(parameters)
        self.get_average_features()
        return self.get_observation()

    def _step(self, action):
        assert self.action_space.contains(
            action), "%r (%s) invalid" % (action, type(action))
        self.increment_step_count()
        if action == self.inaction or self.done:
            return self.get_observation(
            ), self.reward, self.done, self.get_info()
        else:
            increment = self.parameter_alpha if action % 2 == 0 else -self.parameter_alpha
            action = int(np.floor(float(action) / 2.0))
            self.parameters[action] += increment
            self.parameters[action] = max(0.0, min(self.parameters[action],
                                                   1.0))
            self.get_average_features()
            self.get_reward()
            if self.reward >= self.reward_threshold:
                self.done = True
            return self.get_observation(
            ), self.reward, self.done, self.get_info()

    def get_stats(self):
        return (self.parameters, self.features, self.target_parameters,
                self.target_features)

    def get_reward(self):
        feature_difference = np.subtract(self.target_features, self.features)
        abs_difference = np.absolute(feature_difference)
        summed_difference = np.sum(abs_difference)
        normalised_difference = summed_difference / self.features.size
        reversed_normalised_distance = 1.0 - normalised_difference
        self.reward = reversed_normalised_distance * 2.0 - 1.0

    def get_observation(self):
        return self.target_features - self.features

    def get_info(self):
        info = {
            'parameters': self.parameters,
            'features': self.features,
            'target_parameters': self.target_parameters,
            'target_features': self.target_features,
            'reward': self.reward
        }
        return info

    def get_average_features(self):
        patch = self.extractor.partial_patch_to_patch(self.parameters)
        patch = self.extractor.add_patch_indices(patch)
        self.features = self.extractor.get_features_from_patch(patch)
        for i in range(self.patch_average_out_amount):
            self.features += self.extractor.get_features_from_patch(patch)
        self.features /= (self.patch_average_out_amount + 1)

    def increment_step_count(self):
        if self.step_number > self.step_threshold:
            self.done = True
            self.step_number = 0
        self.step_number += 1

    def _render(self, mode='features_array', close=False):
        if mode == 'features_array':
            return self.features
        elif mode == 'spectrograms':
            fig = plt.figure(0)
            fig.suptitle('Actual Patch', fontsize=14, fontweight='bold')
            plt.xlabel('Time')

            plt.ylabel('Frequency')
            plt.specgram(self.extractor.get_audio_frames(), NFFT=256, Fs=256)
            fig = plt.figure(1)
            fig.suptitle('Target Patch', fontsize=14, fontweight='bold')
            plt.xlabel('Time')
            plt.ylabel('Frequency')
            plt.specgram(self.target_audio, NFFT=256, Fs=256)
            return fig
        else:
            super(DexedVstEnv, self).render(mode=mode)

    def _seed(self, seed=8):
        np.random.seed(seed)
        return [seed]
Ejemplo n.º 7
0
from mlp import MLP
from mlp_recursive import RecursiveMLP
from rnn import LSTM
from ga import GeneticAlgorithm
from plugin_feature_extractor import PluginFeatureExtractor
import tensorflow as tf
import numpy as np
from utility_functions import *
from tqdm import trange

# Load VST.
extractor = PluginFeatureExtractor(
    midi_note=24,
    note_length_secs=0.4,
    #desired_features=[i for i in range(8, 21)],
    render_length_secs=0.7,
    pickle_path="utils/normalisers",
    warning_mode="ignore",
    normalise_audio=True)
path = "/home/tollie/Development/vsts/dexed/Builds/Linux/build/Dexed.so"
extractor.load_plugin(path)

if extractor.need_to_fit_normalisers():
    extractor.fit_normalisers(2000000)

# Get training and testing batch.
test_batch_size = 100
train_batch_size = 1000
train_batch_x, train_batch_y, test_batch_x, test_batch_y = get_batches(
    train_batch_size, test_batch_size, extractor)
# FM
overriden_parameters = []

data_folder = "data/fm/"

desired_features = [0, 1, 6]
desired_features.extend([i for i in range(8, 21)])

with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=DeprecationWarning)

    extractor = PluginFeatureExtractor(
        midi_note=24,
        note_length_secs=0.4,
        desired_features=desired_features,
        overriden_parameters=overriden_parameters,
        render_length_secs=0.7,
        pickle_path="utils/normalisers",
        warning_mode="ignore",
        normalise_audio=False)
    # Granulator
    # path = "/home/tollie/Development/vsts/synths/granulator/Builds/build-granulator-Desktop-Debug/build/debug/granulator.so"

    path = "/home/tollie/Downloads/synths/FMSynth/Builds/LinuxMakefile/build/FMSynthesiser.so"
    extractor.load_plugin(path)

    all_patches = np.load(data_folder + "all_patches.npy")
    all_x = []
    all_y = []

    step = 3