MCPcopy Create free account
hub / github.com/MYZY-AI/Muyan-TTS / PosteriorEncoder

Class PosteriorEncoder

sovits/models.py:329–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327
328
329class PosteriorEncoder(nn.Module):
330 def __init__(
331 self,
332 in_channels,
333 out_channels,
334 hidden_channels,
335 kernel_size,
336 dilation_rate,
337 n_layers,
338 gin_channels=0,
339 ):
340 super().__init__()
341 self.in_channels = in_channels
342 self.out_channels = out_channels
343 self.hidden_channels = hidden_channels
344 self.kernel_size = kernel_size
345 self.dilation_rate = dilation_rate
346 self.n_layers = n_layers
347 self.gin_channels = gin_channels
348
349 self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
350 self.enc = modules.WN(
351 hidden_channels,
352 kernel_size,
353 dilation_rate,
354 n_layers,
355 gin_channels=gin_channels,
356 )
357 self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
358
359 def forward(self, x, x_lengths, g=None):
360 if g != None:
361 g = g.detach()
362 x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
363 x.dtype
364 )
365 x = self.pre(x) * x_mask
366 x = self.enc(x, x_mask, g=g)
367 stats = self.proj(x) * x_mask
368 m, logs = torch.split(stats, self.out_channels, dim=1)
369 z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
370 return z, m, logs, x_mask
371
372
373class WNEncoder(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected