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)
| 122 | self.optimizers.append(self.optimizer_D) |
| 123 | |
| 124 | def data_dependent_initialize(self, data): |
| 125 | """ |
| 126 | The feature network netF is defined in terms of the shape of the intermediate, extracted |
| 127 | features of the encoder portion of netG. Because of this, the weights of netF are |
| 128 | initialized at the first feedforward pass with some input images. |
| 129 | Please also see PatchSampleF.create_mlp(), which is called at the first forward() call. |
| 130 | """ |
| 131 | self.set_input(data) |
| 132 | bs_per_gpu = self.real_A.size(0) // max(len(self.opt.gpu_ids), 1) |
| 133 | self.real_A = self.real_A[:bs_per_gpu] |
| 134 | self.real_B = self.real_B[:bs_per_gpu] |
| 135 | self.forward() # compute fake images: G(A) |
| 136 | if self.opt.isTrain: |
| 137 | self.compute_G_loss().backward() # calculate graidents for G |
| 138 | self.backward_D_A() # calculate gradients for D_A |
| 139 | self.backward_D_B() # calculate graidents for D_B |
| 140 | if self.opt.lambda_NCE > 0.0: |
| 141 | self.optimizer_F = torch.optim.Adam( |
| 142 | itertools.chain(self.netF1.parameters(), self.netF2.parameters(), self.netF3.parameters(), |
| 143 | self.netF4.parameters(), |
| 144 | self.netF5.parameters(), self.netF6.parameters()), lr=self.opt.lr, |
| 145 | betas=(self.opt.beta1, self.opt.beta2)) |
| 146 | self.optimizers.append(self.optimizer_F) |
| 147 | |
| 148 | def optimize_parameters(self): |
| 149 | # forward |
nothing calls this directly
no test coverage detected