-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with TF2.0 #16
Comments
I've created a separate branch generates MDN layers functionally, and is working with tf2.0 saving/loading |
Hey @andySigler - this looks great! I'm not quite ready to move to tf2.0 yet, so I haven't played around with it, but is everything working? re Not sure that I want to move to tf2.0 until it's the stable release, but at that time, I'll probably think about pulling all your changes in and moving forward from there. |
I found mdn works well both on # self.trainable_weights = self.mdn_mus.trainable_weights + self.mdn_sigmas.trainable_weights + self.mdn_pi.trainable_weights
# self.non_trainable_weights = self.mdn_mus.non_trainable_weights + self.mdn_sigmas.non_trainable_weights + self.mdn_pi.non_trainable_weights In In import pickle
# get weights
with open('mdn_weights.pkl', 'wb') as f:
weights = model.get_weights()
pickle.dump(weights, f, pickle.HIGHEST_PROTOCOL)
# set weights
with open('mdn_weights.pkl', 'rb') as f:
weights = pickle.load(f)
model.set_weights(weights) |
Hi, @DeviLeo this tracks, so far model.save() is not properly implemented. |
Hi, @cpmpercussion, @andySigler from tensorflow import keras
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Input, Dense, concatenate
from tensorflow.keras.models import Model
def mdn_network(x, output_dimension, num_mixtures):
''' Define the network of mdn '''
mdn_mus = Dense(num_mixtures * output_dimension, name='mdn_mus') # mix*output vals, no activation
mdn_sigmas = Dense(num_mixtures * output_dimension, activation=elu_plus_one_plus_epsilon, name='mdn_sigmas') # mix*output vals exp activation
mdn_pi = Dense(num_mixtures, name='mdn_pi') # mix vals, logits
mdn_out = concatenate([mdn_mus(x), mdn_sigmas(x), mdn_pi(x)], name='mdn_outputs')
return mdn_out
def MDN(input_shape, output_dimension, num_mixtures):
""" `input_shape` should be the shape without the batch dimension. """
mdn_input = Input(input_shape)
mdn_output = mdn_network(mdn_input, output_dimension, num_mixtures)
mdn_model = Model(mdn_input, mdn_output)
return mdn_model Test codes below
Notice from tensorflow import keras
output_dimension, num_mixes = 1, 5
input = keras.layers.Input((4, 100)) # input.shape is (None, 4, 100)
output = mdn.MDN(input.shape[1:], output_dimension, num_mixes)(input) # input_shape should be (4, 100)
model = keras.Model(input, output)
model.compile(loss=mdn.get_mixture_loss_func(output_dimension, num_mixes), optimizer=keras.optimizers.Adam())
model.save('test_mdn.h5')
model.save('test_mdn_saved_model', 'tf') |
@DeviLeo, you can certainly do it that way and great if that approach works for you! I guess I'm focused on using the Layer API (hence the name of this repo), so I will try to keep things within a Layer subclass. |
Just for those in this thread, I have a branch called |
I've now merged the |
Hi and thanks for this MDN abstraction and NIME paper. Below is more of a feature request than an issue.
Have you thought of making your MDN layer work with TF2.0?
I am relatively new to TF and attempting to port your work to 2.0, you can see the changes I've made here. It seems to be working, except I am unable to save the model using
model.save()
, I get the errorUnable to create link (name already exists)
If you have any thoughts, suggestions that would greatly appreciated as I'm pretty lost with that error ¯_(ツ)_/¯
The text was updated successfully, but these errors were encountered: