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

Why train generator using real_labels in GAN? #45

Closed
jamestang0219 opened this issue Jun 7, 2017 · 2 comments
Closed

Why train generator using real_labels in GAN? #45

jamestang0219 opened this issue Jun 7, 2017 · 2 comments

Comments

@jamestang0219
Copy link

jamestang0219 commented Jun 7, 2017

Hello,
I'm confused about the codes of training generator in GAN. Anyone could help me?
Codes here:

        #=============== Train the generator ===============#
        # Compute loss with fake images
        z = to_var(torch.randn(batch_size, 64))
        fake_images = G(z)
        outputs = D(fake_images)
        g_loss = criterion(outputs, real_labels)
        
        # Backprop + Optimize
        D.zero_grad()
        G.zero_grad()
        g_loss.backward()
        g_optimizer.step()

Images generated from generator are fake, but why the second parameter of criterion is real_labels not fake_labels? Thank you all.

@AceCoooool
Copy link

Because the "task" of generator is to cheat the Discriminator. ~ How can you cheat the Discriminator ? ---> you can let the Generator to generate "real image" ! , so the output of Generator is close to real_labels as possible. (If you use fake_label, you want to creat a bad image to cheat Discriminator ? )

@jamestang0219
Copy link
Author

Thank you for your help @AceCoooool . In my opinion, training generator won't update discriminator's parameters at the same time, so if the image from generator is fake enough, the loss of criterion will be huge. Using this loss to update generator's parameters, they will be close to real image. Thank you again, :)

@yunjey yunjey closed this as completed Jun 15, 2017
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

3 participants