Ejemplo n.º 1
0
    def __init__(self, args, conv=common.default_conv):
        super(RCAN, self).__init__()
        self.args = args
        
        self.n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        reduction = args.reduction 
        scale = args.scale[0]
        act = nn.ReLU(True)
        
        # RGB mean for DIV2K
        self.sub_mean = common.MeanShift(args.rgb_range)
        
        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        for group_id in range(self.n_resgroups):
            setattr(self, 'body_group{}'.format(str(group_id)), ResidualGroup(conv, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks))
        self.body_tail = conv(n_feats, n_feats, kernel_size)

        # define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)]

        self.add_mean = common.MeanShift(args.rgb_range, sign=1)

        self.head = nn.Sequential(*modules_head)
        self.tail = nn.Sequential(*modules_tail)
Ejemplo n.º 2
0
    def __init__(self, args, conv=common.default_conv):
        super(EDSR, self).__init__()
        n_resblock = args['n_resblocks']
        n_feats = args['n_feats']
        kernel_size = 3
        scale = args['scale']
        act = nn.ReLU(True)

        # RGB mean for DIV2K
        rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args['rgb_range'], rgb_mean, rgb_std)

        # define head module
        m_head = [conv(args['n_colors'], n_feats, kernel_size)]

        # define body module
        m_body = [
            common.ResBlock(conv, n_feats, kernel_size, act=act, res_scale=args['res_scale']) for _ in range(n_resblock)
        ]
        m_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        m_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args['n_colors'], kernel_size)
        ]

        self.add_mean = common.MeanShift(args['rgb_range'], rgb_mean, rgb_std, 1)
        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)
        self.tail = nn.Sequential(*m_tail)
Ejemplo n.º 3
0
    def __init__(self, args, conv=common.default_conv):
        super(FERM, self).__init__()

        in_channel = 3
        out_channel = 3
        n_feats = 64
        act = nn.ReLU(True)
        n_resblocks = 20
        n_resgroups = 10
        bn = False

        # RGB mean for DIV2K
        self.sub_mean = common.MeanShift(1)
        self.add_mean = common.MeanShift(1, sign=1)

        head = [conv(in_channel, n_feats)]

        body = [
            RG(conv, n_feats, bn=bn, act=act, n_resblocks=n_resblocks) \
            for _ in range(n_resgroups)]
        body.append(conv(n_feats, n_feats))

        tail = [conv(n_feats, n_feats), conv(n_feats, out_channel)]

        self.head = nn.Sequential(*head)
        self.body = nn.Sequential(*body)
        self.tail = nn.Sequential(*tail)
    def __init__(self, args, conv=common.default_conv):
        super(EDSR, self).__init__()

        self.args = args
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        scale = args.scale[0]
        act = nn.ReLU(True)
        self.sub_mean = common.MeanShift(args.rgb_range)
        self.add_mean = common.MeanShift(args.rgb_range, sign=1)

        # define head module
        m_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        self.block_num = [
            int(n_resblocks / 3),
            int(2 * n_resblocks / 3) - int(n_resblocks / 3),
            n_resblocks - int(2 * n_resblocks / 3)
        ]

        m_body1 = [
            common.ResBlock(conv,
                            n_feats,
                            kernel_size,
                            act=act,
                            res_scale=args.res_scale)
            for _ in range(self.block_num[0])
        ]
        m_body2 = [
            common.ResBlock(conv,
                            n_feats,
                            kernel_size,
                            act=act,
                            res_scale=args.res_scale)
            for _ in range(self.block_num[1])
        ]
        m_body3 = [
            common.ResBlock(conv,
                            n_feats,
                            kernel_size,
                            act=act,
                            res_scale=args.res_scale)
            for _ in range(self.block_num[2])
        ]

        m_body3.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        m_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.head = nn.Sequential(*m_head)
        self.body1 = nn.Sequential(*m_body1)
        self.body2 = nn.Sequential(*m_body2)
        self.body3 = nn.Sequential(*m_body3)
        self.tail = nn.Sequential(*m_tail)
Ejemplo n.º 5
0
    def __init__(self, args, conv=common.default_conv):
        super(RCAN, self).__init__()

        n_resgroups = args['n_resgroups']
        n_resblocks = args['n_resblocks']
        n_feats = args['n_feats']
        kernel_size = 3
        reduction = args['reduction']
        scale = args['scale']
        act = nn.ReLU(True)

        # RGB mean for DIV2K
        rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args['rgb_range'], rgb_mean, rgb_std)
        #define head module
        modules_head = [conv(args['n_colors'], n_feats, kernel_size)]

        #define body module
        modules_body = [
            ResidualGroup(
                conv, n_feats, kernel_size, reduction, act=act, res_scale=args['res_scale'], n_resblocks=n_resblocks
            ) for _ in range(n_resgroups)
        ]

        #define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args['n_colors'], kernel_size)
        ]
        self.add_mean = common.MeanShift(args['rgb_range'], rgb_mean, rgb_std, 1)
        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)
