Ejemplo n.º 1
0
 def __init__(self, channels):
     super(ResidualBlock, self).__init__()
     self.conv1 = SpectralNorm(
         nn.Conv2d(channels, channels, kernel_size=3, padding=1))
     self.bn1 = nn.BatchNorm2d(channels)
     self.prelu = nn.PReLU()
     self.conv2 = SpectralNorm(
         nn.Conv2d(channels, channels, kernel_size=3, padding=1))
     self.bn2 = nn.BatchNorm2d(channels)
Ejemplo n.º 2
0
    def __init__(self, batch_size, image_size=64, z_dim=100, conv_dim=64):
        super(Generator, self).__init__()
        self.imsize = image_size
        layer1 = []
        layer2 = []
        layer3 = []
        last = []

        repeat_num = int(np.log2(self.imsize)) - 3
        mult = 2**repeat_num  # 8
        layer1.append(
            SpectralNorm(nn.ConvTranspose2d(z_dim, conv_dim * mult, 4)))
        layer1.append(nn.BatchNorm2d(conv_dim * mult))
        layer1.append(nn.ReLU())

        curr_dim = conv_dim * mult

        layer2.append(
            SpectralNorm(
                nn.ConvTranspose2d(curr_dim, int(curr_dim / 2), 4, 2, 1)))
        layer2.append(nn.BatchNorm2d(int(curr_dim / 2)))
        layer2.append(nn.ReLU())

        curr_dim = int(curr_dim / 2)

        layer3.append(
            SpectralNorm(
                nn.ConvTranspose2d(curr_dim, int(curr_dim / 2), 4, 2, 1)))
        layer3.append(nn.BatchNorm2d(int(curr_dim / 2)))
        layer3.append(nn.ReLU())

        if self.imsize == 64:
            layer4 = []
            curr_dim = int(curr_dim / 2)
            layer4.append(
                SpectralNorm(
                    nn.ConvTranspose2d(curr_dim, int(curr_dim / 2), 4, 2, 1)))
            layer4.append(nn.BatchNorm2d(int(curr_dim / 2)))
            layer4.append(nn.ReLU())
            self.l4 = nn.Sequential(*layer4)
            curr_dim = int(curr_dim / 2)

        self.l1 = nn.Sequential(*layer1)
        self.l2 = nn.Sequential(*layer2)
        self.l3 = nn.Sequential(*layer3)

        last.append(nn.ConvTranspose2d(curr_dim, 3, 4, 2, 1))
        last.append(nn.Tanh())
        self.last = nn.Sequential(*last)

        self.attn1 = Self_Attn(128, 'relu')
        self.attn2 = Self_Attn(64, 'relu')
 def __init__(self):
     super(Discriminator, self).__init__()
     self.conv0 = nn.Sequential(
         SpectralNorm(nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1)),
         nn.BatchNorm2d(64), nn.ReLU())
     self.conv1 = nn.Sequential(
         SpectralNorm(nn.Conv2d(64, 64, kernel_size=3, stride=1,
                                padding=1)), nn.BatchNorm2d(64), nn.ReLU())
     self.conv2 = nn.Sequential(
         SpectralNorm(nn.Conv2d(64, 64, kernel_size=3, stride=1,
                                padding=1)), nn.BatchNorm2d(64), nn.ReLU())
     self.average_pooling = nn.AdaptiveAvgPool2d(1)
     self.linear = SpectralNorm(nn.Linear(64, 1))
Ejemplo n.º 4
0
 def __init__(self):
     super(Generator, self).__init__()
     self.det_conv0 = nn.Sequential(
         SpectralNorm(
             nn.Conv2d(3 + 1, 64, kernel_size=3, stride=1, padding=1)),
         nn.ReLU())
     self.det_conv1 = ResidualBlock(64)
     self.det_conv2 = ResidualBlock(64)
     self.det_conv3 = ResidualBlock(64)
     self.det_conv4 = ResidualBlock(64)
     self.det_conv5 = ResidualBlock(64)
     self.det_conv6 = ResidualBlock(64)
     self.output = nn.Sequential(SpectralNorm(nn.Conv2d(64, 3, 3, 1, 1)))
Ejemplo n.º 5
0
    def __init__(self,
                 batch_size=64,
                 image_size=64,
                 conv_dim=64,
                 feat_dim=512):
        super(Discriminator, self).__init__()
        self.imsize = image_size
        layer1 = []
        layer2 = []
        layer3 = []
        last = []

        layer1.append(SpectralNorm(nn.Conv2d(3, conv_dim, 4, 2, 1)))
        layer1.append(nn.LeakyReLU(0.1))

        curr_dim = conv_dim

        layer2.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 4, 2, 1)))
        layer2.append(nn.LeakyReLU(0.1))
        curr_dim = curr_dim * 2

        layer3.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 4, 2, 1)))
        layer3.append(nn.LeakyReLU(0.1))
        curr_dim = curr_dim * 2

        if self.imsize == 256:
            layer4 = []
            layer4.append(
                SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 4, 2, 1)))
            layer4.append(nn.LeakyReLU(0.1))
            self.l4 = nn.Sequential(*layer4)
            curr_dim = curr_dim * 2
        self.l1 = nn.Sequential(*layer1)
        self.l2 = nn.Sequential(*layer2)
        self.l3 = nn.Sequential(*layer3)

        last.append(nn.Conv2d(curr_dim, 1, 4))
        self.last = nn.Sequential(*last)

        self.attn1 = Self_Attn(256, 'relu')
        self.attn2 = Self_Attn(512, 'relu')

        self.cn = CondNorm2d(feat_dim, 512)
Ejemplo n.º 6
0
    def __init__(self,
                 batch_size,
                 image_size=64,
                 z_dim=100,
                 conv_dim=64,
                 feat_dim=512):
        super(Generator32, self).__init__()
        self.imsize = image_size
        self.z_dim = z_dim
        layer1 = []
        layer2 = []
        layer3 = []
        last = []

        repeat_num = int(np.log2(self.imsize)) - 3
        mult = 2**repeat_num  # 8

        self.l1 = SpectralNorm(nn.ConvTranspose2d(z_dim, conv_dim * mult, 4))
        #layer1.append(nn.BatchNorm2d(conv_d
        self.cn1 = CondNorm2d(feat_dim, conv_dim * mult)

        curr_dim = conv_dim * mult

        self.l2 = SpectralNorm(
            nn.ConvTranspose2d(curr_dim, int(curr_dim / 2), 4, 2, 1))
        #layer2.append(nn.BatchNorm2d(int(curr_dim / 2)))
        self.cn2 = CondNorm2d(feat_dim, int(curr_dim / 2))

        curr_dim = int(curr_dim / 2)

        self.l3 = SpectralNorm(
            nn.ConvTranspose2d(curr_dim, int(curr_dim / 2), 4, 2, 1))
        #layer3.append(nn.BatchNorm2d(int(curr_dim / 2)))
        self.cn3 = CondNorm2d(feat_dim, int(curr_dim / 2))

        curr_dim = int(curr_dim / 2)

        self.last = nn.ConvTranspose2d(curr_dim, 3, 4, 2, 1)
        self.last_cn = CondNorm2d(feat_dim, 3)

        self.attn1 = Self_Attn(128, 'relu')
        self.attn2 = Self_Attn(64, 'relu')