MCPcopy Create free account
hub / github.com/ASLP-lab/OSUM-Pangu / __init__

Method __init__

wenet/efficient_conformer/convolution.py:26–91  ·  view source on GitHub ↗

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 stride (int): Stride Convolution, for efficie

(self,
                 channels: int,
                 kernel_size: int = 15,
                 activation: nn.Module = nn.ReLU(),
                 norm: str = "batch_norm",
                 causal: bool = False,
                 bias: bool = True,
                 stride: int = 1)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected