Esempio n. 1
0
    def __init__(self,
                 nf=64,
                 nframes=5,
                 groups=8,
                 front_RBs=5,
                 back_RBs=10,
                 center=None,
                 predeblur=False,
                 HR_in=False,
                 w_TSA=True):
        super(EDVR, self).__init__()
        self.nf = nf
        self.center = nframes // 2 if center is None else center
        self.is_predeblur = True if predeblur else False
        self.HR_in = True if HR_in else False
        self.w_TSA = w_TSA
        ResidualBlock_noBN_f = functools.partial(arch_util.ResidualBlock_noBN,
                                                 nf=nf)
        ResidualCABlock_noBN_f = functools.partial(arch_util.RCAB, n_feat=nf)

        #### extract features (for each frame)
        if self.is_predeblur:
            self.pre_deblur = Predeblur_ResNet_Pyramid(nf=nf, HR_in=self.HR_in)
            self.conv_1x1 = nn.Conv2d(nf, nf, 1, 1, bias=True)
        else:
            if self.HR_in:
                self.conv_first_1 = nn.Conv2d(3, nf, 3, 1, 1, bias=True)
                self.conv_first_2 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
                self.conv_first_3 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
            else:
                self.conv_first = nn.Conv2d(3, nf, 3, 1, 1, bias=True)
        self.feature_extraction = arch_util.make_layer(ResidualBlock_noBN_f,
                                                       front_RBs)
        self.fea_L2_conv1 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
        self.fea_L2_conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.fea_L3_conv1 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
        self.fea_L3_conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)

        self.pcd_align = PCD_Align(nf=nf, groups=groups)
        if self.w_TSA:
            self.tsa_fusion = TSA_Fusion(nf=nf,
                                         nframes=nframes,
                                         center=self.center)
        else:
            self.tsa_fusion = nn.Conv2d(nframes * nf, nf, 1, 1, bias=True)

        #### reconstruction
        # self.recon_trunk = arch_util.make_layer(ResidualBlock_noBN_f, back_RBs)
        self.recon_trunk = arch_util.make_layer(ResidualCABlock_noBN_f,
                                                back_RBs)

        #### upsampling
        self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
        self.upconv2 = nn.Conv2d(nf, 64 * 4, 3, 1, 1, bias=True)
        self.pixel_shuffle = nn.PixelShuffle(2)
        self.HRconv = nn.Conv2d(64, 64, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(64, 3, 3, 1, 1, bias=True)

        #### activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)
Esempio n. 2
0
    def __init__(self, in_nc=3, nf=64):
        super(ResNet_alpha_beta_sconv, self).__init__()

        self.conv_1 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)  # 64f
        basic_block_64 = functools.partial(mutil.ResidualBlock_noBN, nf=nf)
        self.encoder1 = mutil.make_layer(basic_block_64, 2)  # 64f
        self.down_conv_1 = nn.Conv2d(nf, nf, 4, 2, 1, bias=False)

        self.conv_2 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=True)  # 128f
        basic_block_128 = functools.partial(mutil.ResidualBlock_noBN,
                                            nf=nf * 2)
        self.encoder2 = mutil.make_layer(basic_block_128, 2)  # 128f
        self.down_conv_2 = nn.Conv2d(nf * 2, nf * 2, 4, 2, 1, bias=False)

        self.conv_3 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=True)  # 256f
        basic_block_256 = functools.partial(mutil.ResidualBlock_noBN,
                                            nf=nf * 4)
        self.encoder3 = mutil.make_layer(basic_block_256, 2)  # 256f
        self.down_conv_3 = nn.Conv2d(nf * 4, nf * 4, 4, 2, 1, bias=False)

        self.conv_4 = nn.Conv2d(nf * 4, nf, 3, 1, 1, bias=True)  # 64f
        self.conv_5 = nn.Conv2d(nf, 6, 3, 1, 1, bias=True)  # 6f

        # pooling
        #self.avg_pool = nn.AvgPool2d(2)
        self.global_avg_pool = nn.AdaptiveAvgPool2d(1)

        # activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)
