MCPcopy Create free account
hub / github.com/Xiaobin-Rong/gtcrn / StreamConv1d

Class StreamConv1d

stream/modules/convolution.py:16–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14"""
15
16class StreamConv1d(nn.Module):
17 def __init__(self,
18 in_channels: int,
19 out_channels: int,
20 kernel_size: int,
21 stride: int=1,
22 padding: int=0,
23 dilation: int=1,
24 groups: int=1,
25 bias: bool=True,
26 *args, **kargs):
27 super(StreamConv1d, self).__init__(*args, *kargs)
28
29 assert padding == 0, "To meet the demands of causal streaming requirements"
30
31 self.Conv1d = nn.Conv1d(in_channels = in_channels,
32 out_channels = out_channels,
33 kernel_size = kernel_size,
34 stride = stride,
35 padding = padding,
36 dilation = dilation,
37 groups = groups,
38 bias = bias)
39
40 def forward(self, x, cache):
41 """
42 x: [bs, C, T_size]
43 cache: [bs, C, T_size-1]
44 """
45 inp = torch.cat([cache, x], dim=-1)
46 oup = self.Conv1d(inp)
47 out_cache = inp[..., 1:]
48 return oup, out_cache
49
50
51class StreamConv2d(nn.Module):

Callers 1

convolution.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected