MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / forward

Method forward

modules/parallel_wavegan/stft_loss.py:29–52  ·  view source on GitHub ↗

Calculate forward propagation. Args: x (Tensor): Predicted signal (B, T). y (Tensor): Groundtruth signal (B, T). Returns: Tensor: Spectral convergence loss value. Tensor: Log STFT magnitude loss value.

(self, x, y)

Source from the content-addressed store, hash-verified

27 self.mel_basis = None
28
29 def forward(self, x, y):
30 """Calculate forward propagation.
31
32 Args:
33 x (Tensor): Predicted signal (B, T).
34 y (Tensor): Groundtruth signal (B, T).
35
36 Returns:
37 Tensor: Spectral convergence loss value.
38 Tensor: Log STFT magnitude loss value.
39
40 """
41 x_mag = stft(x, self.fft_size, self.shift_size, self.win_length, self.window)
42 y_mag = stft(y, self.fft_size, self.shift_size, self.win_length, self.window)
43 if self.use_mel_loss:
44 if self.mel_basis is None:
45 self.mel_basis = torch.from_numpy(librosa.filters.mel(22050, self.fft_size, 80)).cuda().T
46 x_mag = x_mag @ self.mel_basis
47 y_mag = y_mag @ self.mel_basis
48
49 sc_loss = self.spectral_convergenge_loss(x_mag, y_mag)
50 mag_loss = self.log_stft_magnitude_loss(x_mag, y_mag)
51
52 return sc_loss, mag_loss
53
54
55class MultiResolutionSTFTLoss(torch.nn.Module):

Callers

nothing calls this directly

Calls 1

stftFunction · 0.90

Tested by

no test coverage detected