Esempio n. 1
0
    def __init__(self,
                 num_block,
                 num_feature,
                 scale,
                 n_colors=15,
                 res_scale=0.1,
                 conv=common.default_conv,
                 isTrain=True):
        super(EDSR, self).__init__()

        n_resblocks = num_block
        n_feats = num_feature
        scale = scale
        kernel_size = 3
        act = nn.LeakyReLU(negative_slope=0.1, inplace=True)

        # define head module

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

        self.body = nn.Sequential(*m_body)

        self.down_x2 = nn.Sequential(
            nn.Conv2d(n_feats, n_feats, kernel_size=3, stride=2, padding=1),
            act)
        self.up_x2 = common.Upsampler(conv, scale=2, n_feats=n_feats, act=act)

        self.down_x4 = nn.Sequential(
            nn.Conv2d(n_feats, n_feats, kernel_size=3, stride=2, padding=1),
            act)
        self.up_x4 = common.Upsampler(conv, scale=2, n_feats=n_feats, act=act)

        self.upsampler_2 = common.Upsampler(conv,
                                            scale=2,
                                            n_feats=n_feats,
                                            act=act)
        self.upsampler_4 = common.Upsampler(conv,
                                            scale=4,
                                            n_feats=n_feats,
                                            act=act)

        self.head_y = conv(5, n_feats, kernel_size)
        self.head_uv = conv(10, n_feats, kernel_size)

        self.y_out = conv(n_feats, 1, kernel_size)

        self.uv_out = conv(n_feats, 2, kernel_size)

        self.isTrain = isTrain
Esempio n. 2
0
    def __init__(self,
                 num_block,
                 num_feature,
                 scale,
                 n_colors=15,
                 res_scale=0.1,
                 conv=common.default_conv,
                 isTrain=True):
        super(EDSR, self).__init__()

        n_resblocks = num_block
        n_feats = num_feature
        scale = scale
        kernel_size = 3
        act = nn.ReLU(True)

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

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

        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)

        self.uv_up2 = common.Upsampler(conv, scale=2, n_feats=10, act=False)

        self.y_out_up4 = common.Upsampler(conv,
                                          scale=4,
                                          n_feats=n_feats,
                                          act=False)

        self.uv_out_up2 = common.Upsampler(conv,
                                           scale=2,
                                           n_feats=n_feats,
                                           act=False)

        self.y_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=5, act=False),
            conv(5, n_feats, kernel_size))

        self.y_out = conv(n_feats, 1, kernel_size)

        self.uv_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=10, act=False),
            conv(10, n_feats, kernel_size))

        self.uv_out = conv(n_feats, 2, kernel_size)

        self.isTrain = isTrain
Esempio n. 3
0
    def __init__(self,
                 conv=default_conv,
                 isTrain=True,
                 num_feature=64):  # 这个con是最最普通的那种卷积
        super(RCAN, self).__init__()

        n_resgroups = 10  # 残差组的数量
        n_resblocks = 20  # 残差块的数量
        n_feats = num_feature  # 特征的数量,即通道
        kernel_size = 3
        reduction = 16  # 论文中的那个r因子
        scale = 4  # 默认只进行一个因子的训练
        act = nn.ReLU(True)  # True就是进行原位运算

        # define head module
        modules_head = [conv(15, n_feats, 3)]  # n_colors使用的通道数

        # define body module
        modules_body = [
            ResidualGroup(  # act激活函数,残差缩放比例
                conv, n_feats, kernel_size, reduction, act=act, res_scale=1, n_resblocks=n_resblocks) \
            for _ in range(n_resgroups)]

        modules_body.append(conv(n_feats, n_feats, kernel_size))  # 主体尾巴那个小卷积层

        self.uv_up2 = common.Upsampler(conv, scale=2, n_feats=10, act=False)

        self.y_out_up4 = common.Upsampler(conv,
                                          scale=4,
                                          n_feats=n_feats,
                                          act=False)

        self.uv_out_up2 = common.Upsampler(conv,
                                           scale=2,
                                           n_feats=n_feats,
                                           act=False)

        self.y_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=5, act=False),
            conv(5, n_feats, kernel_size))

        self.yy_out = conv(n_feats, 1, kernel_size)

        self.uv_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=10, act=False),
            conv(10, n_feats, kernel_size))

        self.uuv_out = conv(n_feats, 2, kernel_size)

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.PS = nn.PixelShuffle(scale)
        self.isTrain = isTrain
