Example #1
0
    def __init__(self):
        super(Autoencoder, self).__init__()

        self.encoder = nn.Sequential(
            _ConvLayer(3, 128),
            _ConvLayer(128, 256),
            _ConvLayer(256, 512),
            _ConvLayer(512, 1024),
            Flatten(),
            nn.Linear(1024 * 4 * 4,1024),
            nn.Linear(1024,1024 * 4 * 4),
            Reshape(),
            _UpScale(1024, 512),
        )

        self.decoder_A = nn.Sequential(
            _UpScale(512, 256),
            _UpScale(256, 128),
            _UpScale(128, 64),
            Conv2d(64, 3, kernel_size=5, padding=1),
            nn.Sigmoid(),
        )

        self.decoder_B = nn.Sequential(
            _UpScale(512, 256),
            _UpScale(256, 128),
            _UpScale(128, 64),
            Conv2d(64, 3, kernel_size=5, padding=1),
            nn.Sigmoid(),
        )
Example #2
0
 def __init__(self, ndf=128):
     super(Discriminator, self).__init__()
     self.ndf = ndf
     self.conv1 = Conv2d(3, ndf, 5, stride=2)
     self.conv2 = nn.utils.spectral_norm(Conv2d(ndf, ndf*2, 5, stride=2))
     self.conv3 = nn.utils.spectral_norm(Conv2d(ndf*2, ndf*4, 5, stride=2))
     self.conv4 = nn.utils.spectral_norm(Conv2d(ndf*4, ndf*8, 3, stride=2))
     self.fc5 = nn.Linear(4*4*ndf*8, 1)
Example #3
0
    def __init__(self):
        super(Discriminator, self).__init__()
        self.conv1 = Conv2d(3, 128, 5, stride=2)

        self.conv2 = Conv2d(128, 256, 5, stride=2)
        self.bn2 = nn.BatchNorm2d(256)

        self.conv3 = Conv2d(256, 512, 5, stride=2)
        self.bn3 = nn.BatchNorm2d(512)

        self.conv4 = Conv2d(512, 1024, 3, stride=2)
        self.bn4 = nn.BatchNorm2d(1024)

        self.fc5 = nn.Linear(4 * 4 * 1024, 1)
Example #4
0
    def __init__(self, z_dim):
        super(Generator, self).__init__()
        self.fc1 = nn.Linear(z_dim, 8 * 8 * 1024)

        self.up2 = nn.Upsample(scale_factor=2, mode='nearest')
        self.conv2 = Conv2d(1024, 512, 3)
        self.bn2 = nn.BatchNorm2d(512)

        self.up3 = nn.Upsample(scale_factor=2, mode='nearest')
        self.conv3 = Conv2d(512, 256, 5)
        self.bn3 = nn.BatchNorm2d(256)

        self.up4 = nn.Upsample(scale_factor=2, mode='nearest')
        self.conv4 = Conv2d(256, 3, 5)
    def __init__(self, z_dim, ndf=128):
        super(Encoder, self).__init__()
        self.ndf = ndf
        self.conv1 = Conv2d(3, ndf, 5, stride=2)

        self.conv2 = Conv2d(ndf, ndf * 2, 5, stride=2)
        self.bn2 = nn.BatchNorm2d(ndf * 2)

        self.conv3 = Conv2d(ndf * 2, ndf * 4, 5, stride=2)
        self.bn3 = nn.BatchNorm2d(ndf * 4)

        self.conv4 = Conv2d(ndf * 4, ndf * 8, 3, stride=2)
        self.fc5_mu = nn.Linear(4 * 4 * ndf * 8, z_dim)
        self.fc5_logvar = nn.Linear(4 * 4 * ndf * 8, z_dim)
Example #6
0
    def __init__(self, z_dim):
        super(GeneratorZ, self).__init__()
        self.conv1 = Conv2d(3, 128, 5, stride=2)
        self.bn1 = nn.BatchNorm2d(128)

        self.conv2 = Conv2d(128, 256, 5, stride=2)
        self.bn2 = nn.BatchNorm2d(256)

        self.conv3 = Conv2d(256, 512, 5, stride=2)
        self.bn3 = nn.BatchNorm2d(512)

        self.conv4 = Conv2d(512, 1024, 3, stride=2)
        self.bn4 = nn.BatchNorm2d(1024)

        self.fc5 = nn.Linear(4 * 4 * 1024, z_dim)
Example #7
0
 def __init__(self, z_dim):
     super(Encoder, self).__init__()
     self.conv1 = Conv2d(3, 128, 5, stride=2)
     
     self.conv2 = Conv2d(128, 256, 5, stride=2)
     self.bn2 = nn.BatchNorm2d(256)
     
     self.conv3 = Conv2d(256, 512, 5, stride=2)
     self.bn3 = nn.BatchNorm2d(512)
     
     self.conv4 = Conv2d(512, 1024, 3, stride=2)
     self.bn4 = nn.BatchNorm2d(1024)
     
     self.fc5_mu = nn.Linear(4*4*1024, z_dim)
     self.fc5_logvar = nn.Linear(4*4*1024, z_dim)
 def __init__(self, z_dim, ndf=128):
     super(Generator, self).__init__()
     self.ndf = ndf
     self.fc1 = nn.Linear(z_dim, 8 * 8 * ndf * 8)
     self.conv1 = Conv2d(ndf * 8, ndf * 4, 3)
     # (512, 8, 8)
     self.up2 = nn.Upsample(scale_factor=2, mode='nearest')
     self.conv2 = Conv2d(ndf * 4, ndf * 2, 3)
     self.bn2 = nn.BatchNorm2d(ndf * 2)
     # (256, 16, 16)
     self.up3 = nn.Upsample(scale_factor=2, mode='nearest')
     self.conv3 = Conv2d(ndf * 2, ndf, 5)
     self.bn3 = nn.BatchNorm2d(ndf)
     # (128, 32, 32)
     self.up4 = nn.Upsample(scale_factor=2, mode='nearest')
     self.conv4 = Conv2d(ndf, 3, 5)
Example #9
0
 def __init__(self, input_features, output_features):
     super(_UpScale, self).__init__()
     self.add_module(
         "conv2_", Conv2d(input_features,
                          output_features * 4,
                          kernel_size=3))
     self.add_module("leakyrelu", nn.LeakyReLU(0.1, inplace=True))
     self.add_module("pixelshuffler", _PixelShuffler())
Example #10
0
 def __init__(self, input_features, output_features):
     super(_ConvLayer, self).__init__()
     self.add_module('conv2', Conv2d(input_features, output_features,
                                     kernel_size=5, stride=2))
     self.add_module('leakyrelu', nn.LeakyReLU(0.1, inplace=True))
Example #11
0
 def __init__(self, in_channels, out_channels):
     super(UpScale, self).__init__()
     self.add_module('conv2d_',
                     Conv2d(in_channels, out_channels * 4, kernel_size=3))
     self.add_module('leakyrelu', nn.LeakyReLU(0.1, inplace=True))
     self.add_module('pixelshuffle', PixelShuffle())
Example #12
0
 def __init__(self, in_channels, out_channels):
     super(ConvLayer, self).__init__()
     self.add_module(
         'conv2d_',
         Conv2d(in_channels, out_channels, kernel_size=5, stride=2))
     self.add_module('leakyrelu', nn.LeakyReLU(0.1, inplace=True))