Calculate GAN loss for the discriminator Parameters: netD (network) -- the discriminator D real (tensor array) -- real images fake (tensor array) -- images generated by a generator Return the discriminator loss. We also call loss_D.ba
(self, netD, real, fake)
| 187 | self.idt_B = self.netG_B(self.real_A) |
| 188 | |
| 189 | def backward_D_basic(self, netD, real, fake): |
| 190 | """Calculate GAN loss for the discriminator |
| 191 | Parameters: |
| 192 | netD (network) -- the discriminator D |
| 193 | real (tensor array) -- real images |
| 194 | fake (tensor array) -- images generated by a generator |
| 195 | |
| 196 | Return the discriminator loss. |
| 197 | We also call loss_D.backward() to calculate the gradients. |
| 198 | """ |
| 199 | # Real |
| 200 | pred_real = netD(real) |
| 201 | loss_D_real = self.criterionGAN(pred_real, True) |
| 202 | # Fake |
| 203 | pred_fake = netD(fake.detach()) |
| 204 | loss_D_fake = self.criterionGAN(pred_fake, False) |
| 205 | # Combined loss and calculate gradients |
| 206 | loss_D = (loss_D_real + loss_D_fake) * 0.5 |
| 207 | loss_D.backward() |
| 208 | return loss_D |
| 209 | |
| 210 | def backward_D_A(self): |
| 211 | """Calculate GAN loss for discriminator D_A""" |
no test coverage detected