Esempio n. 3
0
    def __init__(self, in_nc=3, nf=64):
        super(ResNet_alpha_beta_sconv_3d, self).__init__()

        self.conv_1 = nn.Conv3d(in_channels=in_nc,
                                out_channels=nf,
                                kernel_size=(3, 3, 3),
                                stride=1,
                                padding=(0, 0, 0),
                                bias=True)
        basic_block_64 = functools.partial(mutil.ResidualBlock_noBN_3D, nf=nf)
        self.encoder1 = mutil.make_layer(basic_block_64, 2)  # 64f
        self.down_conv_1 = nn.Conv3d(nf,
                                     nf, (1, 4, 4), (1, 2, 2), (0, 1, 1),
                                     bias=False)

        self.conv_2 = nn.Conv3d(nf,
                                nf * 2, (3, 3, 3),
                                stride=1,
                                padding=(0, 0, 0),
                                bias=True)  # 128f
        basic_block_128 = functools.partial(mutil.ResidualBlock_noBN_3D,
                                            nf=nf * 2)
        self.encoder2 = mutil.make_layer(basic_block_128, 2)  # 128f
        self.down_conv_2 = nn.Conv3d(nf * 2,
                                     nf * 2, (1, 4, 4), (1, 2, 2), (0, 1, 1),
                                     bias=False)

        self.conv_3 = nn.Conv3d(nf * 2,
                                nf * 4, (3, 3, 3),
                                stride=1,
                                padding=(0, 0, 0),
                                bias=True)  # 256f
        basic_block_256 = functools.partial(mutil.ResidualBlock_noBN_3D,
                                            nf=nf * 4)
        self.encoder3 = mutil.make_layer(basic_block_256, 2)  # 256f
        self.down_conv_3 = nn.Conv3d(nf * 4,
                                     nf * 4, (1, 4, 4), (1, 2, 2), (0, 1, 1),
                                     bias=False)

        self.conv_4 = nn.Conv3d(nf * 4,
                                nf, (3, 3, 3),
                                stride=1,
                                padding=(0, 1, 1),
                                bias=True)  # 64f
        self.conv_5 = nn.Conv3d(nf,
                                6, (3, 3, 3),
                                stride=1,
                                padding=(0, 1, 1),
                                bias=True)  # 6f

        # pooling
        #self.avg_pool = nn.AvgPool2d(2)
        self.global_avg_pool = nn.AdaptiveAvgPool2d(1)

        # activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        # padding
        self.pad_3d = nn.ReplicationPad3d(1)
Esempio n. 4
0
    def __init__(self, in_nc=3, out_nc=3, nf=64, nb=32, cond_dim=2):
        super(CResMDNet, self).__init__()

        # condition mapping
        self.global_scale = nn.Linear(cond_dim, out_nc, bias=True)

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 2, 1, bias=True)

        basic_block = functools.partial(ResidualBlock_CRes,
                                        nf=nf,
                                        cond_dim=cond_dim)
        self.recon_trunk = arch_util.make_layer(basic_block, nb)

        self.upconv = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
        self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.act = nn.ReLU(inplace=True)

        # initialization
        arch_util.initialize_weights(
            [self.conv_first, self.upconv, self.HRconv, self.conv_last], 0.1)
        arch_util.initialize_weights([self.global_scale], 0.1)
Esempio n. 5
0
    def __init__(self, in_nc=3, out_nc=3, nf=64, nb=16, upscale=4):
        super(SRResNet, self).__init__()
        self.upscale = upscale

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        basic_block = functools.partial(arch_util.ResidualBlock_noBN, nf=nf)
        self.recon_trunk = arch_util.make_layer(basic_block, nb)
        self.LRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)

        # upsampling
        if self.upscale == 2:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)
        elif self.upscale == 3:
            self.upconv1 = nn.Conv2d(nf, nf * 9, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(3)
        elif self.upscale == 4:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.upconv2 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        # activation function
        self.relu = nn.ReLU(inplace=True)

        # initialization
        arch_util.initialize_weights([self.conv_first, self.upconv1, self.HRconv, self.conv_last],
                                     0.1)
        if self.upscale == 4:
            arch_util.initialize_weights(self.upconv2, 0.1)
Esempio n. 6
0
    def __init__(self, in_nc, out_nc, nf, unf, nb, scale=4):
        super(PAN, self).__init__()
        # SCPA
        SCPA_block_f = functools.partial(SCPA, nf=nf, reduction=2)
        self.scale = scale

        ### first convolution
        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)

        ### main blocks
        self.SCPA_trunk = arch_util.make_layer(SCPA_block_f, nb)
        self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)

        #### upsampling
        self.upconv1 = nn.Conv2d(nf, unf, 3, 1, 1, bias=True)
        self.att1 = PA(unf)
        self.HRconv1 = nn.Conv2d(unf, unf, 3, 1, 1, bias=True)

        if self.scale == 4:
            self.upconv2 = nn.Conv2d(unf, unf, 3, 1, 1, bias=True)
            self.att2 = PA(unf)
            self.HRconv2 = nn.Conv2d(unf, unf, 3, 1, 1, bias=True)

        self.conv_last = nn.Conv2d(unf, out_nc, 3, 1, 1, bias=True)
        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