Ejemplo n.º 6
0
    def __init__(self, args, conv=common.default_conv):
        super(SAN, self).__init__()
        n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        reduction = args.reduction
        scale = args.scale[0]
        act = nn.ReLU(inplace=True)

        # RGB mean for DIV2K
        rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std)
        # self.soca= SOCA(n_feats, reduction=reduction)

        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        ## share-source skip connection

        ##
        self.gamma = nn.Parameter(torch.zeros(1))
        # self.gamma = 0.2
        self.n_resgroups = n_resgroups
        self.RG = nn.ModuleList([LSRAG(conv, n_feats, kernel_size, reduction, \
                                              act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) for _ in range(n_resgroups)])
        self.conv_last = conv(n_feats, n_feats, kernel_size)

        # modules_body = [
        #     ResidualGroup(
        #         conv, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
        #     for _ in range(n_resgroups)]
        # modules_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.add_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std, 1)
        self.non_local = Nonlocal_CA(in_feat=n_feats,
                                     inter_feat=n_feats // 4,
                                     reduction=8,
                                     sub_sample=False,
                                     bn_layer=False)

        self.head = nn.Sequential(*modules_head)
        # self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)

        if n_resgroups == 20:
            self.pos = [6, 13]
        elif n_resgroups == 6:
            self.pos = [1, 3]
    def __init__(self, args, conv=common.default_conv):
        conv = common.default_conv
        conv_1x1 = common.conv_1x1_9_layer
        super(RCAN, self).__init__()
        self.args = args
        n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        reduction = args.reduction
        scale = args.scale
        if args.act_ver == 1:
            act = nn.ReLU(True)
        elif args.act_ver == 2:
            act = nn.LeakyReLU(negative_slope=0.01, inplace=True)
        elif args.act_ver == 3:
            act = nn.PReLU()

        # RGB mean for DIV2K
        # rgb_mean = (0.4488, 0.4371, 0.4040)
        # rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std)

        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        # 3x3 conv, secure receptive field modules (original)
        modules_body = [
            ResidualGroup(
                conv, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
            for _ in range(3)]
        # 1x1 conv, secure depth modules
        modules_body += [
            ResidualGroup_1x1(
                conv_1x1, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
            for _ in range(3, n_resgroups)]
        modules_body.append(conv_1x1(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.add_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std, 1)

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)
    def __init__(self, args, conv=common.default_conv):
        conv = common.default_conv
        conv1x1 = common.conv_1x1_9_layer
        super(EDSR, self).__init__()
        self.args = args
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        scale = args.scale
        act = nn.ReLU(True)
        # url_name = 'r{}f{}x{}'.format(n_resblocks, n_feats, scale)
        # if url_name in url:
        #     self.url = url[url_name]
        # else:
        #     self.url = None
        self.sub_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std)
        self.add_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std, 1)

        # define head module
        m_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        # 3x3 conv, secure receptive field modules (original)
        m_body = [
            common.ResBlock(conv,
                            n_feats,
                            kernel_size,
                            act=act,
                            res_scale=args.res_scale) for _ in range(60)
        ]
        # 1x1 conv, secure depth modules
        m_body += [
            common.ResBlock(conv1x1,
                            n_feats,
                            kernel_size,
                            act=act,
                            res_scale=args.res_scale)
            for _ in range(60, n_resblocks)
        ]
        m_body.append(conv1x1(n_feats, n_feats, kernel_size))

        # define tail module
        m_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)
        self.tail = nn.Sequential(*m_tail)
Ejemplo n.º 9
0
    def __init__(self, args, in_nc, out_nc, nf, nb, gc=32): # nb:23
        super(RRDBNet, self).__init__()
        RRDB_block_f = functools.partial(RRDB, nf=nf, gc=gc)
        self.args = args
        self.ref_model = args.RRDB_ref

        self.sub_mean = common.MeanShift(args.rgb_range, args.rgb_mean, args.rgb_std)
        self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True)
        self.RRDB_trunk = 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.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.add_mean = common.MeanShift(args.rgb_range, args.rgb_mean, args.rgb_std, 1)
        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
Ejemplo n.º 10
0
    def __init__(self, n_feats, rgb_range):
        super(RIDNET, self).__init__()

        kernel_size = 3

        rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_std = (1.0, 1.0, 1.0)

        self.sub_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std)
        self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1)

        self.head = ops.BasicBlock(3, n_feats, kernel_size, 1, 1)
        self.conv = nn.Conv2d((3 + n_feats), n_feats, kernel_size, 1, 1)
        self.b1 = Block(n_feats, n_feats)
        self.b2 = Block(n_feats, n_feats)
        self.b3 = Block(n_feats, n_feats)
        self.b4 = Block(n_feats, n_feats)

        self.tail = nn.Conv2d(n_feats, 3, kernel_size, 1, 1, 1)
