Skip to content

Commit

Permalink
Fix Taco inference for reduction factor
Browse files Browse the repository at this point in the history
  • Loading branch information
r9y9 committed Jul 9, 2022
1 parent 823d164 commit 9ad61a5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion nnsvs/acoustic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def __init__(
self.out_lf0_idx = out_lf0_idx
self.out_lf0_mean = out_lf0_mean
self.out_lf0_scale = out_lf0_scale
self.reduction_factor = reduction_factor

# Encoder
self.lstm = nn.LSTM(
Expand Down Expand Up @@ -710,4 +711,20 @@ def inference(self, x, lengths=None):
Returns:
torch.Tensor: the output features
"""
return self(x, lengths, None)[0][-1]
mod = max(lengths) % self.reduction_factor
pad = self.reduction_factor - mod

# Pad zeros to the end of the input features
# so that the lenght of the input features is a multiple of the reduction factor
if pad != 0:
x_pad = torch.nn.functional.pad(x, (0, 0, 0, pad), mode="constant")
lengths = lengths.copy()
lengths = [length + pad for length in lengths]
else:
x_pad = x
y = self(x_pad, lengths, None)[0][-1]

if pad != 0:
y = y[:, :-pad]

return y

0 comments on commit 9ad61a5

Please sign in to comment.