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

Class ConvBlock

modules/fastspeech/pe.py:44–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class ConvBlock(nn.Module):
45 def __init__(self, idim=80, n_chans=256, kernel_size=3, stride=1, norm='gn', dropout=0):
46 super().__init__()
47 self.conv = ConvNorm(idim, n_chans, kernel_size, stride=stride)
48 self.norm = norm
49 if self.norm == 'bn':
50 self.norm = nn.BatchNorm1d(n_chans)
51 elif self.norm == 'in':
52 self.norm = nn.InstanceNorm1d(n_chans, affine=True)
53 elif self.norm == 'gn':
54 self.norm = nn.GroupNorm(n_chans // 16, n_chans)
55 elif self.norm == 'ln':
56 self.norm = LayerNorm(n_chans // 16, n_chans)
57 elif self.norm == 'wn':
58 self.conv = torch.nn.utils.weight_norm(self.conv.conv)
59 self.dropout = nn.Dropout(dropout)
60 self.relu = nn.ReLU()
61
62 def forward(self, x):
63 """
64
65 :param x: [B, C, T]
66 :return: [B, C, T]
67 """
68 x = self.conv(x)
69 if not isinstance(self.norm, str):
70 if self.norm == 'none':
71 pass
72 elif self.norm == 'ln':
73 x = self.norm(x.transpose(1, 2)).transpose(1, 2)
74 else:
75 x = self.norm(x)
76 x = self.relu(x)
77 x = self.dropout(x)
78 return x
79
80
81class ConvStacks(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected