|
|
|
@ -27,14 +27,18 @@ class HighToLowResNet(nn.Module):
|
|
|
|
|
self.trunk_lores = arch_util.make_layer(basic_block2, nb - 15)
|
|
|
|
|
|
|
|
|
|
# downsampling
|
|
|
|
|
if self.downscale == 4:
|
|
|
|
|
if self.downscale == 4 or self.downscale == 1:
|
|
|
|
|
self.downconv1 = nn.Conv2d(nf, nf, 3, stride=2, padding=1, bias=True)
|
|
|
|
|
self.downconv2 = nn.Conv2d(nf, nf*2, 3, stride=2, padding=1, bias=True)
|
|
|
|
|
else:
|
|
|
|
|
raise EnvironmentError("Requested downscale not supported: %i" % (downscale,))
|
|
|
|
|
|
|
|
|
|
self.HRconv = nn.Conv2d(nf*2, nf*2, 3, stride=1, padding=1, bias=True)
|
|
|
|
|
self.conv_last = nn.Conv2d(nf*2, out_nc, 3, stride=1, padding=1, bias=True)
|
|
|
|
|
if self.downscale == 4:
|
|
|
|
|
self.conv_last = nn.Conv2d(nf*2, out_nc, 3, stride=1, padding=1, bias=True)
|
|
|
|
|
else:
|
|
|
|
|
self.pixel_shuffle = nn.PixelShuffle(4)
|
|
|
|
|
self.conv_last = nn.Conv2d(int(nf/8), out_nc, 3, stride=1, padding=1, bias=True)
|
|
|
|
|
|
|
|
|
|
# activation function
|
|
|
|
|
self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)
|
|
|
|
@ -51,13 +55,22 @@ class HighToLowResNet(nn.Module):
|
|
|
|
|
out = self.lrelu(self.conv_first(out))
|
|
|
|
|
out = self.trunk_hires(out)
|
|
|
|
|
|
|
|
|
|
if self.downscale == 4:
|
|
|
|
|
if self.downscale == 4 or self.downscale == 1:
|
|
|
|
|
out = self.lrelu(self.downconv1(out))
|
|
|
|
|
out = self.trunk_medres(out)
|
|
|
|
|
out = self.lrelu(self.downconv2(out))
|
|
|
|
|
out = self.trunk_lores(out)
|
|
|
|
|
|
|
|
|
|
out = self.conv_last(self.lrelu(self.HRconv(out)))
|
|
|
|
|
base = F.interpolate(x, scale_factor=1/self.downscale, mode='bilinear', align_corners=False)
|
|
|
|
|
if self.downscale == 1:
|
|
|
|
|
out = self.lrelu(self.pixel_shuffle(self.HRconv(out)))
|
|
|
|
|
out = self.conv_last(out)
|
|
|
|
|
else:
|
|
|
|
|
out = self.conv_last(self.lrelu(self.HRconv(out)))
|
|
|
|
|
|
|
|
|
|
if self.downscale == 1:
|
|
|
|
|
base = x
|
|
|
|
|
else:
|
|
|
|
|
base = F.interpolate(x, scale_factor=1/self.downscale, mode='bilinear', align_corners=False)
|
|
|
|
|
|
|
|
|
|
out += base
|
|
|
|
|
return out
|
|
|
|
|