Ejemplo n.º 11
0
    def __init__(self, args, conv=common.default_conv):
        super(RCAN, self).__init__()

        ##added
        # self.down4x = nn.Upsample(scale_factor=4, mode='bilinear')
        ###
        n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        reduction = args.reduction
        scale = args.scale[0]
        act = nn.ReLU(True)

        # RGB mean for DIV2K
        rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std)

        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        modules_body = [
            ResidualGroup(
                conv, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
            for _ in range(n_resgroups)]

        modules_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.add_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std, 1)

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)
Ejemplo n.º 12
0
    def __init__(self, conv_index, rgb_range=1):
        super(VGG, self).__init__()
        vgg_features = models.vgg19(pretrained=True).features
        modules = [m for m in vgg_features]
        if conv_index == '22':
            self.vgg = nn.Sequential(*modules[:8])
        elif conv_index == '54':
            self.vgg = nn.Sequential(*modules[:35])

        vgg_mean = (0.485, 0.456, 0.406)
        vgg_std = (0.229 * rgb_range, 0.224 * rgb_range, 0.225 * rgb_range)
        self.sub_mean = common.MeanShift(rgb_range, vgg_mean, vgg_std)
        self.vgg.requires_grad = False
Ejemplo n.º 13
0
    def __init__(self, args, conv=common.default_conv):
        super(SWLA, self).__init__()
        self.args = args
        self.scale = args.scale
        self.lr_p_size = args.patch_size // self.scale
        self.device = torch.device('cpu' if args.cpu else 'cuda')
        n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        act = nn.ReLU(True)

        # RGB mean for DIV2K
        # rgb_mean = (0.4488, 0.4371, 0.4040)
        # rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args.rgb_range, args.rgb_mean, args.rgb_std)

        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        modules_body = [
            ResidualGroup(
                conv, n_feats, kernel_size, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
            for _ in range(n_resgroups)]

        modules_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            common.Upsampler(conv, self.args.scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)]

        self.add_mean = common.MeanShift(args.rgb_range, args.rgb_mean, args.rgb_std, 1)

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)
    def __init__(self, args, conv=common.default_conv):
        super(SAN, self).__init__()
        self.args = args
        conv = common.default_conv
        conv1x1 = common.conv_1x1_9_layer
        n_resgroups = args.n_resgroups
        n_resblocks = args.n_resblocks
        n_feats = args.n_feats
        kernel_size = 3
        reduction = args.reduction
        scale = args.scale
        act = nn.ReLU(inplace=True)  # change it to leaky relu???!#!#!#!#
        if args.act_ver == 1:
            act = nn.ReLU(True)
        elif args.act_ver == 2:
            act = nn.LeakyReLU(negative_slope=0.2, inplace=True)
        elif args.act_ver == 3:
            act = nn.PReLU()

        # RGB mean for DIV2K
        # rgb_mean = (0.4488, 0.4371, 0.4040)
        # rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std)
        # self.soca= SOCA(n_feats, reduction=reduction)

        # define head module
        modules_head = [conv(args.n_colors, n_feats, kernel_size)]

        # define body module
        ## share-source skip connection

        ##
        self.gamma = nn.Parameter(torch.zeros(1))
        # self.gamma = 0.2
        self.n_resgroups = n_resgroups
        # 3x3 conv, secure proper receptive field area

        RG = [LSRAG(conv, n_feats, kernel_size, reduction, \
                                       act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) for _ in
                                 range(3)]
        # 1x1 conv, secure depth area
        RG += [LSRAG(conv1x1, n_feats, kernel_size, reduction, \
                                       act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) for _ in
                                 range(3, n_resgroups)]
        self.RG = nn.ModuleList(RG)
        self.conv_last = conv1x1(n_feats, n_feats, kernel_size)

        # modules_body = [
        #     ResidualGroup(
        #         conv, n_feats, kernel_size, reduction, act=act, res_scale=args.res_scale, n_resblocks=n_resblocks) \
        #     for _ in range(n_resgroups)]
        # modules_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, args.n_colors, kernel_size)
        ]

        self.add_mean = common.MeanShift(args.rgb_range, args.rgb_mean,
                                         args.rgb_std, 1)
        self.non_local = Nonlocal_CA(in_feat=n_feats,
                                     inter_feat=n_feats // 8,
                                     reduction=8,
                                     sub_sample=False,
                                     bn_layer=False)

        self.head = nn.Sequential(*modules_head)
        # self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)