(self, opt)
| 48 | return parser |
| 49 | |
| 50 | def __init__(self, opt): |
| 51 | BaseModel.__init__(self, opt) |
| 52 | |
| 53 | # specify the training losses you want to print out. |
| 54 | # The training/test scripts will call <BaseModel.get_current_losses> |
| 55 | self.loss_names = ['G_GAN', 'D_real', 'D_fake', 'G', 'NCE'] |
| 56 | self.visual_names = ['real_A', 'fake_B', 'real_B'] |
| 57 | self.nce_layers = [int(i) for i in self.opt.nce_layers.split(',')] |
| 58 | |
| 59 | if opt.nce_idt and self.isTrain: |
| 60 | self.loss_names += ['NCE_Y'] |
| 61 | self.visual_names += ['idt_B'] |
| 62 | |
| 63 | if self.isTrain: |
| 64 | self.model_names = ['G', 'F', 'D'] |
| 65 | else: # during test time, only load G |
| 66 | self.model_names = ['G'] |
| 67 | |
| 68 | # define networks (both generator and discriminator) |
| 69 | self.netG = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, opt.normG, not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias, opt.no_antialias_up, self.gpu_ids, opt) |
| 70 | self.netF = networks.define_F(opt.input_nc, opt.netF, opt.normG, not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias, self.gpu_ids, opt) |
| 71 | |
| 72 | if self.isTrain: |
| 73 | self.netD = networks.define_D(opt.output_nc, opt.ndf, opt.netD, opt.n_layers_D, opt.normD, opt.init_type, opt.init_gain, opt.no_antialias, self.gpu_ids, opt) |
| 74 | |
| 75 | # define loss functions |
| 76 | self.criterionGAN = networks.GANLoss(opt.gan_mode).to(self.device) |
| 77 | self.criterionNCE = [] |
| 78 | |
| 79 | for nce_layer in self.nce_layers: |
| 80 | self.criterionNCE.append(PatchNCELoss2(opt).to(self.device)) |
| 81 | |
| 82 | self.criterionIdt = torch.nn.L1Loss().to(self.device) |
| 83 | self.optimizer_G = torch.optim.Adam(self.netG.parameters(), lr=opt.lr, betas=(opt.beta1, opt.beta2)) |
| 84 | self.optimizer_D = torch.optim.Adam(self.netD.parameters(), lr=opt.lr, betas=(opt.beta1, opt.beta2)) |
| 85 | self.optimizers.append(self.optimizer_G) |
| 86 | self.optimizers.append(self.optimizer_D) |
| 87 | |
| 88 | def data_dependent_initialize(self, data): |
| 89 | """ |
nothing calls this directly
no test coverage detected