KingNish commited on
Commit
991013d
·
verified ·
1 Parent(s): 36cffd8

Upload ./RepCodec/repcodec/modules/residual_unit.py with huggingface_hub

Browse files
RepCodec/repcodec/modules/residual_unit.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) ByteDance, Inc. and its affiliates.
2
+ # Copyright (c) Chutong Meng
3
+ #
4
+ # This source code is licensed under the CC BY-NC license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+ # Based on AudioDec (https://github.com/facebookresearch/AudioDec)
7
+
8
+ import torch.nn as nn
9
+
10
+ from RepCodec.repcodec.layers.conv_layer import Conv1d, Conv1d1x1
11
+
12
+
13
+ class ResidualUnit(nn.Module):
14
+ def __init__(
15
+ self,
16
+ in_channels: int,
17
+ out_channels: int,
18
+ kernel_size=3,
19
+ dilation=1,
20
+ bias=False,
21
+ nonlinear_activation="ELU",
22
+ nonlinear_activation_params={},
23
+ ):
24
+ super().__init__()
25
+ self.activation = getattr(nn, nonlinear_activation)(**nonlinear_activation_params)
26
+ self.conv1 = Conv1d(
27
+ in_channels=in_channels,
28
+ out_channels=out_channels,
29
+ kernel_size=kernel_size,
30
+ stride=1,
31
+ dilation=dilation,
32
+ bias=bias,
33
+ )
34
+ self.conv2 = Conv1d1x1(out_channels, out_channels, bias)
35
+
36
+ def forward(self, x):
37
+ y = self.conv1(self.activation(x))
38
+ y = self.conv2(self.activation(y))
39
+ return x + y