27 lines
989 B
Python
27 lines
989 B
Python
|
import numpy as np
|
||
|
import tensorflow as tf
|
||
|
from keras.layers import Input, Dense, Conv2D
|
||
|
from keras.models import Model
|
||
|
import settings
|
||
|
|
||
|
#model
|
||
|
input_shape = settings.midi_resolution*128
|
||
|
input_img = tf.keras.layers.Input(shape=(input_shape,))
|
||
|
encoded = tf.keras.layers.Dense(160, activation='relu')(input_img)
|
||
|
decoded = tf.keras.layers.Dense(input_shape, activation='sigmoid')(encoded)
|
||
|
autoencoder = tf.keras.models.Model(input_img, decoded)
|
||
|
|
||
|
autoencoder.compile(optimizer='adadelta',
|
||
|
loss='categorical_crossentropy',
|
||
|
metrics=['accuracy'])
|
||
|
|
||
|
# load weights into new model
|
||
|
autoencoder.load_weights(settings.model_path)
|
||
|
print("Loaded model from {}".format(settings.model_path))
|
||
|
|
||
|
# generate_seed = np.random.rand(12288).reshape(1,12288)
|
||
|
generate_seed = np.load(settings.samples_path)['arr_0'][15].reshape(1,12288)
|
||
|
|
||
|
generated_sample = autoencoder.predict(generate_seed)
|
||
|
np.savez_compressed(settings.generated_sample_path, generated_sample)
|