Esempio n. 7
0
    def __init__(self, in_nc=3, out_nc=3, nf=64, nb=16, adafm_ksize=None):
        super(AdaFMNet, self).__init__()

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 2, 1, bias=True)

        if adafm_ksize is not None:
            basic_block = functools.partial(ResidualBlock_adafm,
                                            nf=nf,
                                            adafm_ksize=adafm_ksize)
        else:
            basic_block = functools.partial(arch_util.ResidualBlock_noBN,
                                            nf=nf)
        self.recon_trunk = arch_util.make_layer(basic_block, nb)

        self.LR_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.adafm = nn.Conv2d(nf,
                               nf,
                               kernel_size=adafm_ksize,
                               padding=(adafm_ksize - 1) // 2,
                               groups=nf,
                               bias=True)

        self.upconv = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
        self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        arch_util.initialize_weights(
            [self.conv_first, self.upconv, self.HRconv, self.conv_last], 0.1)
        arch_util.initialize_weights([self.adafm], 0.)

        self.relu = nn.ReLU(inplace=True)
Esempio n. 8
0
    def __init__(self, in_nc=3, out_nc=3, nf=64, nb=16, upscale=4, n_condition=32):
        super(MSRResNet_withSFT, self).__init__()
        self.upscale = upscale

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        basic_block = functools.partial(arch_util.ResidualBlock_noBN, nf=nf)
        self.recon_trunk = arch_util.make_layer(basic_block, nb)

        # upsampling
        if self.upscale == 2:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)
        elif self.upscale == 3:
            self.upconv1 = nn.Conv2d(nf, nf * 9, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(3)
        elif self.upscale == 4:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.upconv2 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        # activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        # initialization
        arch_util.initialize_weights([self.conv_first, self.upconv1, self.HRconv, self.conv_last],
                                     0.1)
        if self.upscale == 4:
            arch_util.initialize_weights(self.upconv2, 0.1)

        self.fc1 = nn.Linear(n_condition, 400)
        self.fc2 = nn.Linear(400, 400)
        self.fc3 = nn.Linear(400, n_condition)
    def __init__(self, in_nc=3, out_nc=3, nf=64, upscale=4):
        super(Coarse_Fine_RCANNet, self).__init__()
        self.upscale = upscale

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.conv_second = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_third = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        basic_block = functools.partial(network_block.ResidualBlock_noBN_CA,
                                        nf=nf)

        self.recon_trunk1 = arch_util.make_layer(basic_block, 5)
        self.recon_trunk2 = arch_util.make_layer(basic_block, 5)
        self.recon_trunk3 = arch_util.make_layer(basic_block, 6)

        # upsampling
        if self.upscale == 2:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)
        elif self.upscale == 3:
            self.upconv1 = nn.Conv2d(nf, nf * 9, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(3)
        elif self.upscale == 4:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.upconv2 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)
        elif self.upscale == 8:
            self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.upconv2 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.upconv3 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
            self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        # activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        # initialization
        arch_util.initialize_weights([
            self.conv_first, self.conv_second, self.conv_third, self.upconv1,
            self.HRconv, self.conv_last
        ], 0.1)
        if self.upscale == 4:
            arch_util.initialize_weights(self.upconv2, 0.1)
        if self.upscale == 8:
            arch_util.initialize_weights(self.upconv3, 0.1)
