Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n_frame_per_step>1 support completed #404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_hparams(hparams_string=None, verbose=False):
encoder_embedding_dim=512,

# Decoder parameters
n_frames_per_step=1, # currently only 1 is supported
n_frames_per_step=1, # more than 1 is supported now
decoder_rnn_dim=1024,
prenet_dim=256,
max_decoder_steps=1000,
Expand Down
18 changes: 11 additions & 7 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def parse_decoder_inputs(self, decoder_inputs):
"""
# (B, n_mel_channels, T_out) -> (B, T_out, n_mel_channels)
decoder_inputs = decoder_inputs.transpose(1, 2)
decoder_inputs = decoder_inputs.view(
decoder_inputs = decoder_inputs.reshape(
decoder_inputs.size(0),
int(decoder_inputs.size(1)/self.n_frames_per_step), -1)
# (B, T_out, n_mel_channels) -> (T_out, B, n_mel_channels)
Expand All @@ -312,21 +312,22 @@ def parse_decoder_outputs(self, mel_outputs, gate_outputs, alignments):
""" Prepares decoder outputs for output
PARAMS
------
mel_outputs:
mel_outputs: list of outputs[batch_size, n_mel_channels*n_frames_per_step] at each step of decoder
gate_outputs: gate output energies
alignments:
alignments: list of alignments at each step of decoder

RETURNS
-------
mel_outputs:
gate_outpust: gate output energies
alignments:
mel_outputs: batched tensor of outputs
gate_outputs: gate output energies
alignments: batched tensor of alignments
"""
# (T_out, B) -> (B, T_out)
alignments = torch.stack(alignments).transpose(0, 1)
# (T_out, B) -> (B, T_out)
gate_outputs = torch.stack(gate_outputs).transpose(0, 1)
gate_outputs = gate_outputs.contiguous()
gate_outputs = gate_outputs.repeat_interleave(self.n_frames_per_step,1)
# (T_out, B, n_mel_channels) -> (B, T_out, n_mel_channels)
mel_outputs = torch.stack(mel_outputs).transpose(0, 1).contiguous()
# decouple frames per step
Expand Down Expand Up @@ -442,7 +443,7 @@ def inference(self, memory):

if torch.sigmoid(gate_output.data) > self.gate_threshold:
break
elif len(mel_outputs) == self.max_decoder_steps:
elif len(mel_outputs)*self.n_frames_per_step >= self.max_decoder_steps:
print("Warning! Reached max decoder steps")
break

Expand Down Expand Up @@ -488,6 +489,9 @@ def parse_output(self, outputs, output_lengths=None):
if self.mask_padding and output_lengths is not None:
mask = ~get_mask_from_lengths(output_lengths)
mask = mask.expand(self.n_mel_channels, mask.size(0), mask.size(1))
if mask.size(2)%self.n_frames_per_step != 0 :
to_append = torch.ones( mask.size(0), mask.size(1), (self.n_frames_per_step-mask.size(2)%self.n_frames_per_step) ).bool().to(mask.device)
mask = torch.cat([mask, to_append], dim=-1)
mask = mask.permute(1, 0, 2)

outputs[0].data.masked_fill_(mask, 0.0)
Expand Down