def __init__(self, channels): super(ResidualBlock, self).__init__() self.conv1 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) self.bn1 = nn.BatchNorm2d(channels) self.prelu = nn.PReLU() self.conv2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) self.bn2 = nn.BatchNorm2d(channels)
def __init__(self, in_channels, up_scale): super(UpsampleBLock, self).__init__() self.conv = nn.Conv2d(in_channels, in_channels * up_scale**2, kernel_size=3, padding=1) self.pixel_shuffle = nn.PixelShuffle(up_scale) self.prelu = nn.PReLU()
def __init__(self, scale_factor): upsample_block_num = int(math.log(scale_factor, 2)) super(Generator, self).__init__() self.block1 = nn.Sequential(nn.Conv2d(3, 64, kernel_size=9, padding=4), nn.PReLU()) self.block2 = ResidualBlock(64) self.block3 = ResidualBlock(64) self.block4 = ResidualBlock(64) self.block5 = ResidualBlock(64) self.block6 = ResidualBlock(64) self.block7 = nn.Sequential( nn.Conv2d(64, 64, kernel_size=3, padding=1), nn.PReLU()) block8 = [UpsampleBLock(64, 2) for _ in range(upsample_block_num)] block8.append(nn.Conv2d(64, 3, kernel_size=9, padding=4)) block8.append(nn.Tanh()) self.block8 = nn.Sequential(*block8)
def __init__(self): super(ModuleDict, self).__init__() self.choices = nn.ModuleDict( {"conv": nn.Conv2d(10, 10, 3), "pool": nn.MaxPool2d(3)} ) self.activations = nn.ModuleDict( {"relu": nn.ReLU(), "prelu": nn.PReLU()} )
def __init__( self, in_channels=256, conv_channels=512, kernel_size=3, dilation=1, norm="cLN", causal=False, ): super(Conv1DBlock, self).__init__() # 1x1 conv self.conv1x1 = Conv1D(in_channels, conv_channels, 1) self.prelu1 = nn.PReLU() self.lnorm1 = build_norm(norm, conv_channels) dconv_pad = ( (dilation * (kernel_size - 1)) // 2 if not causal else (dilation * (kernel_size - 1)) ) # depthwise conv self.dconv = nn.Conv1d( conv_channels, conv_channels, kernel_size, groups=conv_channels, padding=dconv_pad, dilation=dilation, bias=True, ) self.prelu2 = nn.PReLU() self.lnorm2 = build_norm(norm, conv_channels) # 1x1 conv cross channel self.sconv = nn.Conv1d(conv_channels, in_channels, 1, bias=True) # different padding way self.causal = causal self.dconv_pad = dconv_pad