def __init__(self, is_training, cbhg_out_units=256, conv_channels=128, max_filter_width=16, projection1_out_channels=128, projection2_out_channels=128, num_highway=4, prenet_out_units=(256, 128), drop_rate=0.5, trainable=True, name=None, **kwargs): super(EncoderV1, self).__init__(name=name, trainable=trainable, **kwargs) self.prenet_out_units = prenet_out_units self.prenets = [ PreNet(out_unit, is_training, drop_rate) for out_unit in prenet_out_units ] self.cbhg = CBHG(cbhg_out_units, conv_channels, max_filter_width, projection1_out_channels, projection2_out_channels, num_highway, is_training)
class EncoderV1(tf.layers.Layer): def __init__(self, is_training, cbhg_out_units=256, conv_channels=128, max_filter_width=16, projection1_out_channels=128, projection2_out_channels=128, num_highway=4, prenet_out_units=(256, 128), drop_rate=0.5, trainable=True, name=None, **kwargs): super(EncoderV1, self).__init__(name=name, trainable=trainable, **kwargs) self.prenet_out_units = prenet_out_units self.prenets = [PreNet(out_unit, is_training, drop_rate) for out_unit in prenet_out_units] self.cbhg = CBHG(cbhg_out_units, conv_channels, max_filter_width, projection1_out_channels, projection2_out_channels, num_highway, is_training) def build(self, input_shape): embed_dim = input_shape[2].value with tf.control_dependencies([tf.assert_equal(self.prenet_out_units[0], embed_dim)]): self.built = True def call(self, inputs, input_lengths=None, **kwargs): prenet_output = reduce(lambda acc, pn: pn(acc), self.prenets, inputs) cbhg_output = self.cbhg(prenet_output, input_lengths=input_lengths) return cbhg_output def compute_output_shape(self, input_shape): return self.cbhg.compute_output_shape(input_shape)
def __init__(self, is_training, num_freq, cbhg_out_units=256, conv_channels=128, max_filter_width=8, projection1_out_channels=256, projection2_out_channels=80, num_highway=4, trainable=True, name=None, dtype=None, **kwargs): super(PostNet, self).__init__(trainable=trainable, name=name, dtype=dtype, **kwargs) self.cbhg = CBHG(cbhg_out_units, conv_channels, max_filter_width, projection1_out_channels, projection2_out_channels, num_highway, is_training, dtype=dtype) self.linear = tf.layers.Dense(num_freq, dtype=dtype)