def initialize(self, opt): BaseModel.initialize(self, opt) self.is_Train = opt.is_Train self.G = Generator(N_p=opt.N_p, N_z=opt.N_z) self.D = Discriminator(N_p=opt.N_p, N_d=opt.N_d) if self.is_Train: self.optimizer_G = optim.Adam(self.G.parameters(), lr=opt.lr_G, betas=(opt.beta1, opt.beta2)) self.optimizer_D = optim.Adam(self.D.parameters(), lr=opt.lr_D, betas=(opt.beta1, opt.beta2)) self.criterion = nn.CrossEntropyLoss() self.L1_criterion = nn.L1Loss() self.w_L1 = opt.w_L1 self.N_z = opt.N_z self.N_p = opt.N_p self.N_d = opt.N_d import torchvision.models as models self.resnet18 = models.resnet18(pretrained=True) if self.gpu_ids: self.resnet18 = self.resnet18.cuda() self.resnet18.fc = torch.nn.LeakyReLU(0.1) for param in self.resnet18.parameters(): param.requires_grad = False self.resnet18.eval() torch.set_num_threads(1)
def initialize(self, opt): BaseModel.initialize(self, opt) self.is_Train = opt.is_Train self.G = Generator(N_p=opt.N_p, N_z=opt.N_z,single = True) self.D = Discriminator(N_p=opt.N_p, N_d=opt.N_d) if self.is_Train: self.optimizer_G = optim.Adam(self.G.parameters(), lr=opt.lr_G, betas=(opt.beta1, opt.beta2)) self.optimizer_D = optim.Adam(self.D.parameters(), lr=opt.lr_D, betas=(opt.beta1, opt.beta2)) self.criterion = nn.CrossEntropyLoss() self.L1_criterion = nn.L1Loss() self.w_L1 = opt.w_L1 self.N_z = opt.N_z self.N_p = opt.N_p self.N_d = opt.N_d