Esempio n. 4
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)
    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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
    def __init__(self,
                 num_block,
                 num_feature,
                 scale,
                 n_colors=15,
                 res_scale=0.1,
                 conv=common.default_conv,
                 isTrain=True):
        super(UNET, self).__init__()

        n_resblocks = num_block
        n_feats = num_feature
        scale = scale
        kernel_size = 3
        act = nn.ReLU(True)

        self.head = common.default_conv(n_colors, n_feats, kernel_size)
        self.inc = common.inconv(num_feature, num_feature)
        self.down1 = common.down(num_feature, num_feature)
        self.down2 = common.down(num_feature, num_feature)
        self.up1 = common.up(num_feature, num_feature)
        self.up2 = common.up(num_feature, num_feature)

        self.uv_up2 = common.Upsampler(conv, scale=2, n_feats=10, act=False)
        self.y_out_up4 = common.Upsampler(conv,
                                          scale=4,
                                          n_feats=n_feats,
                                          act=False)

        self.uv_out_up2 = common.Upsampler(conv,
                                           scale=2,
                                           n_feats=n_feats,
                                           act=False)

        self.y_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=5, act=False),
            conv(5, n_feats, kernel_size))
        self.y_out = conv(n_feats, 1, kernel_size)

        self.uv_res_up4 = nn.Sequential(
            common.Upsampler(conv, scale=4, n_feats=10, act=False),
            conv(10, n_feats, kernel_size))

        self.uv_out = conv(n_feats, 2, kernel_size)

        self.isTrain = isTrain
Esempio n. 9
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
        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)
    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)
Esempio n. 12
0
    def __init__(self, args, conv=default_conv):
        super(RCANModule, self).__init__()

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

        self.weight_3 = nn.Sequential(
            nn.Conv2d(n_colors * 3, n_colors, kernel_size=1, stride=1),
            nn.ReLU(True), nn.Conv2d(n_colors, 3, kernel_size=1, stride=1),
            nn.Softmax(dim=1))

        # define head module
        modules_head = [conv(in_size, 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
        if self.sr_factor == 1:
            modules_tail = [
                conv(n_feats, n_feats, 3),
                nn.ReLU(True),
                conv(n_feats, n_colors, 3)
            ]

        else:
            modules_tail = [
                common.Upsampler(conv, self.sr_factor, n_feats, act=False),
                conv(n_feats, n_colors, 3)
            ]

        # 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)
Esempio n. 13
0
    def __init__(self,
                 n_colors,
                 n_resgroups=10,
                 n_resblocks=20,
                 n_feats=64,
                 reduction=16,
                 upsampler_scale=1,
                 conv=common.default_conv):
        super(RCAN, self).__init__()

        n_resgroups = n_resgroups
        n_resblocks = n_resblocks
        n_feats = n_feats
        kernel_size = 3
        reduction = reduction
        scale = int(upsampler_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(rgb_range, rgb_mean, rgb_std)

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

        # define body module
        modules_body = [
            ResidualGroup(conv,
                          n_feats,
                          kernel_size,
                          reduction,
                          act=act,
                          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, n_colors, kernel_size)
        ]

        # self.add_mean = common.MeanShift(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)
Esempio n. 14
0
    def __init__(self,
                 conv=common.default_conv,
                 n_resblock=8,
                 n_filters=64,
                 scale=4,
                 rgb_range=255,
                 n_colors=1,
                 res_scale=1):
        super(EDSR, self).__init__()

        # n_resblock = args.n_resblocks
        # n_feats = args.n_feats
        kernel_size = 3
        # scale = args.scale[0]
        act = nn.ReLU(True)

        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, -1)  # rgb_std)

        # define head module
        m_head = [conv(n_colors, n_filters, kernel_size)]

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

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

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

        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)
        self.tail = nn.Sequential(*m_tail)
Esempio n. 15
0
    def __init__(self, block, layers, num_classes=2, zero_init_residual=False):
        super(ResNet, self).__init__()
        self.inplanes = 64
        self.conv1 = nn.Conv2d(15,
                               64,
                               kernel_size=7,
                               stride=2,
                               padding=3,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.fc = nn.Linear(512 * block.expansion, num_classes)
        self.uv_up2 = common.Upsampler(common.default_conv,
                                       scale=2,
                                       n_feats=10,
                                       act=False)

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight,
                                        mode='fan_out',
                                        nonlinearity='relu')
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)

        # Zero-initialize the last BN in each residual branch,
        # so that the residual branch starts with zeros, and each residual block behaves like an identity.
        # This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677
        if zero_init_residual:
            for m in self.modules():
                if isinstance(m, Bottleneck):
                    nn.init.constant_(m.bn3.weight, 0)
                elif isinstance(m, BasicBlock):
                    nn.init.constant_(m.bn2.weight, 0)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
0
        data_uv_2x = PS(data_uv_2x)
        data_yuv = torch.cat([data_y, data_uv_2x], dim=1)
        outputs = cls_net(data_yuv)
        # print(len(outputs), len(cls_label))
        # print(outputs.size(), cls_label.squeeze().size())
        loss = criterion(outputs, cls_label.squeeze())
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

        if iteration % 20 == 0:
            print('Epoch [{}/{}], Step [{}/{}], Loss: {:.4f}'.format(
                epoch, config.numEpoch, iteration + 1, total_step,
                loss.item()))
    upsample = common.Upsampler(common.default_conv,
                                scale=2,
                                n_feats=10,
                                act=False)
    if epoch % 2 == 0:
        save_checkpoint(cls_net, None, epoch, config.checkpoint)
        correct = 0
        total = 0
        cls_net.eval()
        for iteration, batch in enumerate(test_data_loader, 1):
            data_y = batch[0]
            data_uv = batch[2]
            cls_label = batch[4]

            data_y = data_y.to(device)
            data_uv = data_uv.to(device)
            cls_label = cls_label.to(device)
            data_y -= 127.5
    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)