Exemplo n.º 1
0
    def __init__(self, in_nc=3, out_nc=3, nc=64, nb=8, upscale=4, act_mode='L', upsample_mode='pixelshuffle', negative_slope=0.05):
        """
        in_nc: channel number of input
        out_nc: channel number of output
        nc: channel number
        nb: number of residual blocks
        upscale: up-scale factor
        act_mode: activation function
        upsample_mode: 'upconv' | 'pixelshuffle' | 'convtranspose'
        """
        super(IMDN, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'

        m_head = B.conv(in_nc, nc, mode='C')
        m_body = [B.IMDBlock(nc, nc, mode='C'+act_mode, negative_slope=negative_slope) for _ in range(nb)]
        m_body.append(B.conv(nc, nc, mode='C'))

        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError('upsample mode [{:s}] is not found'.format(upsample_mode))

        m_uper = upsample_block(nc, out_nc, mode=str(upscale))

        self.model = B.sequential(m_head, B.ShortcutBlock(B.sequential(*m_body)), *m_uper)
Exemplo n.º 2
0
    def __init__(self,
                 in_nc=3,
                 out_nc=3,
                 nc=64,
                 nb=16,
                 upscale=4,
                 act_mode='R',
                 upsample_mode='upconv'):
        """
        in_nc: channel number of input
        out_nc: channel number of output
        nc: channel number
        nb: number of residual blocks
        upscale: up-scale factor
        act_mode: activation function
        upsample_mode: 'upconv' | 'pixelshuffle' | 'convtranspose'
        """
        super(MSRResNet0, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'

        n_upscale = int(math.log(upscale, 2))
        if upscale == 3:
            n_upscale = 1

        m_head = B.conv(in_nc, nc, mode='C')

        m_body = [
            B.ResBlock(nc, nc, mode='C' + act_mode + 'C') for _ in range(nb)
        ]
        m_body.append(B.conv(nc, nc, mode='C'))

        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError(
                'upsample mode [{:s}] is not found'.format(upsample_mode))
        if upscale == 3:
            m_uper = upsample_block(nc, nc, mode='3' + act_mode)
        else:
            m_uper = [
                upsample_block(nc, nc, mode='2' + act_mode)
                for _ in range(n_upscale)
            ]

        H_conv0 = B.conv(nc, nc, mode='C' + act_mode)
        H_conv1 = B.conv(nc, out_nc, bias=False, mode='C')
        m_tail = B.sequential(H_conv0, H_conv1)

        self.model = B.sequential(m_head,
                                  B.ShortcutBlock(B.sequential(*m_body)),
                                  *m_uper, m_tail)
Exemplo n.º 3
0
    def __init__(self, in_nc=1, out_nc=1, nc=64, nb=15, act_mode='R'):
        """
        # ------------------------------------
        in_nc: channel number of input
        out_nc: channel number of output
        nc: channel number
        nb: total number of conv layers
        act_mode: batch norm + activation function; 'BR' means BN+ReLU.
        # ------------------------------------
        # ------------------------------------
        """
        super(FFDNet, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'
        bias = True
        sf = 2

        self.m_down = B.PixelUnShuffle(upscale_factor=sf)

        m_head = B.conv(in_nc * sf * sf + 1,
                        nc,
                        mode='C' + act_mode[-1],
                        bias=bias)
        m_body = [
            B.conv(nc, nc, mode='C' + act_mode, bias=bias)
            for _ in range(nb - 2)
        ]
        m_tail = B.conv(nc, out_nc * sf * sf, mode='C', bias=bias)

        self.model = B.sequential(m_head, *m_body, m_tail)

        self.m_up = nn.PixelShuffle(upscale_factor=sf)
Exemplo n.º 4
0
    def __init__(self, in_nc=1, out_nc=1, nc=64, nb=17, act_mode='BR'):
        """
        # ------------------------------------
        in_nc: channel number of input
        out_nc: channel number of output
        nc: channel number
        nb: total number of conv layers
        act_mode: batch norm + activation function; 'BR' means BN+ReLU.
        # ------------------------------------
        Batch normalization and residual learning are
        beneficial to Gaussian denoising (especially
        for a single noise level).
        The residual of a noisy image corrupted by additive white
        Gaussian noise (AWGN) follows a constant
        Gaussian distribution which stablizes batch
        normalization during training.
        # ------------------------------------
        """
        super(DnCNN, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'
        bias = True

        m_head = B.conv(in_nc, nc, mode='C' + act_mode[-1], bias=bias)
        m_body = [
            B.conv(nc, nc, mode='C' + act_mode, bias=bias)
            for _ in range(nb - 2)
        ]
        m_tail = B.conv(nc, out_nc, mode='C', bias=bias)

        self.model = B.sequential(m_head, *m_body, m_tail)
    def __init__(self, in_nc=3, base_nc=64, ac_type='BL'):
        super(Discriminator_VGG_192, self).__init__()
        # features
        # hxw, c
        # 192, 64
        conv0 = B.conv(in_nc, base_nc, kernel_size=3, mode='C')
        conv1 = B.conv(base_nc, base_nc, kernel_size=4, stride=2, mode='C'+ac_type)
        # 96, 64
        conv2 = B.conv(base_nc, base_nc*2, kernel_size=3, stride=1, mode='C'+ac_type)
        conv3 = B.conv(base_nc*2, base_nc*2, kernel_size=4, stride=2, mode='C'+ac_type)
        # 48, 128
        conv4 = B.conv(base_nc*2, base_nc*4, kernel_size=3, stride=1, mode='C'+ac_type)
        conv5 = B.conv(base_nc*4, base_nc*4, kernel_size=4, stride=2, mode='C'+ac_type)
        # 24, 256
        conv6 = B.conv(base_nc*4, base_nc*8, kernel_size=3, stride=1, mode='C'+ac_type)
        conv7 = B.conv(base_nc*8, base_nc*8, kernel_size=4, stride=2, mode='C'+ac_type)
        # 12, 512
        conv8 = B.conv(base_nc*8, base_nc*8, kernel_size=3, stride=1, mode='C'+ac_type)
        conv9 = B.conv(base_nc*8, base_nc*8, kernel_size=4, stride=2, mode='C'+ac_type)
        # 6, 512
        conv10 = B.conv(base_nc*8, base_nc*8, kernel_size=3, stride=1, mode='C'+ac_type)
        conv11 = B.conv(base_nc*8, base_nc*8, kernel_size=4, stride=2, mode='C'+ac_type)
        # 3, 512
        self.features = B.sequential(conv0, conv1, conv2, conv3, conv4, conv5,
                                     conv6, conv7, conv8, conv9, conv10, conv11)

        # classifier
        self.classifier = nn.Sequential(nn.Linear(512 * 3 * 3, 100),
                                        nn.LeakyReLU(0.2, True),
                                        nn.Linear(100, 1))
Exemplo n.º 6
0
    def __init__(self,
                 in_nc=3,
                 out_nc=3,
                 nc=64,
                 nb=23,
                 gc=32,
                 upscale=4,
                 act_mode='L',
                 upsample_mode='upconv'):
        super(RRDB, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'

        n_upscale = int(math.log(upscale, 2))
        if upscale == 3:
            n_upscale = 1

        m_head = B.conv(in_nc, nc, mode='C')

        m_body = [B.RRDB(nc, gc=32, mode='C' + act_mode) for _ in range(nb)]
        m_body.append(B.conv(nc, nc, mode='C'))

        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError(
                'upsample mode [{:s}] is not found'.format(upsample_mode))

        if upscale == 3:
            m_uper = upsample_block(nc, nc, mode='3' + act_mode)
        else:
            m_uper = [
                upsample_block(nc, nc, mode='2' + act_mode)
                for _ in range(n_upscale)
            ]

        H_conv0 = B.conv(nc, nc, mode='C' + act_mode)
        H_conv1 = B.conv(nc, out_nc, mode='C')
        m_tail = B.sequential(H_conv0, H_conv1)

        self.model = B.sequential(m_head,
                                  B.ShortcutBlock(B.sequential(*m_body)),
                                  *m_uper, m_tail)
Exemplo n.º 7
0
    def __init__(self,
                 in_nc=1,
                 out_nc=1,
                 nc=[64, 128, 256, 512],
                 nb=2,
                 act_mode='R',
                 downsample_mode='strideconv',
                 upsample_mode='convtranspose'):
        super(UNet, self).__init__()

        self.m_head = B.conv(in_nc, nc[0], mode='C' + act_mode[-1])

        # downsample
        if downsample_mode == 'avgpool':
            downsample_block = B.downsample_avgpool
        elif downsample_mode == 'maxpool':
            downsample_block = B.downsample_maxpool
        elif downsample_mode == 'strideconv':
            downsample_block = B.downsample_strideconv
        else:
            raise NotImplementedError(
                'downsample mode [{:s}] is not found'.format(downsample_mode))

        self.m_down1 = B.sequential(
            *[B.conv(nc[0], nc[0], mode='C' + act_mode) for _ in range(nb)],
            downsample_block(nc[0], nc[1], mode='2' + act_mode))
        self.m_down2 = B.sequential(
            *[B.conv(nc[1], nc[1], mode='C' + act_mode) for _ in range(nb)],
            downsample_block(nc[1], nc[2], mode='2' + act_mode))
        self.m_down3 = B.sequential(
            *[B.conv(nc[2], nc[2], mode='C' + act_mode) for _ in range(nb)],
            downsample_block(nc[2], nc[3], mode='2' + act_mode))

        self.m_body = B.sequential(
            *
            [B.conv(nc[3], nc[3], mode='C' + act_mode) for _ in range(nb + 1)])

        # upsample
        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError(
                'upsample mode [{:s}] is not found'.format(upsample_mode))

        self.m_up3 = B.sequential(
            upsample_block(nc[3], nc[2], mode='2' + act_mode),
            *[B.conv(nc[2], nc[2], mode='C' + act_mode) for _ in range(nb)])
        self.m_up2 = B.sequential(
            upsample_block(nc[2], nc[1], mode='2' + act_mode),
            *[B.conv(nc[1], nc[1], mode='C' + act_mode) for _ in range(nb)])
        self.m_up1 = B.sequential(
            upsample_block(nc[1], nc[0], mode='2' + act_mode),
            *[B.conv(nc[0], nc[0], mode='C' + act_mode) for _ in range(nb)])

        self.m_tail = B.conv(nc[0], out_nc, bias=True, mode='C')
Exemplo n.º 8
0
    def __init__(self,
                 in_nc=3,
                 out_nc=3,
                 nc=64,
                 nb=16,
                 upscale=4,
                 act_mode='R',
                 upsample_mode='upconv'):
        super(SRResNet, self).__init__()
        n_upscale = int(math.log(upscale, 2))
        if upscale == 3:
            n_upscale = 1

        m_head = B.conv(in_nc, nc, mode='C')

        m_body = [
            B.ResBlock(nc, nc, mode='C' + act_mode + 'C') for _ in range(nb)
        ]
        m_body.append(B.conv(nc, nc, mode='C'))

        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError(
                'upsample mode [{:s}] is not found'.format(upsample_mode))
        if upscale == 3:
            m_uper = upsample_block(nc, nc, mode='3' + act_mode)
        else:
            m_uper = [
                upsample_block(nc, nc, mode='2' + act_mode)
                for _ in range(n_upscale)
            ]

        H_conv0 = B.conv(nc, nc, mode='C' + act_mode)
        H_conv1 = B.conv(nc, out_nc, bias=False, mode='C')
        m_tail = B.sequential(H_conv0, H_conv1)

        self.model = B.sequential(m_head,
                                  B.ShortcutBlock(B.sequential(*m_body)),
                                  *m_uper, m_tail)
    def __init__(self,
                 in_nc: int = 65,
                 nc_x: List[int] = [64, 128, 256, 512],
                 nb: int = 4):
        super(NetX, self).__init__()

        self.m_down1 = B.sequential(
            *[
                B.ResBlock(in_nc, in_nc, bias=False, mode='CRC')
                for _ in range(nb)
            ], B.downsample_strideconv(in_nc, nc_x[1], bias=False, mode='2'))
        self.m_down2 = B.sequential(
            *[
                B.ResBlock(nc_x[1], nc_x[1], bias=False, mode='CRC')
                for _ in range(nb)
            ], B.downsample_strideconv(nc_x[1], nc_x[2], bias=False, mode='2'))
        self.m_down3 = B.sequential(
            *[
                B.ResBlock(nc_x[2], nc_x[2], bias=False, mode='CRC')
                for _ in range(nb)
            ], B.downsample_strideconv(nc_x[2], nc_x[3], bias=False, mode='2'))

        self.m_body = B.sequential(*[
            B.ResBlock(nc_x[-1], nc_x[-1], bias=False, mode='CRC')
            for _ in range(nb)
        ])

        self.m_up3 = B.sequential(
            B.upsample_convtranspose(nc_x[3], nc_x[2], bias=False, mode='2'),
            *[
                B.ResBlock(nc_x[2], nc_x[2], bias=False, mode='CRC')
                for _ in range(nb)
            ])
        self.m_up2 = B.sequential(
            B.upsample_convtranspose(nc_x[2], nc_x[1], bias=False, mode='2'),
            *[
                B.ResBlock(nc_x[1], nc_x[1], bias=False, mode='CRC')
                for _ in range(nb)
            ])
        self.m_up1 = B.sequential(
            B.upsample_convtranspose(nc_x[1], nc_x[0], bias=False, mode='2'),
            *[
                B.ResBlock(nc_x[0], nc_x[0], bias=False, mode='CRC')
                for _ in range(nb)
            ])

        self.m_tail = B.conv(nc_x[0], nc_x[0], bias=False, mode='C')
Exemplo n.º 10
0
    def __init__(self, in_nc=2, out_nc=1, nc=64, nb=20, act_mode='R'):
        """
        in_nc: channel number of input
        out_nc: channel number of output
        nc: channel number
        nb: total number of conv layers
        act_mode: batch norm + activation function; 'BR' means BN+ReLU.
        """
        super(FDnCNN, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'
        bias = True

        m_head = B.conv(in_nc, nc, mode='C' + act_mode[-1], bias=bias)
        m_body = [
            B.conv(nc, nc, mode='C' + act_mode, bias=bias)
            for _ in range(nb - 2)
        ]
        m_tail = B.conv(nc, out_nc, mode='C', bias=bias)

        self.model = B.sequential(m_head, *m_body, m_tail)
Exemplo n.º 11
0
    def __init__(self,
                 in_nc=19,
                 out_nc=3,
                 nc=128,
                 nb=12,
                 upscale=4,
                 act_mode='R',
                 upsample_mode='pixelshuffle'):
        """
        # ------------------------------------
        in_nc: channel number of input, default: 3+15
        out_nc: channel number of output
        nc: channel number
        nb: total number of conv layers
        upscale: scale factor
        act_mode: batch norm + activation function; 'BR' means BN+ReLU
        upsample_mode: default 'pixelshuffle' = conv + pixelshuffle
        # ------------------------------------
        """
        super(SRMD, self).__init__()
        assert 'R' in act_mode or 'L' in act_mode, 'Examples of activation function: R, L, BR, BL, IR, IL'
        bias = True

        if upsample_mode == 'upconv':
            upsample_block = B.upsample_upconv
        elif upsample_mode == 'pixelshuffle':
            upsample_block = B.upsample_pixelshuffle
        elif upsample_mode == 'convtranspose':
            upsample_block = B.upsample_convtranspose
        else:
            raise NotImplementedError(
                'upsample mode [{:s}] is not found'.format(upsample_mode))

        m_head = B.conv(in_nc, nc, mode='C' + act_mode[-1], bias=bias)
        m_body = [
            B.conv(nc, nc, mode='C' + act_mode, bias=bias)
            for _ in range(nb - 2)
        ]
        m_tail = upsample_block(nc, out_nc, mode=str(upscale), bias=bias)

        self.model = B.sequential(m_head, *m_body, m_tail)
Exemplo n.º 12
0
 def __init__(self, in_nc=1, out_nc=1, nc=64):
     """
     # ------------------------------------
     denoiser of IRCNN
     in_nc: channel number of input
     out_nc: channel number of output
     nc: channel number
     nb: total number of conv layers
     act_mode: batch norm + activation function; 'BR' means BN+ReLU.
     # ------------------------------------
     Batch normalization and residual learning are
     beneficial to Gaussian denoising (especially
     for a single noise level).
     The residual of a noisy image corrupted by additive white
     Gaussian noise (AWGN) follows a constant
     Gaussian distribution which stablizes batch
     normalization during training.
     # ------------------------------------
     """
     super(IRCNN, self).__init__()
     L = []
     L.append(
         nn.Conv2d(in_channels=in_nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=1,
                   dilation=1,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=2,
                   dilation=2,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=3,
                   dilation=3,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=4,
                   dilation=4,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=3,
                   dilation=3,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=nc,
                   kernel_size=3,
                   stride=1,
                   padding=2,
                   dilation=2,
                   bias=True))
     L.append(nn.ReLU(inplace=True))
     L.append(
         nn.Conv2d(in_channels=nc,
                   out_channels=out_nc,
                   kernel_size=3,
                   stride=1,
                   padding=1,
                   dilation=1,
                   bias=True))
     self.model = B.sequential(*L)