Residual block module used in SmoothNet. Args: in_channels (int): Input channel number. hidden_channels (int): The hidden feature channel number. dropout (float): Dropout probability. Default: 0.5 Shape: Input: (*, in_channels) Output: (*, in_channels
| 15 | |
| 16 | |
| 17 | class SmoothNetResBlock(nn.Module): |
| 18 | """Residual block module used in SmoothNet. |
| 19 | |
| 20 | Args: |
| 21 | in_channels (int): Input channel number. |
| 22 | hidden_channels (int): The hidden feature channel number. |
| 23 | dropout (float): Dropout probability. Default: 0.5 |
| 24 | Shape: |
| 25 | Input: (*, in_channels) |
| 26 | Output: (*, in_channels) |
| 27 | """ |
| 28 | def __init__(self, in_channels, hidden_channels, dropout=0.1): |
| 29 | super().__init__() |
| 30 | self.linear1 = nn.Linear(in_channels, hidden_channels) |
| 31 | self.linear2 = nn.Linear(hidden_channels, in_channels) |
| 32 | self.lrelu = nn.LeakyReLU(0.2, inplace=True) |
| 33 | self.dropout = nn.Dropout(p=dropout, inplace=True) |
| 34 | |
| 35 | def forward(self, x): |
| 36 | identity = x |
| 37 | x = self.linear1(x) |
| 38 | x = self.dropout(x) |
| 39 | x = self.lrelu(x) |
| 40 | x = self.linear2(x) |
| 41 | x = self.dropout(x) |
| 42 | x = self.lrelu(x) |
| 43 | |
| 44 | out = x + identity |
| 45 | return out |
| 46 | |
| 47 | |
| 48 | class SmoothNet(nn.Module): |