def new_lpcnet_model(rnn_units1=384, rnn_units2=16, nb_used_features = 38, training=False, use_gpu=True, adaptation=False): pcm = Input(shape=(None, 3)) feat = Input(shape=(None, nb_used_features)) pitch = Input(shape=(None, 1)) dec_feat = Input(shape=(None, 128)) dec_state1 = Input(shape=(rnn_units1,)) dec_state2 = Input(shape=(rnn_units2,)) 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)) pembed = Embedding(256, 64, name='embed_pitch') cat_feat = Concatenate()([feat, Reshape((-1, 64))(pembed(pitch))]) cfeat = fconv2(fconv1(cat_feat)) fdense1 = Dense(128, activation='tanh', name='feature_dense1') fdense2 = Dense(128, activation='tanh', name='feature_dense2') cfeat = fdense2(fdense1(cfeat)) rep = Lambda(lambda x: K.repeat_elements(x, frame_size, 1)) rnn = GRU(rnn_units1, return_sequences=True, return_state=True, recurrent_activation="sigmoid", reset_after='true', name='gru_a') rnn2 = GRU(rnn_units2, return_sequences=True, return_state=True, recurrent_activation="sigmoid", reset_after='true', name='gru_b') rnn_in = Concatenate()([cpcm, rep(cfeat)]) md = MDense(pcm_levels, activation='softmax', name='dual_fc') gru_out1, _ = rnn(rnn_in) gru_out2, _ = rnn2(Concatenate()([gru_out1, rep(cfeat)])) ulaw_prob = md(gru_out2) if adaptation: rnn.trainable=False rnn2.trainable=False md.trainable=False embed.Trainable=False model = Model([pcm, feat, pitch], ulaw_prob) model.rnn_units1 = rnn_units1 model.rnn_units2 = rnn_units2 model.nb_used_features = nb_used_features model.frame_size = frame_size encoder = Model([feat, pitch], cfeat) dec_rnn_in = Concatenate()([cpcm, dec_feat]) dec_gru_out1, state1 = rnn(dec_rnn_in, initial_state=dec_state1) dec_gru_out2, state2 = rnn2(Concatenate()([dec_gru_out1, dec_feat]), initial_state=dec_state2) dec_ulaw_prob = md(dec_gru_out2) decoder = Model([pcm, dec_feat, dec_state1, dec_state2], [dec_ulaw_prob, state1, state2]) return model, encoder, decoder
def new_lpcnet_model(rnn_units1=384, rnn_units2=16, nb_used_features = 38, use_gpu=True): pcm = Input(shape=(None, 2)) exc = Input(shape=(None, 1)) feat = Input(shape=(None, nb_used_features)) pitch = Input(shape=(None, 1)) dec_feat = Input(shape=(None, 128)) 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(102, 3, padding='same', activation='tanh', name='feature_conv2') embed = Embedding(256, embed_size, embeddings_initializer=PCMInit(), name='embed_sig') cpcm = Reshape((-1, embed_size*2))(embed(pcm)) embed2 = Embedding(256, embed_size, embeddings_initializer=PCMInit(), name='embed_exc') cexc = Reshape((-1, embed_size))(embed2(exc)) pembed = Embedding(256, 64, name='embed_pitch') cat_feat = Concatenate()([feat, Reshape((-1, 64))(pembed(pitch))]) cfeat = fconv2(fconv1(cat_feat)) fdense1 = Dense(128, activation='tanh', name='feature_dense1') fdense2 = Dense(128, activation='tanh', name='feature_dense2') cfeat = Add()([cfeat, cat_feat]) cfeat = fdense2(fdense1(cfeat)) rep = Lambda(lambda x: K.repeat_elements(x, 160, 1)) if use_gpu: rnn = CuDNNGRU(rnn_units1, return_sequences=True, return_state=True, name='gru_a') rnn2 = CuDNNGRU(rnn_units2, return_sequences=True, return_state=True, name='gru_b') else: rnn = GRU(rnn_units1, return_sequences=True, return_state=True, recurrent_activation="sigmoid", reset_after='true', name='gru_a') rnn2 = GRU(rnn_units2, return_sequences=True, return_state=True, recurrent_activation="sigmoid", reset_after='true', name='gru_b') rnn_in = Concatenate()([cpcm, cexc, rep(cfeat)]) md = MDense(pcm_levels, activation='softmax', name='dual_fc') gru_out1, _ = rnn(rnn_in) gru_out2, _ = rnn2(Concatenate()([gru_out1, rep(cfeat)])) ulaw_prob = md(gru_out2) model = Model([pcm, exc, feat, pitch], ulaw_prob) model.rnn_units1 = rnn_units1 model.rnn_units2 = rnn_units2 model.nb_used_features = nb_used_features encoder = Model([feat, pitch], cfeat) dec_rnn_in = Concatenate()([cpcm, cexc, dec_feat]) dec_gru_out1, state1 = rnn(dec_rnn_in, initial_state=dec_state1) dec_gru_out2, state2 = rnn2(Concatenate()([dec_gru_out1, dec_feat]), initial_state=dec_state2) dec_ulaw_prob = md(dec_gru_out2) decoder = Model([pcm, exc, dec_feat, dec_state1, dec_state2], [dec_ulaw_prob, state1, state2]) return model, encoder, decoder