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

Method data_dependent_initialize

models/cut_model.py:84–101  ·  view source on GitHub ↗

The feature network netF is defined in terms of the shape of the intermediate, extracted features of the encoder portion of netG. Because of this, the weights of netF are initialized at the first feedforward pass with some input images. Please also see PatchSampleF.c

(self, data)

Source from the content-addressed store, hash-verified

82 self.optimizers.append(self.optimizer_D)
83
84 def data_dependent_initialize(self, data):
85 """
86 The feature network netF is defined in terms of the shape of the intermediate, extracted
87 features of the encoder portion of netG. Because of this, the weights of netF are
88 initialized at the first feedforward pass with some input images.
89 Please also see PatchSampleF.create_mlp(), which is called at the first forward() call.
90 """
91 self.set_input(data)
92 bs_per_gpu = self.real_A.size(0) // max(len(self.opt.gpu_ids), 1)
93 self.real_A = self.real_A[:bs_per_gpu]
94 self.real_B = self.real_B[:bs_per_gpu]
95 self.forward() # compute fake images: G(A)
96 if self.opt.isTrain:
97 self.compute_D_loss().backward() # calculate gradients for D
98 self.compute_G_loss().backward() # calculate graidents for G
99 if self.opt.lambda_NCE > 0.0:
100 self.optimizer_F = torch.optim.Adam(self.netF.parameters(), lr=self.opt.lr, betas=(self.opt.beta1, self.opt.beta2))
101 self.optimizers.append(self.optimizer_F)
102
103 def optimize_parameters(self):
104 # forward

Callers

nothing calls this directly

Calls 5

set_inputMethod · 0.95
forwardMethod · 0.95
compute_D_lossMethod · 0.95
compute_G_lossMethod · 0.95
backwardMethod · 0.80

Tested by

no test coverage detected