Esempio n. 10
0
    def __init__(self, in_nc=3, nf=64):
        super(ResNet_alpha_beta_decoder_3x3_IN_encoder_8HW, self).__init__()

        # encoder
        self.conv_1 = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)  # 64f
        basic_block_64 = functools.partial(mutil.ResidualBlock_IN, nf=nf)
        self.encoder1 = mutil.make_layer(basic_block_64, 2)  # 64f

        self.conv_2 = nn.Conv2d(nf, nf * 2, 3, 1, 1, bias=True)  # 128f
        basic_block_128 = functools.partial(mutil.ResidualBlock_IN, nf=nf * 2)
        self.encoder2 = mutil.make_layer(basic_block_128, 2)  # 128f

        self.conv_3 = nn.Conv2d(nf * 2, nf * 4, 3, 1, 1, bias=True)  # 256f
        basic_block_256 = functools.partial(mutil.ResidualBlock_IN, nf=nf * 4)
        self.encoder3 = mutil.make_layer(basic_block_256, 2)  # 256f

        self.conv_4 = nn.Conv2d(nf * 4, nf, 3, 1, 1, bias=True)  # 64f
        self.bn_4 = nn.InstanceNorm2d(nf, affine=True)
        self.conv_5 = nn.Conv2d(nf, 64, 3, 1, 1, bias=True)  # 64f

        # pooling
        self.avg_pool = nn.AvgPool2d(2)

        # activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        # decoder
        self.conv_6 = nn.Conv2d(64, 32, 3, 1, padding=1, bias=True)

        self.conv_7 = nn.Conv2d(96, 32, 3, 1, padding=1, bias=True)

        self.conv_8 = nn.Conv2d(32, 32, 3, 1, padding=1, bias=True)

        self.conv_9 = nn.Conv2d(288, 32, 3, 1, padding=1, bias=True)

        self.conv_10 = nn.Conv2d(32, 32, 3, 1, padding=1, bias=True)

        self.conv_11 = nn.Conv2d(160, 32, 3, 1, padding=1, bias=True)

        self.conv_12 = nn.Conv2d(32, 32, 3, 1, padding=1, bias=True)

        self.conv_13 = nn.Conv2d(96, 32, 3, 1, padding=1, bias=True)

        self.conv_14 = nn.Conv2d(32, 6, 3, 1, padding=1, bias=True)
Esempio n. 11
0
    def __init__(self, in_nc=1, out_nc=1, nf=32, nb=1, gc=32):
        super(RRDBNet_lite, self).__init__()
        RRDB_block_f = functools.partial(RRDB, nf=nf, gc=gc)

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.RRDB_trunk = arch_util.make_layer(RRDB_block_f, nb)
        self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        #### upsampling
        self.upconv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=False)
Esempio n. 12
0
    def __init__(self, in_nc, out_nc, nf, nb, gc=32):
        super(RRDBNetTRConv_16x, self).__init__()
        RRDB_block_f = functools.partial(RRDB, nf=nf, gc=gc)

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.RRDB_trunk = arch_util.make_layer(RRDB_block_f, nb)
        self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        #### upsampling
        self.tr_conv = nn.ConvTranspose2d(nf, nf, 2, 2, bias=True)
        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
Esempio n. 13
0
    def __init__(self, in_nc, out_nc, nf, nb):
        super(FastNet, self).__init__()
        BasicBlock_block_f = functools.partial(RRDB, nf=nf)

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.RRDB_trunk = arch_util.make_layer(BasicBlock_block_f, nb)
        self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        #### upsampling
        self.upconv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.upconv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
Esempio n. 14
0
    def __init__(self, nf=64, N_RBs=15, in_dim=3, depthwise_separable=False):
        super(Conv_ResBlocks, self).__init__()
        if depthwise_separable:
            ResidualBlock_noBN_f = functools.partial(
                mutil.ResidualBlock_noBN_depthwise_separable, nf=nf)
        else:
            ResidualBlock_noBN_f = functools.partial(mutil.ResidualBlock_noBN,
                                                     nf=nf)

        #### extract features
        self.conv_first = nn.Conv2d(in_dim, nf, 3, 1, 1, bias=True)
        self.res_blocks = mutil.make_layer(ResidualBlock_noBN_f, N_RBs)

        #### activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)
Esempio n. 15
0
    def __init__(self, in_nc, out_nc, nf, nb, gc=32, upscale=2):
        super(RRDBNet, self).__init__()
        self.upscale = upscale
        assert (upscale == 2 or upscale == 4)
        RRDB_block_f = functools.partial(RRDB, nf=nf, gc=gc)

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.RRDB_trunk = arch_util.make_layer(RRDB_block_f, nb)
        self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        #### upsampling
        self.upconv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        if self.upscale == 4:
            self.upconv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
