Esempio n. 1
0
def train(hlayers, logpath, batch, epchs):
  model = K.Sequential()
  if len(hlayers) == 0:
    model.add(K.layers.Dense(tgt.shape[1], activation=act, input_shape=(ipt.shape[1],)))
  else:
    model.add(K.layers.Dense(hlayers[0], activation=act, input_shape=(ipt.shape[1],)))
    # model.add(K.layers.Dropout(0.01))
    for hn in hlayers[1:]:
      model.add(K.layers.Dense(hn, activation=act))
      # model.add(K.layers.Dropout(0.01))
    model.add(K.layers.Dense(tgt.shape[1], activation=act))
    # model.add(K.layers.Dropout(0.01))
  model.compile(loss='mean_squared_error', optimizer=opt)
  tb = K.callbacks.TensorBoard(logpath)
  K.utils.print_summary(model)
  history = model.fit(ipt, tgt, batch_size=batch, epochs=epchs, verbose=0, callbacks=[tb], shuffle=True)
  
  save_model(model, logpath, 'model')
  
  return model
Esempio n. 2
0
    names = names[shuffled_idx]
    for i in range(samples):  # for every sample
        batch_ipt = []
        batch_tgt = []
        for step in range(timesteps - channels - 1):
            batch_ipt.append(signals[i, step:step + channels])
            batch_tgt.append([signals[i, step + channels + 1]])
        batch_ipt = np.array(batch_ipt)
        batch_tgt = np.array(batch_tgt)
        batch_ipt = np.expand_dims(batch_ipt, 0)
        batch_tgt = np.expand_dims(batch_tgt, 0)
        batch_loss = model.train_on_batch(batch_ipt, batch_tgt)  ### TRAINNING
        loss.append([time.time() - initial_time, batch_loss])
        print('LOSS:', loss[-1][1], 'Time:', loss[-1][0])

save_model(model, path, 'model')
np.savetxt(path + 'loss.csv', np.array(loss), fmt='%.18e', delimiter=',')
P_model.set_weights(model.get_weights())
save_model(P_model, path, 'P_model')

for i in range(samples):
    seed = np.array(signals[i][0:channels])
    save_wav(max_amp * seed, name=path + 'seed_' + names[i] + '.wav')
    seed = np.expand_dims(seed, 0)
    seed = np.expand_dims(seed, 0)
    pred_wave = np.zeros(timesteps)
    for j in range(channels, timesteps):
        predicted = P_model.predict(seed)
        pred_wave[j] = predicted[0, 0, 0]
        seed = np.roll(seed, -1)
        seed[0, 0, channels - 1] = predicted[0, 0, 0]
Esempio n. 3
0
                        activation=act,
                        kernel_initializer=init,
                        bias_initializer=init)(layer)

model = K.models.Model(input, output)
K.utils.print_summary(model)
model.compile(loss='mean_squared_error', optimizer=opt)

tb = K.callbacks.TensorBoard(path + '/amplitudes')
history = model.fit(ipt,
                    tgt,
                    batch_size=ipt.shape[0],
                    epochs=epcs,
                    verbose=1,
                    callbacks=[tb],
                    shuffle=True)

save_model(model, path + '/amplitudes/', 'model')

pred = np.reshape(model.predict(complete_ipt), (-1, partials)) * (M - m) + m

print(m, M)

X = np.reshape(complete_ipt[:, 1], (-1, partials))
plt.plot(X, amplitudes, 'ko')
plt.plot(X, pred, 'r.')
plt.savefig(path + 'fractions_of_max_amps.png')
plt.close()

np.savetxt(path + 'fractions_of_max_amps.csv', pred, delimiter=',')
Esempio n. 4
0
                        activation=act,
                        kernel_initializer=init,
                        bias_initializer=init)(layer)

model = K.models.Model(input, output)
K.utils.print_summary(model)
model.compile(loss='mean_squared_error', optimizer=opt)

tb = K.callbacks.TensorBoard(path + '/decays')
history = model.fit(ipt,
                    tgt,
                    batch_size=ipt.shape[0],
                    epochs=epcs,
                    verbose=1,
                    callbacks=[tb],
                    shuffle=True)

save_model(model, path + '/decays/', 'model')

pred = np.reshape(model.predict(complete_ipt), (-1, partials)) * (M - m) + m

print(m, M)

np.savetxt(path + 'fractions_of_max_decays.csv', pred, delimiter=',')

X = np.reshape(complete_ipt[:, 1], (-1, partials))
plt.plot(X, decays, 'ko')
plt.plot(X, pred, 'r.')
plt.savefig(path + 'fractions_of_max_decays.png')
plt.close()
Esempio n. 5
0
                        activation=act,
                        kernel_initializer=init,
                        bias_initializer=init)(layer)

model = K.models.Model(input, output)
K.utils.print_summary(model)
model.compile(loss='mean_squared_error', optimizer=opt)

tb = K.callbacks.TensorBoard(path + '/frequencies')
history = model.fit(ipt,
                    tgt,
                    batch_size=ipt.shape[0],
                    epochs=epcs,
                    verbose=1,
                    callbacks=[tb],
                    shuffle=True)

save_model(model, path + '/frequencies/', 'model')

# tgt = (tgt - m) / (M - m)
pred = np.reshape(model.predict(complete_ipt), (-1, partials)) * (M - m) + m

print(m, M)

plt.plot(frequencies, 'ko')
plt.plot(pred, 'r.')
plt.savefig(path + 'Mfreqs_over_Tfreqs.png')
plt.close()

np.savetxt(path + 'Mfreqs_over_Tfreqs.csv', pred, delimiter=',')