(self, txt_tokens, mel2ph=None, spk_embed=None,
ref_mels=None, f0=None, uv=None, energy=None, infer=False)
| 294 | return loss |
| 295 | |
| 296 | def forward(self, txt_tokens, mel2ph=None, spk_embed=None, |
| 297 | ref_mels=None, f0=None, uv=None, energy=None, infer=False): |
| 298 | b, *_, device = *txt_tokens.shape, txt_tokens.device |
| 299 | ret = self.fs2(txt_tokens, mel2ph, spk_embed, ref_mels, f0, uv, energy, |
| 300 | skip_decoder=True, infer=infer) |
| 301 | cond = ret['decoder_inp'].transpose(1, 2) |
| 302 | if not infer: |
| 303 | t = torch.randint(0, self.num_timesteps, (b,), device=device).long() |
| 304 | x = ref_mels |
| 305 | x = self.norm_spec(x) |
| 306 | x = x.transpose(1, 2)[:, None, :, :] # [B, 1, M, T] |
| 307 | nonpadding = (mel2ph != 0).float() |
| 308 | ret['diff_loss'] = self.p_losses(x, t, cond, nonpadding=nonpadding) |
| 309 | else: |
| 310 | t = self.num_timesteps |
| 311 | shape = (cond.shape[0], 1, self.mel_bins, cond.shape[2]) |
| 312 | x = torch.randn(shape, device=device) |
| 313 | for i in tqdm(reversed(range(0, t)), desc='sample time step', total=t): |
| 314 | x = self.p_sample(x, torch.full((b,), i, device=device, dtype=torch.long), cond) |
| 315 | x = x[:, 0].transpose(1, 2) |
| 316 | ret['mel_out'] = self.denorm_spec(x) |
| 317 | |
| 318 | return ret |
| 319 | |
| 320 | def norm_spec(self, x): |
| 321 | return (x - self.spec_min) / (self.spec_max - self.spec_min) * 2 - 1 |
nothing calls this directly
no test coverage detected