Skip to content

Commit

Permalink
tf.keras wrappers fixes (issue Rayhane-mamah#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayhane-mamah authored Oct 7, 2018
1 parent 55db0b4 commit 970b080
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions hparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@
cbhg_rnn_units = 128, #Number of GRU units used in bidirectional RNN of CBHG block. CBHG output is 2x rnn_units in shape

#Loss params
mask_encoder = False, #whether to mask encoder padding while computing attention. Set to True for better prosody but slower convergence.
mask_encoder = True, #whether to mask encoder padding while computing attention. Set to True for better prosody but slower convergence.
mask_decoder = False, #Whether to use loss mask for padded sequences (if False, <stop_token> loss function will not be weighted, else recommended pos_weight = 20)
cross_entropy_pos_weight = 1, #Use class weights to reduce the stop token classes imbalance (by adding more penalty on False Negatives (FN)) (1 = disabled)
cross_entropy_pos_weight = 20, #Use class weights to reduce the stop token classes imbalance (by adding more penalty on False Negatives (FN)) (1 = disabled)
predict_linear = True, #Whether to add a post-processing network to the Tacotron to predict linear spectrograms (True mode Not tested!!)
###########################################################################################################################################

Expand Down
17 changes: 10 additions & 7 deletions wavenet_vocoder/models/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ def call(self, inputs, incremental=False, convolution_queue=None):
output = tf.nn.bias_add(output, self.layer.bias)

#[batch_size, 1(time_step), channels(filters)]
return tf.reshape(output, [batch_size, 1, self.layer.filters]), convolution_queue
if convolution_queue is None:
return tf.reshape(output, [batch_size, 1, self.layer.filters])
else:
return [tf.reshape(output, [batch_size, 1, self.layer.filters]), convolution_queue]

#Normal run
#Causal convolutions are only padded on the left side
Expand Down Expand Up @@ -322,7 +325,7 @@ def incremental_step(self, inputs, convolution_queue=None):
inputs: [batch_size, time_length, channels] ('NWC')! Channels last!
'''
return self(inputs, True, convolution_queue)
return self(inputs, incremental=True, convolution_queue=convolution_queue)


class Conv1D1x1(CausalConv1D):
Expand Down Expand Up @@ -370,11 +373,11 @@ def __init__(self, filters,

def call(self, inputs, incremental=False, convolution_queue=None):
#Call parent class call function
return super(Conv1D1x1, self).call(inputs, incremental, convolution_queue)
return super(Conv1D1x1, self).call(inputs, incremental=incremental, convolution_queue=convolution_queue)

def incremental_step(self, inputs, unused_queue=None):
#Call parent class incremental function
output, _ = self(inputs, True, unused_queue) #Drop unused queue
output = self(inputs, incremental=True, convolution_queue=unused_queue) #Drop unused queue
return output


Expand Down Expand Up @@ -449,11 +452,11 @@ def set_mode(self, is_training):


def call(self, x, c=None, g=None):
x, s, _ = self.step(x, c, g, False)
return (x, s)
x, s, _ = self.step(x, c=c, g=g, is_incremental=False)
return [x, s]

def incremental_step(self, x, c=None, g=None, queue=None):
return self.step(x, c, g, True, queue=queue)
return self.step(x, c=c, g=g, is_incremental=True, queue=queue)

def step(self, x, c, g, is_incremental, queue=None):
'''
Expand Down
4 changes: 3 additions & 1 deletion wavenet_vocoder/models/wavenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ def initialize(self, y, c, g, input_lengths, x=None, synthesis_length=None):
self.variables = tf.trainable_variables()
n_vars = np.sum([np.prod(v.shape) for v in tf.trainable_variables()])
log(' Receptive Field: ({} samples / {:.1f} ms)'.format(self.receptive_field, self.receptive_field / hparams.sample_rate * 1000.))
log(' WaveNet Parameters: {:.3f} Million.'.format(np.sum([np.prod(v.get_shape().as_list()) for v in self.variables]) / 1_000_000))

#1_000_000 is causing syntax problems for some people?! Python please :)
log(' WaveNet Parameters: {:.3f} Million.'.format(np.sum([np.prod(v.get_shape().as_list()) for v in self.variables]) / 1000000))

self.ema = tf.train.ExponentialMovingAverage(decay=hparams.wavenet_ema_decay)

Expand Down

0 comments on commit 970b080

Please sign in to comment.