コード例 #1
0
    def __init__(self, n_resblocks=16, n_feats=64, nf=None, scale=4, rgb_range=255, n_colors=3, res_scale=1,
                 conv=common.default_conv, **kwargs):
        super(EDSR_layerwise_Model, self).__init__()

        n_resblocks = n_resblocks
        n_feats = n_feats if nf is None else nf
        kernel_size = 3
        act = nn.ReLU(True)

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

        # 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))

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

        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)
        self.tail = nn.Sequential(*m_tail)
コード例 #2
0
    def __init__(self,
                 n_resblocks=16,
                 n_feats=64,
                 rgb_range=255,
                 n_colors=3,
                 conv=common.default_conv,
                 **kwargs):
        super(VDSR_Model, self).__init__()

        n_resblocks = n_resblocks
        n_feats = n_feats
        kernel_size = 3
        self.sub_mean = common.MeanShift(rgb_range)
        self.add_mean = common.MeanShift(rgb_range, sign=1)

        def basic_block(in_channels, out_channels, act):
            return common.BasicBlock(conv,
                                     in_channels,
                                     out_channels,
                                     kernel_size,
                                     bias=True,
                                     bn=False,
                                     act=act)

        # define body module
        m_body = []
        m_body.append(basic_block(n_colors, n_feats, nn.ReLU(True)))
        for _ in range(n_resblocks - 2):
            m_body.append(basic_block(n_feats, n_feats, nn.ReLU(True)))
        m_body.append(basic_block(n_feats, n_colors, None))

        self.body = nn.Sequential(*m_body)
コード例 #3
0
ファイル: csnln_model.py プロジェクト: wukailu/EDSR-PyTorch
    def __init__(self,
                 depth=12,
                 rgb_range=255,
                 n_colors=3,
                 n_feats=64,
                 scale=4,
                 conv=common.default_conv,
                 **kwargs):
        super(CSNLN_Model, self).__init__()

        # n_convblock = args.n_convblocks
        self.depth = depth
        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)

        # define head module
        m_head = [
            common.BasicBlock(conv,
                              n_colors,
                              n_feats,
                              kernel_size,
                              stride=1,
                              bias=True,
                              bn=False,
                              act=nn.PReLU()),
            common.BasicBlock(conv,
                              n_feats,
                              n_feats,
                              kernel_size,
                              stride=1,
                              bias=True,
                              bn=False,
                              act=nn.PReLU())
        ]

        # define Self-Exemplar Mining Cell
        self.SEM = RecurrentProjection(n_feats, scale=scale)

        # define tail module
        m_tail = [
            nn.Conv2d(n_feats * self.depth,
                      n_colors,
                      kernel_size,
                      padding=(kernel_size // 2))
        ]

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

        self.head = nn.Sequential(*m_head)
        self.tail = nn.Sequential(*m_tail)
コード例 #4
0
    def __init__(self, scale=4, rgb_range=255, n_feats=128, n_colors=3, **kwargs):
        super(DDBPN_Model, self).__init__()

        n0 = n_feats
        nr = 32
        self.depth = 6

        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)
        initial = [
            nn.Conv2d(n_colors, n0, 3, padding=1),
            nn.PReLU(n0),
            nn.Conv2d(n0, nr, 1),
            nn.PReLU(nr)
        ]
        self.initial = nn.Sequential(*initial)

        self.upmodules = nn.ModuleList()
        self.downmodules = nn.ModuleList()
        channels = nr
        for i in range(self.depth):
            self.upmodules.append(
                DenseProjection(channels, nr, scale, True, i > 1)
            )
            if i != 0:
                channels += nr
        
        channels = nr
        for i in range(self.depth - 1):
            self.downmodules.append(
                DenseProjection(channels, nr, scale, False, i != 0)
            )
            channels += nr

        reconstruction = [
            nn.Conv2d(self.depth * nr, n_colors, 3, padding=1)
        ]
        self.reconstruction = nn.Sequential(*reconstruction)

        self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1)
コード例 #5
0
    def __init__(self,
                 n_resgroups=10,
                 reduction=16,
                 res_scale=1,
                 n_resblocks=16,
                 n_feats=64,
                 rgb_range=255,
                 n_colors=3,
                 scale=4,
                 conv=common.default_conv,
                 **kwargs):
        super(RCAN_Model, self).__init__()
        kernel_size = 3
        act = nn.ReLU(True)

        # RGB mean for DIV2K
        self.sub_mean = common.MeanShift(rgb_range)

        # 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, res_scale=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, n_colors, kernel_size)
        ]

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

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)
コード例 #6
0
    def __init__(self,
                 n_resblocks=16,
                 n_feats=64,
                 rgb_range=255,
                 n_colors=3,
                 scale=4,
                 conv=common.default_conv):
        super(MDSR_Model, self).__init__()
        n_resblocks = n_resblocks
        n_feats = n_feats
        kernel_size = 3
        act = nn.ReLU(True)
        self.scale_idx = 0
        self.url = url['r{}f{}'.format(n_resblocks, n_feats)]
        self.sub_mean = common.MeanShift(rgb_range)
        self.add_mean = common.MeanShift(rgb_range, sign=1)

        m_head = [conv(n_colors, n_feats, kernel_size)]

        self.pre_process = nn.ModuleList([
            nn.Sequential(common.ResBlock(conv, n_feats, 5, act=act),
                          common.ResBlock(conv, n_feats, 5, act=act))
            for _ in scale
        ])

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

        self.upsample = nn.ModuleList(
            [common.Upsampler(conv, s, n_feats, act=False) for s in scale])

        m_tail = [conv(n_feats, n_colors, kernel_size)]

        self.head = nn.Sequential(*m_head)
        self.body = nn.Sequential(*m_body)
        self.tail = nn.Sequential(*m_tail)
コード例 #7
0
ファイル: han_model.py プロジェクト: wukailu/EDSR-PyTorch
    def __init__(self, n_resgroups=10, n_resblocks=16, n_feats=50, reduction=16, res_scale=1, scale=4, rgb_range=255, n_colors=3, conv=common.default_conv, **kwargs):
        super(HAN_Modle, self).__init__()

        n_resgroups = n_resgroups
        n_resblocks = n_resblocks
        kernel_size = 3
        reduction = reduction
        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, res_scale=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, 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.csa = CSAM_Module(n_feats)
        self.la = LAM_Module(n_feats)
        self.last_conv = nn.Conv2d(n_feats * 11, n_feats, 3, 1, 1)
        self.last = nn.Conv2d(n_feats * 2, n_feats, 3, 1, 1)
        self.tail = nn.Sequential(*modules_tail)
コード例 #8
0
ファイル: vgg.py プロジェクト: wukailu/EDSR-PyTorch
    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.find('22') >= 0:
            self.vgg = nn.Sequential(*modules[:8])
        elif conv_index.find('54') >= 0:
            self.vgg = nn.Sequential(*modules[:35])
        else:
            raise KeyError("must be vgg22 or vgg54")

        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)
        for p in self.parameters():
            p.requires_grad = False