FL2VA/audio_vae/dac_alias_free_act.py
835 B · 31 lines · python Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
3
4 import torch.nn as nn
5 from .dac_alias_free_resample import UpSample1d, DownSample1d
6
7
8 class Activation1d(nn.Module):
9 def __init__(
10 self,
11 activation,
12 up_ratio: int = 2,
13 down_ratio: int = 2,
14 up_kernel_size: int = 12,
15 down_kernel_size: int = 12,
16 ):
17 super().__init__()
18 self.up_ratio = up_ratio
19 self.down_ratio = down_ratio
20 self.act = activation
21 self.upsample = UpSample1d(up_ratio, up_kernel_size)
22 self.downsample = DownSample1d(down_ratio, down_kernel_size)
23
24 # x: [B,C,T]
25 def forward(self, x):
26 x = self.upsample(x)
27 x = self.act(x)
28 x = self.downsample(x)
29
30 return x
31