Python net.Discriminator() Examples

The following are 2 code examples of net.Discriminator(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module net , or try the search function .
Example #1
Source File: solver_makeup.py    From BeautyGAN_pytorch with MIT License 5 votes vote down vote up
def build_model(self):
        # Define generators and discriminators
        if self.whichG=='normal':
            self.G = net.Generator_makeup(self.g_conv_dim, self.g_repeat_num)
        if self.whichG=='branch':
            self.G = net.Generator_branch(self.g_conv_dim, self.g_repeat_num)
        for i in self.cls:
            setattr(self, "D_" + i, net.Discriminator(self.img_size, self.d_conv_dim, self.d_repeat_num, self.norm))

        self.criterionL1 = torch.nn.L1Loss()
        self.criterionL2 = torch.nn.MSELoss()
        self.criterionGAN = GANLoss(use_lsgan=True, tensor =torch.cuda.FloatTensor)
        self.vgg = net.VGG()
        self.vgg.load_state_dict(torch.load('addings/vgg_conv.pth'))
        # Optimizers
        self.g_optimizer = torch.optim.Adam(self.G.parameters(), self.g_lr, [self.beta1, self.beta2])
        for i in self.cls:
            setattr(self, "d_" + i + "_optimizer", \
                    torch.optim.Adam(filter(lambda p: p.requires_grad, getattr(self, "D_" + i).parameters()), \
                                     self.d_lr, [self.beta1, self.beta2]))

        # Weights initialization
        self.G.apply(self.weights_init_xavier)
        for i in self.cls:
            getattr(self, "D_" + i).apply(self.weights_init_xavier)

        # Print networks
        self.print_network(self.G, 'G')
        for i in self.cls:
            self.print_network(getattr(self, "D_" + i), "D_" + i)

        if torch.cuda.is_available():
            self.G.cuda()
            self.vgg.cuda()
            for i in self.cls:
                getattr(self, "D_" + i).cuda() 
Example #2
Source File: solver_cycle.py    From BeautyGAN_pytorch with MIT License 5 votes vote down vote up
def build_model(self):
        # Define generators and discriminators
        self.G_A = net.Generator(self.g_conv_dim, self.g_repeat_num) 
        self.G_B = net.Generator(self.g_conv_dim, self.g_repeat_num)
        self.D_A = net.Discriminator(self.img_size, self.d_conv_dim, self.d_repeat_num)
        self.D_B = net.Discriminator(self.img_size, self.d_conv_dim, self.d_repeat_num)
        self.criterionL1 = torch.nn.L1Loss()
        self.criterionGAN = GANLoss(use_lsgan=True, tensor =torch.cuda.FloatTensor)

        # Optimizers
        self.g_optimizer = torch.optim.Adam(itertools.chain(self.G_A.parameters(), self.G_B.parameters()),
                                                self.g_lr, [self.beta1, self.beta2])
        self.d_A_optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad, self.D_A.parameters()), self.d_lr, [self.beta1, self.beta2])
        self.d_B_optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad, self.D_B.parameters()), self.d_lr, [self.beta1, self.beta2])

        self.G_A.apply(self.weights_init_xavier)
        self.D_A.apply(self.weights_init_xavier)
        self.G_B.apply(self.weights_init_xavier)
        self.D_B.apply(self.weights_init_xavier)

        # Print networks
      #  self.print_network(self.E, 'E')
        self.print_network(self.G_A, 'G_A')
        self.print_network(self.D_A, 'D_A')
        self.print_network(self.G_B, 'G_B')
        self.print_network(self.D_B, 'D_B')

        if torch.cuda.is_available():
            self.G_A.cuda()
            self.G_B.cuda()
            self.D_A.cuda()
            self.D_B.cuda()