Esempio n. 16
0
    def __init__(self, in_nc=3, out_nc=3, nf=64, nb=32):
        super(BaseNet, self).__init__()

        self.conv_first = nn.Conv2d(in_nc, nf, 3, 2, 1, bias=True)

        basic_block = functools.partial(arch_util.ResidualBlock_noBN, nf=nf)
        self.recon_trunk = arch_util.make_layer(basic_block, nb)

        self.upconv = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
        self.pixel_shuffle = nn.PixelShuffle(2)

        self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True)

        self.act = nn.ReLU(inplace=True)

        # initialization
        arch_util.initialize_weights(
            [self.conv_first, self.upconv, self.HRconv, self.conv_last], 0.1)
Esempio n. 17
0
    def __init__(self,
                 nf=64,
                 nframes=5,
                 groups=8,
                 front_RBs=5,
                 back_RBs=10,
                 center=None,
                 predeblur=False,
                 HR_in=False,
                 w_TSA=True,
                 deconv=True):
        super(MYEDVR_RES, self).__init__()
        self.nf = nf
        self.center = nframes // 2 if center is None else center
        self.is_predeblur = True if predeblur else False
        self.HR_in = True if HR_in else False
        self.w_TSA = w_TSA
        self.deconv = deconv
        ResidualBlock_noBN_f = functools.partial(arch_util.ResidualBlock_noBN,
                                                 nf=nf)

        #### extract features (for each frame)
        if self.is_predeblur:
            self.pre_deblur = Predeblur_ResNet_Pyramid(nf=nf, HR_in=self.HR_in)
            self.conv_1x1 = nn.Conv2d(nf, nf, 1, 1, bias=True)
        else:
            if self.HR_in:
                self.conv_first_1 = nn.Conv2d(3, nf, 3, 1, 1, bias=True)
                self.conv_first_2 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
                self.conv_first_3 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
            else:
                self.conv_first = nn.Conv2d(3, nf, 3, 1, 1, bias=True)
        self.feature_extraction = arch_util.make_layer(ResidualBlock_noBN_f,
                                                       front_RBs)
        self.fea_L2_conv1 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
        self.fea_L2_conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)
        self.fea_L3_conv1 = nn.Conv2d(nf, nf, 3, 2, 1, bias=True)
        self.fea_L3_conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True)

        self.pcd_align = PCD_Align(nf=nf, groups=groups)
        if self.w_TSA:
            self.tsa_fusion = TSA_Fusion(nf=nf,
                                         nframes=nframes,
                                         center=self.center)
        else:
            self.tsa_fusion = nn.Conv2d(nframes * nf, nf, 1, 1, bias=True)

        #### reconstruction
        self.recon_trunk = arch_util.make_layer(ResidualBlock_noBN_f, back_RBs)
        #### upsampling
        self.upconv1 = nn.Conv2d(nf, nf * 4, 3, 1, 1, bias=True)
        self.upconv2 = nn.Conv2d(nf, 64 * 4, 3, 1, 1, bias=True)
        self.pixel_shuffle = nn.PixelShuffle(2)
        self.HRconv = nn.Conv2d(64, 64, 3, 1, 1, bias=True)
        self.conv_last = nn.Conv2d(64, 3, 3, 1, 1, bias=True)

        #### activation function
        self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        ### denoise block
        self.denoise_block = FusionDenoise()
        self.denoise_extract_fea = nn.Sequential(
            nn.ReplicationPad3d(1),
            nn.Conv3d(nf,
                      nf,
                      kernel_size=(3, 3, 3),
                      stride=1,
                      padding=(0, 0, 0),
                      bias=True))

        ### deconv upsampling
        self.deconv_up = nn.ConvTranspose2d(3,
                                            64,
                                            kernel_size=4,
                                            stride=4,
                                            padding=0,
                                            output_padding=0,
                                            groups=1,
                                            bias=True,
                                            dilation=1,
                                            padding_mode='zeros')
        self.content_out = nn.Conv2d(64, 3, 3, 1, 1, bias=True)

        ### HF enhancer
        self.HF_enhancer = nn.Sequential(
            nn.Conv2d(3, nf, 3, 1, 1, bias=True),
            arch_util.make_layer(ResidualBlock_noBN_f, 3),
            nn.Conv2d(64, 3, 3, 1, 1, bias=True))