Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Why two passes through the Generator? #19

Open
nevakanezzar opened this issue Jun 20, 2020 · 0 comments
Open

Question: Why two passes through the Generator? #19

nevakanezzar opened this issue Jun 20, 2020 · 0 comments

Comments

@nevakanezzar
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant