def test_in_out(): layer = Decoder(in_features=256, memory_dim=80, r=2, memory_size=4, attn_windowing=False, attn_norm="sigmoid", prenet_type='original', prenet_dropout=True, forward_attn=True, trans_agent=True, forward_attn_mask=True, location_attn=True, separate_stopnet=True) dummy_input = T.rand(4, 8, 256) dummy_memory = T.rand(4, 2, 80) output, alignment, stop_tokens = layer(dummy_input, dummy_memory, mask=None) assert output.shape[0] == 4 assert output.shape[1] == 1, "size not {}".format(output.shape[1]) assert output.shape[2] == 80 * 2, "size not {}".format(output.shape[2]) assert stop_tokens.shape[0] == 4
def __init__(self, num_chars, num_speakers, r=5, linear_dim=1025, mel_dim=80, memory_size=5, attn_win=False, attn_norm="sigmoid", prenet_type="original", prenet_dropout=True, forward_attn=False, trans_agent=False, forward_attn_mask=False, location_attn=True, separate_stopnet=True): super(Tacotron, self).__init__() self.r = r self.mel_dim = mel_dim self.linear_dim = linear_dim self.embedding = nn.Embedding(num_chars, 256) self.embedding.weight.data.normal_(0, 0.3) if num_speakers > 1: self.speaker_embedding = nn.Embedding(num_speakers, 256) self.speaker_embedding.weight.data.normal_(0, 0.3) self.encoder = Encoder(256) self.decoder = Decoder(256, mel_dim, r, memory_size, attn_win, attn_norm, prenet_type, prenet_dropout, forward_attn, trans_agent, forward_attn_mask, location_attn, separate_stopnet) self.postnet = PostCBHG(mel_dim) self.last_linear = nn.Linear(self.postnet.cbhg.gru_features * 2, linear_dim)
def __init__(self, num_chars, num_speakers, r=5, postnet_output_dim=1025, decoder_output_dim=80, memory_size=5, attn_type='original', attn_win=False, gst=False, attn_norm="sigmoid", prenet_type="original", prenet_dropout=True, forward_attn=False, trans_agent=False, forward_attn_mask=False, location_attn=True, attn_K=5, separate_stopnet=True, bidirectional_decoder=False): super(Tacotron, self).__init__() self.r = r self.decoder_output_dim = decoder_output_dim self.postnet_output_dim = postnet_output_dim self.gst = gst self.num_speakers = num_speakers self.bidirectional_decoder = bidirectional_decoder decoder_dim = 512 if num_speakers > 1 else 256 encoder_dim = 512 if num_speakers > 1 else 256 proj_speaker_dim = 80 if num_speakers > 1 else 0 # embedding layer self.embedding = nn.Embedding(num_chars, 256) self.embedding.weight.data.normal_(0, 0.3) # boilerplate model self.encoder = Encoder(encoder_dim) self.decoder = Decoder(decoder_dim, decoder_output_dim, r, memory_size, attn_type, attn_win, attn_norm, prenet_type, prenet_dropout, forward_attn, trans_agent, forward_attn_mask, location_attn, attn_K, separate_stopnet, proj_speaker_dim) if self.bidirectional_decoder: self.decoder_backward = copy.deepcopy(self.decoder) self.postnet = PostCBHG(decoder_output_dim) self.last_linear = nn.Linear(self.postnet.cbhg.gru_features * 2, postnet_output_dim) # speaker embedding layers if num_speakers > 1: self.speaker_embedding = nn.Embedding(num_speakers, 256) self.speaker_embedding.weight.data.normal_(0, 0.3) self.speaker_project_mel = nn.Sequential( nn.Linear(256, proj_speaker_dim), nn.Tanh()) self.speaker_embeddings = None self.speaker_embeddings_projected = None # global style token layers if self.gst: gst_embedding_dim = 256 self.gst_layer = GST(num_mel=80, num_heads=4, num_style_tokens=10, embedding_dim=gst_embedding_dim)
def test_in_out(self): layer = Decoder(in_features=256, memory_dim=80, r=2) dummy_input = T.autograd.Variable(T.rand(4, 8, 256)) dummy_memory = T.autograd.Variable(T.rand(4, 2, 80)) output, alignment = layer(dummy_input, dummy_memory) assert output.shape[0] == 4 assert output.shape[1] == 1, "size not {}".format(output.shape[1]) assert output.shape[2] == 80 * 2, "size not {}".format(output.shape[2])
def test_in_out(self): layer = Decoder(in_features=128, memory_dim=32, r=5) dummy_input = T.autograd.Variable(T.rand(4, 8, 128)) dummy_memory = T.autograd.Variable(T.rand(4, 120, 32)) print(layer) output, alignment = layer(dummy_input, dummy_memory) print(output.shape) assert output.shape[0] == 4 assert output.shape[1] == 120 / 5 assert output.shape[2] == 32 * 5
def test_in_out(self): layer = Decoder(in_features=256, memory_dim=80, r=2) dummy_input = T.rand(4, 8, 256) dummy_memory = T.rand(4, 2, 80) output, alignment, stop_tokens = layer(dummy_input, dummy_memory) assert output.shape[0] == 4 assert output.shape[1] == 1, "size not {}".format(output.shape[1]) assert output.shape[2] == 80 * 2, "size not {}".format(output.shape[2]) assert stop_tokens.shape[0] == 4 assert stop_tokens.max() <= 1.0 assert stop_tokens.min() >= 0
def __init__(self, embedding_dim=256, linear_dim=1025, mel_dim=80, r=5, padding_idx=None): super(Tacotron, self).__init__() self.r = r self.mel_dim = mel_dim self.linear_dim = linear_dim self.embedding = nn.Embedding(len(symbols), embedding_dim, padding_idx=padding_idx) print(" | > Embedding dim : {}".format(len(symbols))) self.embedding.weight.data.normal_(0, 0.3) self.encoder = Encoder(embedding_dim) self.decoder = Decoder(256, mel_dim, r) self.postnet = CBHG(mel_dim, K=8, projections=[256, mel_dim]) self.last_linear = nn.Linear(mel_dim * 2, linear_dim)
def __init__(self, embedding_dim=256, linear_dim=1025, mel_dim=80, r=5, padding_idx=None): super(Tacotron, self).__init__() self.r = r self.mel_dim = mel_dim self.linear_dim = linear_dim self.embedding = nn.Embedding( len(symbols), embedding_dim, padding_idx=padding_idx) print(" | > Number of characters : {}".format(len(symbols))) self.embedding.weight.data.normal_(0, 0.3) self.encoder = Encoder(embedding_dim) self.decoder = Decoder(256, mel_dim, r) self.postnet = PostCBHG(mel_dim) self.last_linear = nn.Sequential( nn.Linear(self.postnet.cbhg.gru_features * 2, linear_dim), nn.Sigmoid())
def __init__(self, num_chars, linear_dim=1025, mel_dim=80, r=5, padding_idx=None, memory_size=5, attn_win=False, attn_norm="sigmoid"): super(Tacotron, self).__init__() self.r = r self.mel_dim = mel_dim self.linear_dim = linear_dim self.embedding = nn.Embedding(num_chars, 256, padding_idx=padding_idx) self.embedding.weight.data.normal_(0, 0.3) self.encoder = Encoder(256) self.decoder = Decoder(256, mel_dim, r, memory_size, attn_win, attn_norm) self.postnet = PostCBHG(mel_dim) self.last_linear = nn.Sequential( nn.Linear(self.postnet.cbhg.gru_features * 2, linear_dim), nn.Sigmoid())
def __init__(self, num_chars, num_speakers, r=5, postnet_output_dim=1025, decoder_output_dim=80, attn_type='original', attn_win=False, attn_norm="sigmoid", prenet_type="original", prenet_dropout=True, forward_attn=False, trans_agent=False, forward_attn_mask=False, location_attn=True, attn_K=5, separate_stopnet=True, bidirectional_decoder=False, double_decoder_consistency=False, ddc_r=None, gst=False, memory_size=5): super(Tacotron, self).__init__(num_chars, num_speakers, r, postnet_output_dim, decoder_output_dim, attn_type, attn_win, attn_norm, prenet_type, prenet_dropout, forward_attn, trans_agent, forward_attn_mask, location_attn, attn_K, separate_stopnet, bidirectional_decoder, double_decoder_consistency, ddc_r, gst) decoder_in_features = 512 if num_speakers > 1 else 256 encoder_in_features = 512 if num_speakers > 1 else 256 speaker_embedding_dim = 256 proj_speaker_dim = 80 if num_speakers > 1 else 0 # base model layers self.embedding = nn.Embedding(num_chars, 256, padding_idx=0) self.embedding.weight.data.normal_(0, 0.3) self.encoder = Encoder(encoder_in_features) self.decoder = Decoder(decoder_in_features, decoder_output_dim, r, memory_size, attn_type, attn_win, attn_norm, prenet_type, prenet_dropout, forward_attn, trans_agent, forward_attn_mask, location_attn, attn_K, separate_stopnet, proj_speaker_dim) self.postnet = PostCBHG(decoder_output_dim) self.last_linear = nn.Linear(self.postnet.cbhg.gru_features * 2, postnet_output_dim) # speaker embedding layers if num_speakers > 1: self.speaker_embedding = nn.Embedding(num_speakers, speaker_embedding_dim) self.speaker_embedding.weight.data.normal_(0, 0.3) self.speaker_project_mel = nn.Sequential( nn.Linear(speaker_embedding_dim, proj_speaker_dim), nn.Tanh()) self.speaker_embeddings = None self.speaker_embeddings_projected = None # global style token layers if self.gst: gst_embedding_dim = 256 self.gst_layer = GST(num_mel=80, num_heads=4, num_style_tokens=10, embedding_dim=gst_embedding_dim) # backward pass decoder if self.bidirectional_decoder: self._init_backward_decoder() # setup DDC if self.double_decoder_consistency: self.coarse_decoder = Decoder( decoder_in_features, decoder_output_dim, ddc_r, memory_size, attn_type, attn_win, attn_norm, prenet_type, prenet_dropout, forward_attn, trans_agent, forward_attn_mask, location_attn, attn_K, separate_stopnet, proj_speaker_dim)