| 61 | |
| 62 | |
| 63 | class XLSR(nn.Module): |
| 64 | def __init__(self, SR_rate): |
| 65 | super(XLSR, self).__init__() |
| 66 | |
| 67 | self.conv0_0 = ConvRelu(in_channels=3, out_channels=8, kernel_size=3) |
| 68 | self.conv0_1 = ConvRelu(in_channels=3, out_channels=8, kernel_size=3) |
| 69 | self.conv0_2 = ConvRelu(in_channels=3, out_channels=8, kernel_size=3) |
| 70 | self.conv0_3 = ConvRelu(in_channels=3, out_channels=8, kernel_size=3) |
| 71 | |
| 72 | self.conv1 = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, padding=1) |
| 73 | self.conv2 = nn.Conv2d(in_channels=32, out_channels=32, kernel_size=1, padding=0) |
| 74 | self.conv3 = ConvRelu(in_channels=48, out_channels=32, kernel_size=1) |
| 75 | self.conv4 = nn.Conv2d(in_channels=32, out_channels=3 * SR_rate ** 2, kernel_size=3, padding=1) |
| 76 | |
| 77 | self.Gblocks = nn.Sequential(Gblock(32, 32, 4), Gblock(32, 32, 4), Gblock(32, 32, 4)) |
| 78 | self.depth2spcae = nn.PixelShuffle(SR_rate) |
| 79 | self.clippedReLU = ClippedReLU() |
| 80 | |
| 81 | # init weights |
| 82 | for m in self.modules(): |
| 83 | if isinstance(m, nn.Conv2d): |
| 84 | # nn.init.kaiming_normal_(m.weight.data, mode='fan_out', nonlinearity='relu') |
| 85 | _, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(m.weight.data) |
| 86 | std = math.sqrt(2 / fan_out * 0.1) |
| 87 | torch.nn.init.normal_(m.weight.data, mean=0, std=std) |
| 88 | if m.bias is not None: |
| 89 | nn.init.constant_(m.bias.data, 0.01) |
| 90 | |
| 91 | def forward(self, x): |
| 92 | |
| 93 | res_conv0_0 = self.conv0_0(x) |
| 94 | res_conv0_1 = self.conv0_1(x) |
| 95 | res_conv0_2 = self.conv0_2(x) |
| 96 | res_conv0_3 = self.conv0_3(x) |
| 97 | res = torch.cat((res_conv0_0, res_conv0_1, res_conv0_2, res_conv0_3), dim=1) |
| 98 | |
| 99 | res = self.conv2(res) |
| 100 | res = self.Gblocks(res) |
| 101 | |
| 102 | res_conv1 = self.conv1(x) |
| 103 | res = torch.cat((res, res_conv1), dim=1) |
| 104 | |
| 105 | res = self.conv3(res) |
| 106 | res = self.conv4(res) |
| 107 | res = self.clippedReLU(res) |
| 108 | |
| 109 | res = self.depth2spcae(res) |
| 110 | |
| 111 | return res |
| 112 | |
| 113 | |
| 114 | class XLSR_quantization(nn.Module): |