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)
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')
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=4, out_nc=3, nc=[64, 128, 256, 512], nb=2, act_mode='R', downsample_mode='strideconv', upsample_mode='convtranspose'): super(ResUNet, self).__init__() self.m_head = B.conv(in_nc, nc[0], bias=False, mode='C') # 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.ResBlock(nc[0], nc[0], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ], downsample_block(nc[0], nc[1], bias=False, mode='2')) self.m_down2 = B.sequential( *[ B.ResBlock(nc[1], nc[1], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ], downsample_block(nc[1], nc[2], bias=False, mode='2')) self.m_down3 = B.sequential( *[ B.ResBlock(nc[2], nc[2], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ], downsample_block(nc[2], nc[3], bias=False, mode='2')) self.m_body = B.sequential(*[ B.ResBlock(nc[3], nc[3], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ]) # 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], bias=False, mode='2'), *[ B.ResBlock(nc[2], nc[2], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ]) self.m_up2 = B.sequential( upsample_block(nc[2], nc[1], bias=False, mode='2'), *[ B.ResBlock(nc[1], nc[1], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ]) self.m_up1 = B.sequential( upsample_block(nc[1], nc[0], bias=False, mode='2'), *[ B.ResBlock(nc[0], nc[0], bias=False, mode='C' + act_mode + 'C') for _ in range(nb) ]) self.m_tail = B.conv(nc[0], out_nc, bias=False, mode='C')