Spaces:
Sleeping
Sleeping
File size: 2,196 Bytes
e72f4c2 bdac835 e72f4c2 bdac835 e72f4c2 bdac835 e72f4c2 bdac835 e72f4c2 bdac835 e72f4c2 bdac835 e72f4c2 bdac835 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from torch import nn, Tensor
class UpResConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size) -> None:
super(UpResConvBlock, self).__init__()
self.residual = nn.Sequential(
nn.Upsample(scale_factor=2),
nn.Conv1d(in_channels, out_channels, 1, 1, bias=False),
)
self.main = nn.Sequential(
nn.Upsample(scale_factor=2),
nn.Conv1d(in_channels, out_channels, kernel_size, 1),
nn.GroupNorm(1, out_channels),
nn.GELU(),
nn.Conv1d(out_channels, out_channels, kernel_size, 1),
nn.GroupNorm(1, out_channels),
nn.GELU()
)
def forward(self, x: Tensor) -> Tensor:
return self.main(x) + self.residual(x)
class DownResConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size) -> None:
super(DownResConvBlock, self).__init__()
self.residual = nn.Conv1d(in_channels, out_channels, 1, 2, bias=False)
self.main = nn.Sequential(
nn.Conv1d(in_channels, out_channels, kernel_size, 2),
nn.GroupNorm(1, out_channels),
nn.GELU(),
nn.Conv1d(out_channels, out_channels, kernel_size, 1),
nn.GroupNorm(1, out_channels),
nn.GELU()
)
def forward(self, x: Tensor) -> Tensor:
return self.main(x) + self.residual(x)
class ResConvBlock(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size) -> None:
super(ResConvBlock, self).__init__()
self.residual = nn.Identity() if in_channels == out_channels else nn.Conv1d(in_channels, out_channels, 1, bias=False)
self.main = nn.Sequential(
nn.Conv1d(in_channels, out_channels, kernel_size),
nn.GroupNorm(1, out_channels),
nn.GELU(),
nn.Conv1d(out_channels, out_channels, kernel_size),
nn.GroupNorm(1, out_channels),
nn.GELU()
)
def forward(self, x: Tensor) -> Tensor:
return self.main(x) + self.residual(x) |