shithub: opus

Download patch

ref: 477d08734d8d716b8875df490787c6b8b59656f6
parent: d93239e955d67fe6d1b0cbb3880307af11abf7f7
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Fri Nov 23 18:33:35 EST 2018

Dump embedding

--- a/dnn/dump_lpcnet.py
+++ b/dnn/dump_lpcnet.py
@@ -42,7 +42,6 @@
     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 @@
     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 @@
     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:
@@ -95,6 +92,18 @@
     hf.write('extern const MDenseLayer {};\n\n'.format(name));
     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)
--- a/dnn/lpcnet.py
+++ b/dnn/lpcnet.py
@@ -102,7 +102,7 @@
     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))
--