tagan icon indicating copy to clipboard operation
tagan copied to clipboard

Question: Why two passes through the Generator?

Open nevakanezzar opened this issue 4 years ago • 0 comments

Hi, thank for you this work. I was wondering why, during training, it is necessary to take two passes through the Generator, i.e. once in line 145 and once in line 158:

`

        fake, _ = G(img, (txt_m, len_txt_m))   # line 145
        fake_logit, _ = D(fake.detach(), txt_m, len_txt_m)

        fake_loss = F.binary_cross_entropy_with_logits(fake_logit, zeros_like(fake_logit))
        avg_D_fake_loss += fake_loss.item()

        fake_loss.backward()

        d_optimizer.step()

        # UPDATE GENERATOR
        G.zero_grad()

        fake, (z_mean, z_log_stddev) = G(img, (txt_m, len_txt_m))   # line 158

`

Both these lines are identical (in that you are not sampling new data), and presumably fake.detach() prevents contamination of gradients between the Discriminator update and the Generator update? I think I might be misunderstanding something; if it won't take much time, could you clarify this for me? Thanks.

nevakanezzar avatar Jun 20 '20 18:06 nevakanezzar