From 477d08734d8d716b8875df490787c6b8b59656f6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 23 Nov 2018 23:33:35 -0500 Subject: [PATCH] Dump embedding --- dnn/dump_lpcnet.py | 15 ++++++++++++--- dnn/lpcnet.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dnn/dump_lpcnet.py b/dnn/dump_lpcnet.py index f3556740..b1047460 100755 --- a/dnn/dump_lpcnet.py +++ b/dnn/dump_lpcnet.py @@ -42,7 +42,6 @@ def dump_gru_layer(self, f, hf): printVector(f, weights[0], name + '_weights') printVector(f, weights[1], name + '_recurrent_weights') printVector(f, weights[-1], name + '_bias') - #activation = re.search('function (.*) at', str(layer.activation)).group(1).upper() if hasattr(self, 'activation'): activation = self.activation.__name__.upper() else: @@ -65,7 +64,6 @@ def dump_dense_layer(self, f, hf): weights = self.get_weights() printVector(f, weights[0], name + '_weights') printVector(f, weights[-1], name + '_bias') - #activation = re.search('function (.*) at', str(layer.activation)).group(1).upper() if hasattr(self, 'activation'): activation = self.activation.__name__.upper() else: @@ -84,7 +82,6 @@ def dump_mdense_layer(self, f, hf): printVector(f, weights[0], name + '_weights') printVector(f, weights[1], name + '_bias') printVector(f, weights[1], name + '_factor') - #activation = re.search('function (.*) at', str(layer.activation)).group(1).upper() if hasattr(self, 'activation'): activation = self.activation.__name__.upper() else: @@ -96,6 +93,18 @@ def dump_mdense_layer(self, f, hf): return False MDense.dump_layer = dump_mdense_layer +def dump_embedding_layer(self, f, hf): + name = self.name + print("printing layer " + name + " of type " + self.__class__.__name__) + weights = self.get_weights() + printVector(f, weights[0], name + '_weights') + f.write('const EmbeddingLayer {} = {{\n {}_weights,\n {}, {}\n}};\n\n' + .format(name, name, weights[0].shape[0], weights[0].shape[1])) + hf.write('#define {}_SIZE {}\n'.format(name.upper(), weights[0].shape[1])) + hf.write('extern const EmbeddingLayer {};\n\n'.format(name)); + return False +Embedding.dump_layer = dump_embedding_layer + model, _, _ = lpcnet.new_lpcnet_model(rnn_units1=640, use_gpu=False) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy']) diff --git a/dnn/lpcnet.py b/dnn/lpcnet.py index 54a714f0..3ab340c8 100644 --- a/dnn/lpcnet.py +++ b/dnn/lpcnet.py @@ -102,7 +102,7 @@ def new_lpcnet_model(rnn_units1=384, rnn_units2=16, nb_used_features = 38, use_g embed2 = Embedding(256, embed_size, embeddings_initializer=PCMInit(), name='embed_exc') cexc = Reshape((-1, embed_size))(embed2(exc)) - pembed = Embedding(256, 64) + pembed = Embedding(256, 64, name='embed_pitch') cat_feat = Concatenate()([feat, Reshape((-1, 64))(pembed(pitch))]) cfeat = fconv2(fconv1(cat_feat))