You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
673 B

  1. from torch import nn
  2. class Tacotron2Loss(nn.Module):
  3. def __init__(self):
  4. super(Tacotron2Loss, self).__init__()
  5. def forward(self, model_output, targets):
  6. mel_target, gate_target = targets[0], targets[1]
  7. mel_target.requires_grad = False
  8. gate_target.requires_grad = False
  9. gate_target = gate_target.view(-1, 1)
  10. mel_out, mel_out_postnet, gate_out, _ = model_output
  11. gate_out = gate_out.view(-1, 1)
  12. mel_loss = nn.MSELoss()(mel_out, mel_target) + \
  13. nn.MSELoss()(mel_out_postnet, mel_target)
  14. gate_loss = nn.BCEWithLogitsLoss()(gate_out, gate_target)
  15. return mel_loss + gate_loss