MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / __init__

Method __init__

models/dcl_model.py:49–108  ·  view source on GitHub ↗
(self, opt)

Source from the content-addressed store, hash-verified

47 return parser
48
49 def __init__(self, opt):
50 BaseModel.__init__(self, opt)
51
52 # specify the training losses you want to print out.
53 # The training/test scripts will call <BaseModel.get_current_losses>
54 self.loss_names = ['D_A', 'G_A', 'NCE1', 'D_B', 'G_B', 'NCE2', 'G']
55 visual_names_A = ['real_A', 'fake_B']
56 visual_names_B = ['real_B', 'fake_A']
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 += ['idt_B', 'idt_A']
61 visual_names_A.append('idt_B')
62 visual_names_B.append('idt_A')
63
64 self.visual_names = visual_names_A + visual_names_B # combine visualizations for A and B
65
66 if self.isTrain:
67 self.model_names = ['G_A', 'F1', 'D_A', 'G_B', 'F2', 'D_B']
68 else: # during test time, only load G
69 self.model_names = ['G_A', 'G_B']
70
71 # define networks (both generator and discriminator)
72 self.netG_A = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, opt.normG,
73 not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias,
74 opt.no_antialias_up, self.gpu_ids, opt)
75 self.netG_B = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, opt.normG,
76 not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias,
77 opt.no_antialias_up, self.gpu_ids, opt)
78 self.netF1 = networks.define_F(opt.input_nc, opt.netF, opt.normG,
79 not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias, self.gpu_ids,
80 opt)
81 self.netF2 = networks.define_F(opt.input_nc, opt.netF, opt.normG,
82 not opt.no_dropout, opt.init_type, opt.init_gain, opt.no_antialias, self.gpu_ids,
83 opt)
84
85 if self.isTrain:
86 self.netD_A = networks.define_D(opt.output_nc, opt.ndf, opt.netD,
87 opt.n_layers_D, opt.normD, opt.init_type, opt.init_gain, opt.no_antialias,
88 self.gpu_ids, opt)
89 self.netD_B = networks.define_D(opt.output_nc, opt.ndf, opt.netD,
90 opt.n_layers_D, opt.normD, opt.init_type, opt.init_gain, opt.no_antialias,
91 self.gpu_ids, opt)
92 self.fake_A_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images
93 self.fake_B_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images
94 # define loss functions
95 self.criterionGAN = networks.GANLoss(opt.gan_mode).to(self.device)
96 self.criterionNCE = []
97
98 for nce_layer in self.nce_layers:
99 self.criterionNCE.append(PatchNCELoss(opt).to(self.device))
100
101 self.criterionIdt = torch.nn.L1Loss().to(self.device)
102 self.criterionSim = torch.nn.L1Loss('sum').to(self.device)
103 self.optimizer_G = torch.optim.Adam(itertools.chain(self.netG_A.parameters(), self.netG_B.parameters()),
104 lr=opt.lr, betas=(opt.beta1, opt.beta2))
105 self.optimizer_D = torch.optim.Adam(itertools.chain(self.netD_A.parameters(), self.netD_B.parameters()),
106 lr=opt.lr, betas=(opt.beta1, opt.beta2))

Callers

nothing calls this directly

Calls 2

ImagePoolClass · 0.90
PatchNCELossClass · 0.85

Tested by

no test coverage detected