Пример #1
0
    def __init__(self,
                 in_channels,
                 middle_channels,
                 out_channels,
                 is_deconv=True):
        super(CenterBlock, self).__init__()
        self.in_channels = in_channels
        self.is_deconv = is_deconv

        if self.is_deconv:  #Dense Block
            self.conv1 = conv3x3_bn_relu(in_channels, middle_channels)
            self.conv2 = conv3x3_bn_relu(in_channels + middle_channels,
                                         middle_channels)
            self.convUp = nn.Sequential(
                nn.ConvTranspose2d(in_channels + 2 * middle_channels,
                                   out_channels,
                                   kernel_size=4,
                                   stride=2,
                                   padding=1), nn.ReLU(inplace=True))

        else:
            self.convUp = nn.Unsample(scale_factor=2,
                                      mode='bilinear',
                                      align_corners=True),
            self.conv1 = conv3x3_bn_relu(in_channels, middle_channels),
            self.conv2 = conv3x3_bn_relu(in_channels + middle_channels,
                                         out_channels)
Пример #2
0
    def __init__(self, isize, input_nc, output_nc, ngf, n_extra_layers=0):
        super(CDCGAN_G_nobn, self).__init__()
        assert isize % 16 == 0, "isize has to be a multiple of 16"

        self.up = nn.Unsample(isize, mode='bilinear')

        cngf, tisize = ngf//2, 4
        while tisize != isize:
            cngf = cngf * 2
            tisize = tisize * 2

        main = nn.Sequential()
        main.add_module('initial.{0}-{1}.convt'.format(input_nc, cngf),
                        nn.ConvTranspose2d(input_nc, cngf, 4, 1, 0, bias=False))
        main.add_module('initial.{0}.relu'.format(cngf),
                        nn.ReLU(True))

        csize, cndf = 4, cngf
        while csize < isize//2:
            main.add_module('pyramid.{0}-{1}.convt'.format(cngf, cngf//2),
                            nn.ConvTranspose2d(cngf, cngf//2, 4, 2, 1, bias=False))
            main.add_module('pyramid.{0}.relu'.format(cngf//2),
                            nn.ReLU(True))
            cngf = cngf // 2
            csize = csize * 2

        # Extra layers
        for t in range(n_extra_layers):
            main.add_module('extra-layers-{0}.{1}.conv'.format(t, cngf),
                            nn.Conv2d(cngf, cngf, 3, 1, 1, bias=False))
            main.add_module('extra-layers-{0}.{1}.relu'.format(t, cngf),
                            nn.ReLU(True))

        main.add_module('final.{0}-{1}.convt'.format(cngf, output_nc),
                        nn.ConvTranspose2d(cngf, output_nc, 4, 2, 1, bias=False))
        main.add_module('final.{0}.tanh'.format(output_nc),
                        nn.Tanh())
        self.main = main
Пример #3
0
 def __init__(self):
     super(AlbedoGenerationNet, self).__init__()
     self.unsample = nn.Unsample(scale_factor=2, mode='bilinear')
     self.conv1 = get_conv(128, 128, kernel_size=1)
     self.conv2 = get_conv(128, 64, kernel_size=3, padding=1)
     self.conv3 = get_conv(64, 3, kernel_size=1)