Construct an ConvolutionModule object. Args: channels (int): The number of channels of conv layers. kernel_size (int): Kernel size of conv layers. causal (int): Whether use causal convolution or not
(self,
channels: int,
kernel_size: int = 15,
activation: nn.Module = nn.ReLU(),
norm: str = "batch_norm",
causal: bool = False,
bias: bool = True,
adaptive_scale: bool = False,
init_weights: bool = False)
| 25 | """ConvolutionModule in Conformer model.""" |
| 26 | |
| 27 | def __init__(self, |
| 28 | channels: int, |
| 29 | kernel_size: int = 15, |
| 30 | activation: nn.Module = nn.ReLU(), |
| 31 | norm: str = "batch_norm", |
| 32 | causal: bool = False, |
| 33 | bias: bool = True, |
| 34 | adaptive_scale: bool = False, |
| 35 | init_weights: bool = False): |
| 36 | """Construct an ConvolutionModule object. |
| 37 | Args: |
| 38 | channels (int): The number of channels of conv layers. |
| 39 | kernel_size (int): Kernel size of conv layers. |
| 40 | causal (int): Whether use causal convolution or not |
| 41 | """ |
| 42 | super().__init__() |
| 43 | self.bias = bias |
| 44 | self.channels = channels |
| 45 | self.kernel_size = kernel_size |
| 46 | self.adaptive_scale = adaptive_scale |
| 47 | self.ada_scale = torch.nn.Parameter(torch.ones([1, 1, channels]), |
| 48 | requires_grad=adaptive_scale) |
| 49 | self.ada_bias = torch.nn.Parameter(torch.zeros([1, 1, channels]), |
| 50 | requires_grad=adaptive_scale) |
| 51 | |
| 52 | self.pointwise_conv1 = nn.Conv1d( |
| 53 | channels, |
| 54 | 2 * channels, |
| 55 | kernel_size=1, |
| 56 | stride=1, |
| 57 | padding=0, |
| 58 | bias=bias, |
| 59 | ) |
| 60 | # self.lorder is used to distinguish if it's a causal convolution, |
| 61 | # if self.lorder > 0: it's a causal convolution, the input will be |
| 62 | # padded with self.lorder frames on the left in forward. |
| 63 | # else: it's a symmetrical convolution |
| 64 | if causal: |
| 65 | padding = 0 |
| 66 | self.lorder = kernel_size - 1 |
| 67 | else: |
| 68 | # kernel_size should be an odd number for none causal convolution |
| 69 | assert (kernel_size - 1) % 2 == 0 |
| 70 | padding = (kernel_size - 1) // 2 |
| 71 | self.lorder = 0 |
| 72 | self.depthwise_conv = nn.Conv1d( |
| 73 | channels, |
| 74 | channels, |
| 75 | kernel_size, |
| 76 | stride=1, |
| 77 | padding=padding, |
| 78 | groups=channels, |
| 79 | bias=bias, |
| 80 | ) |
| 81 | |
| 82 | assert norm in ['batch_norm', 'layer_norm'] |
| 83 | if norm == "batch_norm": |
| 84 | self.use_layer_norm = False |
nothing calls this directly
no test coverage detected