shithub: opus

Download patch

ref: b2940ed212229475d1431962d88af334926f4f24
parent: 9fd3e45fd3d6565f467c6353e48240778def22aa
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue Jan 22 11:55:02 EST 2019

Use real features at the chunk edges rather than zeros

--- a/dnn/lpcnet.py
+++ b/dnn/lpcnet.py
@@ -113,7 +113,7 @@
             'seed': self.seed
         }
 
-def new_lpcnet_model(rnn_units1=384, rnn_units2=16, nb_used_features = 38, use_gpu=True):
+def new_lpcnet_model(rnn_units1=384, rnn_units2=16, nb_used_features = 38, training=False, use_gpu=True):
     pcm = Input(shape=(None, 3))
     feat = Input(shape=(None, nb_used_features))
     pitch = Input(shape=(None, 1))
@@ -121,8 +121,9 @@
     dec_state1 = Input(shape=(rnn_units1,))
     dec_state2 = Input(shape=(rnn_units2,))
 
-    fconv1 = Conv1D(128, 3, padding='same', activation='tanh', name='feature_conv1')
-    fconv2 = Conv1D(128, 3, padding='same', activation='tanh', name='feature_conv2')
+    padding = 'valid' if training else 'same'
+    fconv1 = Conv1D(128, 3, padding=padding, activation='tanh', name='feature_conv1')
+    fconv2 = Conv1D(128, 3, padding=padding, activation='tanh', name='feature_conv2')
 
     embed = Embedding(256, embed_size, embeddings_initializer=PCMInit(), name='embed_sig')
     cpcm = Reshape((-1, embed_size*3))(embed(pcm))
--- a/dnn/test_lpcnet.py
+++ b/dnn/test_lpcnet.py
@@ -40,7 +40,7 @@
 config.gpu_options.per_process_gpu_memory_fraction = 0.2
 set_session(tf.Session(config=config))
 
-model, enc, dec = lpcnet.new_lpcnet_model()
+model, enc, dec = lpcnet.new_lpcnet_model(use_gpu=False)
 
 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
 #model.summary()
@@ -63,7 +63,7 @@
 
 
 
-model.load_weights('lpcnet20g_384_10_G16_02.h5')
+model.load_weights('lpcnet20h_384_10_G16_80.h5')
 
 order = 16
 
--- a/dnn/train_lpcnet.py
+++ b/dnn/train_lpcnet.py
@@ -51,7 +51,7 @@
 # Try reducing batch_size if you run out of memory on your GPU
 batch_size = 64
 
-model, _, _ = lpcnet.new_lpcnet_model()
+model, _, _ = lpcnet.new_lpcnet_model(training=True)
 
 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
 model.summary()
@@ -89,6 +89,11 @@
 features = features[:, :, :nb_used_features]
 features[:,:,18:36] = 0
 
+fpad1 = np.concatenate([features[0:1, 0:2, :], features[:-1, -2:, :]], axis=0)
+fpad2 = np.concatenate([features[1:, :2, :], features[0:1, -2:, :]], axis=0)
+features = np.concatenate([fpad1, features, fpad2], axis=1)
+
+
 periods = (.1 + 50*features[:,:,36:37]+100).astype('int16')
 
 in_data = np.concatenate([sig, pred, in_exc], axis=-1)
@@ -98,7 +103,7 @@
 del in_exc
 
 # dump models to disk as we go
-checkpoint = ModelCheckpoint('lpcnet20g_384_10_G16_{epoch:02d}.h5')
+checkpoint = ModelCheckpoint('lpcnet20h_384_10_G16_{epoch:02d}.h5')
 
 #model.load_weights('lpcnet9b_384_10_G16_01.h5')
 model.compile(optimizer=Adam(0.001, amsgrad=True, decay=5e-5), loss='sparse_categorical_crossentropy')
--